Adv Java and Data Mining Manual
Adv Java and Data Mining Manual
BCA
Second Year Semester - V
Guidelines
Laboratory rules
1. Attendance is required for all lab classes. Students who do not attend lab will not receive
credit.
2. Ensure that you are aware of the test and its procedure before each lab class. You will NOT
be allowed to attend the class if you are not prepared!
3. Personal safety is top priority. Do not use equipment that is not assigned to you.
5. The surroundings near the equipment must be cleaned before leaving each lab class.
6. Ensure that outputs are checked and marked by your TA for each lab period.\
******
2
XCA512– Lab course based on Advanced Java
STUDENT’S DETAILS
Name of Student
Academic
Programme
Class/ Roll
PRN No.
3
XCA512– Lab course based on Advanced Java
Certificate
This is to certify that Mr/Miss __________________________________________
4
XCA512– Lab course based on Advanced Java
Table of contents
Instruction: Draw Flow-Chart and write algorithms wherever is needed in the Manual.
Sr. Page
Title of Experiment Date Remark
No. No
Group A
1 7 22-07-2024
Program to insert and retrieve data from database through
jdbc drivers
2 9 29-07-2024
Write a program to display information about Database . (Use
DatabaseMetaData).
5 Write a servlet which counts how many times a user has 15 20-08-2024
6 Create a JSP page which accepts username in the textbox and 16 02-09-2024
7 17 09-09-2024
Write a program to make use of the JSP implicit objects.
8 23-09-2024
Define a thread called “PrintTextThread” for printing text on
command prompt 18
5
XCA512– Lab course based on Advanced Java
Group B
20 23-07-2024
9 Write a steps to install Weka Tool for Data Mining Practical.
23 30-07-2024
Demonstrate to apply different kinds of preprocessing
10
techniques on labor.arff dataset.
Write a program to demonstrate the Association rule process 26 06-08-2024
11
on dataset contactlenses.arff using apriori algorithm.
Demonstration of classification rule process on dataset 29 13-08-2024
12 airline.arff using j48 Algorithm.
6
XCA512– Lab course based on Advanced Java
Experiment No. 1
Program to insert and retrieve data from database through jdbc drivers
Program
SQL Script for inserting Data:
Create database jdbc;
Create TABLE `form` (
`PRN` varchar(12)NOTNULL,
`Name` varchar(20)NOTNULL,
`Phone` varchar(10)NOTNULL,
`Email` VARCHAR(256)NOTNULL, UNIQUE `PRN` (`PRN`));
insertinto form(PRN, Name , Phone,
Email)values('200105311004','Arvind','7045440507','[email protected]');
insertinto form(PRN, Name , Phone,
Email)values('200105311010','Harikrishna','8767859566','[email protected]
m'); insertinto form(PRN, Name , Phone,
Email)values('200105311012','Mohan','8625877312','[email protected]'); insertinto
form(PRN, Name , Phone,
Email)values('200105311013','Piyush','9145728659','[email protected]'); insertinto
form(PRN, Name , Phone,
Email)values('200105261002','Abhay','9921200036','[email protected]'); insertinto
form(PRN, Name , Phone,
Email)values('200105041004','Prathamesh','7769968763','[email protected]');
select*from form;
7
XCA512– Lab course based on Advanced Java
Output :
8
XCA512– Lab course based on Advanced Java
Experiment No :2
while(rs.next())
System.out.println(rs.getString("TABLE_NAME"));
rs.close();
con.close();
}
catch(Exception e)
{
System.out.println("Error:"+e);
}
}
}
9
XCA512– Lab course based on Advanced Java
b)
Write a program to display information about all columns in the student table. (Use
ResultSetMetaData).
import java.util.*;
import java.sql.*;
import java.io.*;
class Result1{
public static void main(String args[]) throws IOException
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://192.168.0.202/ty017","ty017","");
ResultSetMetaData rsmd;
Statement stmt=con.createStatement();
ResultSet rs=null;
rs=stmt.executeQuery("select * from student");
rsmd=rs.getMetaData();
int noOfColumns=rsmd.getColumnCount();
System.out.println("Number of columns="+noOfColumns);
for(int i=1;i<=noOfColumns;i++)
{
System.out.println("Column No:"+i);
System.out.println("Column Name:"+rsmd.getColumnName(i));
System.out.println("Column Type:"+rsmd.getColumnTypeName(i));
System.out.println("Column display size:"+rsmd.getColumnDisplaySize(i));
}
con.close();
}
catch(Exception e)
{
System.out.println("Exception found"+e);
}
}
}
10
XCA512– Lab course based on Advanced Java
Output:
Number of columns=3
Column No:1
Column Name:roll_no
Column Type:INT
Column display size:11
Column No:2
Column Name:stud_name
Column Type:VARCHAR
Column display size:20
Column No:3
Column Name:per
Column Type:DOUBLE
Column display size:22
11
XCA512– Lab course based on Advanced Java
Experiment No. 3
Write Java Program using XML Document Object Model (DOM)
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
public class JavaXmlDomReadEx {
12
XCA512– Lab course based on Advanced Java
Output:
13
XCA512– Lab course based on Advanced Java
Experiment No. 4
Write a servlet program to print servlet Server Information.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
Address http://localhost:8080/sv/prg2
14
XCA512– Lab course based on Advanced Java
Experiment No. 5
Write a servlet which counts how many times a user has visited a web page.
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
}
}
}
15
XCA512– Lab course based on Advanced Java
Experiment No. 6
Create a JSP page which accepts username in the textbox and greet the user
according to the time on server side.
/* prg2.html*/
/*prg2.jsp*/
<%@page import="java.util.Calendar"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%String name = request.getParameter("name");
Calendar rightnow = Calendar.getInstance();
int time = rightnow.get(Calendar.HOUR_OF_DAY);
Output:
Good Morning ABC
16
XCA512– Lab course based on Advanced Java
Experiment No. 7
Write a program to make use of the JSP implicit objects.
<%@page import="java.util.Calendar"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
Calendar c = Calendar.getInstance();
int dd = c.get(Calendar.DATE);
int h = c.get(Calendar.HOUR_OF_DAY);
int m = c.get(Calendar.MINUTE);
int s = c.get(Calendar.SECOND);
out.println("\nPath : "+path);
out.println("\nConfig");
out.println("\n"+config.getServletName());
out.println("\nApplication : ");
out.println("\n"+application.getServerInfo());
%>
17
XCA512– Lab course based on Advanced Java
Experiment No. 8
Define a thread called “PrintTextThread” for printing text on command prompt.
import java.io.*;
import java.lang.String.*;
18
XCA512– Lab course based on Advanced Java
Output:
I am in FY
I am in FY
I am in FY
I am in FY
I am in FY
I am in SY
I am in SY
I am in SY
I am in SY
I am in SY
I am in TY
I am in TY
I am in TY
I am in TY
I am in TY
I am in TY
I am in TY
I am in TY
I am in TY
19
XCA512– Lab course based on Advanced Java
Experiment No. 9
Write a steps to install Weka Tool for Data Mining Practical.
Aim: This experiment illustrates how to install Weka software for preprocessing of arff format
data, classification of data using machine learning algorithms.
Step1: Loading the data. We can load the dataset into weka by clicking on open button in
preprocessing interface and selecting the appropriate file.
Step2: Once the data is loaded, weka will recognize the attributes and during the scan of the
data weka will compute some basic strategies on each attribute. The left panel in the above
figure shows the list of recognized attributes while the top panel indicates the names of the base
relation or table and the current working relation (which are same initially).
Step3:Clicking on an attribute in the left panel will show the basic statistics on the attributes
for the categorical attributes the frequency of each attribute value is shown, while for
continuous attributes we can obtain min, max, mean, standard deviation and deviation etc.,
Step4:The visualization in the right button panel in the form of cross-tabulation across two attributes.
Step 6:a)Next click the textbox immediately to the right of the choose button.In the resulting
dialog box enter the index of the attribute to be filtered out.
b) Make sure that invert selection option is set to false.The click OK now in the filter box.you
will see “Remove-R-7”.
c) Click the apply button to apply filter to this data.This will remove the attribute and create
new working relation.
d) Save the new working relation as an arff file by clicking save button on the
top(button)panel.(student.arff)
20
XCA512– Lab course based on Advanced Java
Discretization
1) Sometimes association rule mining can only be performed on categorical data.This requires
performing discretization on numeric or continuous attributes.In the following example let us
discretize age attribute.
To change the defaults for the filters,click on the box immediately to the right of the choose
button.
We enter the index for the attribute to be discretized.In this case the attribute is age.So we
must enter ‘1’ corresponding to the age attribute.
Enter ‘3’ as the number of bins.Leave the remaining field values as they are.
Click OK button.
Click apply in the filter panel.This will result in a new working relation with the selected
attribute partition into 3 bins.
21
XCA512– Lab course based on Advanced Java
22
XCA512– Lab course based on Advanced Java
Experiment No. 10
Aim: This experiment illustrates some of the basic data preprocessing operations that can be
performed using WEKA-Explorer. The sample dataset used for this example is the labor data
available in arff format.
Step1:Loading the data. We can load the dataset into weka by clicking on open button in
preprocessing interface and selecting the appropriate file.
Step2:Once the data is loaded, weka will recognize the attributes and during the scan of the
data weka will compute some basic strategies on each attribute. The left panel in the above
figure shows the list of recognized attributes while the top panel indicates the names of the base
relation or table and the current working relation (which are same initially).
Step3:Clicking on an attribute in the left panel will show the basic statistics on the attributes
for the categorical attributes the frequency of each attribute value is shown, while for
continuous attributes we can obtain min, max, mean, standard deviation and deviation etc.,
Step4:The visualization in the right button panel in the form of cross-tabulation across two attributes.
Step 6:a)Next click the textbox immediately to the right of the choose button.In the resulting
dialog box enter the index of the attribute to be filtered out.
b) Make sure that invert selection option is set to false.The click OK now in the filter box.you
will see “Remove-R-7”.
c) Click the apply button to apply filter to this data.This will remove the attribute and create
new working relation.
d) Save the new working relation as an arff file by clicking save button on the
top(button)panel.(labor.arff)
23
XCA512– Lab course based on Advanced Java
Discretization
1) Sometimes association rule mining can only be performed on categorical data.This requires
performing discretization on numeric or continuous attributes.In the following example let us
discretize duration attribute.
To change the defaults for the filters,click on the box immediately to the right of the choose
button.
We enter the index for the attribute to be discretized.In this case the attribute is duration So
we must enter ‘1’ corresponding to the duration attribute.
Enter ‘1’ as the number of bins.Leave the remaining field values as they are.
Click OK button.
Click apply in the filter panel.This will result in a new working relation with the selected
attribute partition into 1 bin.
Dataset labor.arff
24
XCA512– Lab course based on Advanced Java
25
XCA512– Lab course based on Advanced Java
Experiment No. 11
Step1: Open the data file in Weka Explorer. It is presumed that the required data fields have
been discretized. In this example it is age attribute.
Step2: Clicking on the associate tab will bring up the interface for association rule algorithm.
Step4: Inorder to change the parameters for the run (example support, confidence etc) we click
on the text box immediately to the right of the choose button.
Dataset contactlenses.arff
26
XCA512– Lab course based on Advanced Java
The following screenshot shows the association rules that were generated when apriori
algorithm is applied on the given dataset.
27
XCA512– Lab course based on Advanced Java
28
XCA512– Lab course based on Advanced Java
Experiment No. 12
Step2: Next we select the “classify” tab and click “choose” button t o select the “j48”classifier.
Step3: Now we specify the various parameters. These can be specified by clicking in the text
box to the right of the chose button. In this example, we accept the default values. The default
version does perform some pruning but does not perform error pruning.
Step4: Under the “text” options in the main panel. We select the 10-fold cross validation as our
evaluation approach. Since we don’t have separate evaluation data set, this is necessary to get
a reasonable idea of accuracy of generated model.
Step-5: We now click ”start” to generate the model .the Ascii version of the tree as well as
evaluation statistic will appear in the right panel when the model construction is complete.
Step-6: Note that the classification accuracy of model is about 69%.this indicates that we may
find more work. (Either in preprocessing or in selecting current parameters for the
classification)
Step-7: Now weka also lets us a view a graphical version of the classification tree. This can be
done by right clicking the last result set and selecting “visualize tree” from the pop-up menu.
Step-9: In the main panel under “text” options click the “supplied test set” radio button and
then click the “set” button. This wills pop-up a window which will allow you to open the file
containing test instances.
29
Dataset student .arff XCA512– Lab course based on Advanced Java
@relation student
@attribute age {<30,30-40,>40}
@attribute income {low, medium, high}
@attribute student {yes, no}
@attribute credit-rating {fair, excellent}
@attribute buyspc {yes, no}
@data
%
<30, high, no, fair, no
<30, high, no, excellent, no
30-40, high, no, fair, yes
>40, medium, no, fair, yes
>40, low, yes, fair, yes
>40, low, yes, excellent, no
30-40, low, yes, excellent, yes
<30, medium, no, fair, no
<30, low, yes, fair, no
>40, medium, yes, fair, yes
<30, medium, yes, excellent, yes
30-40, medium, no, excellent, yes
30-40, high, yes, fair, yes
>40, medium, no, excellent, no
%
The following screenshot shows the classification rules that were generated when j48 algorithm
is applied on the given dataset.
30
XCA512– Lab course based on Advanced Java
31
XCA512– Lab course based on Advanced Java
Experiment No. 13
Step 1: We begin the experiment by loading the data (employee.arff) into weka.
Step2: Next we select the “classify” tab and click “choose” button to select the “j48”classifier.
Step3: Now we specify the various parameters. These can be specified by clicking in the text
box to the right of the chose button. In this example, we accept the default values the default
version does perform some pruning but does not perform error pruning.
Step4: Under the “text “options in the main panel. We select the 10-fold cross validation as our
evaluation approach. Since we don’t have separate evaluation data set, this is necessary to get
a reasonable idea of accuracy of generated model.
Step-5: We now click ”start” to generate the model .the ASCII version of the tree as well as
evaluation statistic will appear in the right panel when the model construction is complete.
Step-6: Note that the classification accuracy of model is about 69%.this indicates that we may
find more work. (Either in preprocessing or in selecting current parameters for the
classification)
Step-7: Now weka also lets us a view a graphical version of the classification tree. This can be
done by right clicking the last result set and selecting “visualize tree” from the pop-up menu.
Step-9: In the main panel under “text “options click the “supplied test set” radio button and
then click the “set” button. This wills pop-up a window which will allow you to open the file
containing test instances.
32
XCA512– Lab course based on Advanced Java
The following screenshot shows the classification rules that were generated whenj48 algorithm
is applied on the given dataset.
33
XCA512– Lab course based on Advanced Java
34
XCA512– Lab course based on Advanced Java
Experiment No. 14
Step2: next we select the “classify” tab and click “choose” button to select the “id3”classifier.
Step3: now we specify the various parameters. These can be specified by clicking in the text
box to the right of the chose button. In this example, we accept the default values his default
version does perform some pruning but does not perform error pruning.
Step4: under the “text “options in the main panel. We select the 10-fold cross validation as our
evaluation approach. Since we don’t have separate evaluation data set, this is necessary to get
a reasonable idea of accuracy of generated model.
Step-5: we now click”start”to generate the model .the ASCII version of the tree as well as
evaluation statistic will appear in the right panel when the model construction is complete.
Step-6: note that the classification accuracy of model is about 69%.this indicates that we may
find more work. (Either in preprocessing or in selecting current parameters for the
classification)
Step-7: now weka also lets us a view a graphical version of the classification tree. This can be
done by right clicking the last result set and selecting “visualize tree” from the pop-up menu.
Step-9: In the main panel under “text “options click the “supplied test set” radio button and
then click the “set” button. This will show pop-up window which will allow you to open the
file containing test instances.
35
XCA512– Lab course based on Advanced Java
The following screenshot shows the classification rules that were generated when naive bayes
algorithm is applied on the given dataset.
36
XCA512– Lab course based on Advanced Java
37
XCA512– Lab course based on Advanced Java
Experiment No. 15
Step 1: Run the Weka explorer and load the data file iris.arff in preprocessing interface.
Step 2: Inorder to perform clustering select the ‘cluster’ tab in the explorer and click on the
choose button. This step results in a dropdown list of available clustering algorithms.
Step 4: Next click in text button to the right of the choose button to get popup window shown
in the screenshots. In this window we enter six on the number of clusters and we leave the value
of the seed on as it is. The seed value is used in generating a random number which is used for
making the internal assignments of instances of clusters.
Step 5 : Once of the option have been specified. We run the clustering algorithm there we must
make sure that they are in the ‘cluster mode’ panel. The use of training set option is selected
and then we click ‘start’ button. This process and resulting window are shown in the following
screenshots.
Step 6 : The result window shows the centroid of each cluster as well as statistics on the number
and the percent of instances assigned to different clusters. Here clusters centroid are means
vectors for each clusters. This clusters can be used to characterized the cluster.For eg, the
centroid of cluster1 shows the class iris.versicolor mean value of the sepal length is 5.4706,
sepal width 2.4765, petal width 1.1294, petal length 3.7941.
Step 7: Another way of understanding characterstics of each cluster through visualization ,we
can do this, try right clicking the result set on the result. List panel and selecting the visualize
cluster assignments.
38
XCA512– Lab course based on Advanced Java
The following screenshot shows the clustering rules that were generated when simple k means
algorithm is applied on the given dataset.
39
XCA512– Lab course based on Advanced Java
From the above visualization, we can understand the distribution of sepal length and petal
length in each cluster. For instance, for each cluster is dominated by petal length. In this case
by changing the color dimension to other attributes we can see their distribution with in each
of the cluster.
Step 8: We can assure that resulting dataset which included each instance along with its assign
cluster. To do so we click the save button in the visualization window and save the result iris
k-mean .The top portion of this file is shown in the following figure.
40
XCA512– Lab course based on Advanced Java
Experiment No. 16
Step 1: Run the Weka explorer and load the data file student.arff in preprocessing interface.
Step 2: Inorder to perform clustering select the ‘cluster’ tab in the explorer and click on the
choose button. This step results in a dropdown list of available clustering algorithms.
Step 4: Next click in text button to the right of the choose button to get popup window shown
in the screenshots. In this window we enter six on the number of clusters and we leave the value
of the seed on as it is. The seed value is used in generating a random number which is used for
making the internal assignments of instances of clusters.
Step 5 : Once of the option have been specified. We run the clustering algorithm there we must
make sure that they are in the ‘cluster mode’ panel. The use of training set option is selected
and then we click ‘start’ button. This process and resulting window are shown in the following
screenshots.
Step 6 : The result window shows the centroid of each cluster as well as statistics on the number
and the percent of instances assigned to different clusters. Here clusters centroid are means
vectors for each clusters. This clusters can be used to characterized the cluster.
From the above visualization, we can understand the distribution of age and instance number
in each cluster. For instance, for each cluster is dominated by age. In this case by changing the
color dimension to other attributes we can see their distribution with in each of the cluster.
Step 8: We can assure that resulting dataset which included each instance along with its assign
cluster. To do so we click the save button in the visualization window and save the result student
k-mean .The top portion of this file is shown in the following figure.
41
XCA512– Lab course based on Advanced Java
The following screenshot shows the clustering rules that were generated when simple k- means
algorithm is applied on the given dataset.
42
XCA512– Lab course based on Advanced Java
43