Data Mining Lab
Data Mining Lab
AUTONOMOUS
(Approved by AICTE New Delhi, NAAC Accredited, Affiliated to JNTU Kakinada, ISO 9001-2015 Certified)
Bakkannapalem Village, Madhurawada Post, Visakhapatnam – 530 048
Estd: 2008
Estd: 2008
CERTIFICATE
Year ________________________
Signature
External Examiner
Dt.:____________
INDEX
PAGE
SNO. DATE EXPERIMENT NAME SIGN
NO
Study of WEKA tool and applying data mining
1 techniques on following data sets in ARFF or CSV 1-6
file Format.
1
Weka GUI Chooser:
Click the “Explorer” button to launch the Weka Explorer. This GUI lets you load datasets and run
classification algorithms. It also provides other features like :
Data filtering,
Clustering,
Association rule extraction,
Visualization
Data in WEKA : WEKA prefers to load data in ARFF [Link] is an extension of the CSV (comma
separated values) file format . This is a simple format where data is laid out in a table of rows and
columns and a comma is used to separate the values in a row. Quotes may also be used , if the data
contains strings of text with spaces. where a header is used that provides a metadata about the data types
in the columns.
The CSV format is easily exported from MS-Excel and easily converted into CSV [Link] you do not
have a CSV file ,use the iris flower dataset. Download the file from UCI Machine Learning repository
and save it to your current working directory as [Link].
2
· [Link]
· [Link]
How to load CSV data in WEKA:
Steps to convert dataset from CSV format to ARFF format:
1. Start the WEKA chooser
2. Open the ARFF viewer by clicking “ Tools” in the menu and select “ArffViewer”.
4. Open your CSV file in the ARFF-Viewer by clicking the “File “ menu and select “Open”.
Navigate to your current working directory. Change the” Files of type:” filter to CSV data files
(*.csv). Select your file and click the “Open “ button. Load CSV in ARFF Viewer.
5. You should see a sample of your csv file loaded into the ARFF-Viewer.
6. Save your dataset in ARFF format by clicking the “File “ menu and selecting “save as”. Enter a
file name with a arff extension and click the “Save “ button. You can now load your. arff file
directly into WEKA.
Note: The ARFF-Viewer provides options for modifying your dataset before saving. For example you can
change values, change the name of attributes and change their data types.
Load CSV files in WEKA Explorer:
WEKA Tool and Explorer window [Link] can load your CSV files directly in the Weka Explorer
Interface.
1. Start the WEKA GUI Chooser.
4. Navigate to your current working directory . Change the “Files of Tyoe” to CSV data files(*.csv).
Select your file and click the “ Open “ button.
5. You can work with the data directly. You can also save your dataset in ARFF format by clicking
the “Save “button and typing a filename.
IRIS DATASET
3
7.0 3.2 4.7 1.4 Iris-versicolor
4
Weather Dataset
Outlook Temperature Humidity Windy Play
sunny 85 85 FALSE no
sunny 80 90 TRUE no
overcast 83 86 FALSE yes
rainy 70 96 FALSE yes
rainy 68 80 FALSE yes
rainy 65 70 TRUE no
overcast 64 65 TRUE yes
sunny 72 95 FALSE no
sunny 69 70 FALSE yes
rainy 75 80 FALSE yes
sunny 75 70 TRUE yes
overcast 72 90 TRUE yes
overcast 81 75 FALSE yes
rainy 71 91 TRUE no
5
6
Experiment 2
Implementation / Usage of WEKA for classification of datasets such as
customer’s data, weather forecasting data, agricultural data etc.
7
o Precision, recall, F-measure
Visualize Results
Right-click on the result → Choose Visualize tree or Visualize classify
8
Classifier Output of Weather Dataset
9
Weather Nominal Dataset
Outlook Temperature Humidity Windy Play
sunny hot high FALSE no
sunny hot high TRUE no
overcast hot high FALSE yes
rainy mild high FALSE yes
rainy cool normal FALSE yes
rainy cool normal TRUE no
overcast cool normal TRUE yes
sunny mild high FALSE no
sunny cool normal FALSE yes
rainy mild normal FALSE yes
sunny mild normal TRUE yes
overcast mild high TRUE yes
overcast hot normal FALSE yes
rainy mild high TRUE no
10
11
12
Diabetes Dataset
Preg Plas Pres Skin Insu Mass Pedi Age Class
6 148 72 35 0 33.6 0.627 50 tested_positive
1 85 66 29 0 26.6 0.351 31 tested_negative
8 183 64 0 0 23.3 0.672 32 tested_positive
1 89 66 23 94 28.1 0.167 21 tested_negative
0 137 40 35 168 43.1 2.288 33 tested_positive
5 116 74 0 0 25.6 0.201 30 tested_negative
3 78 50 32 88 31 0.248 26 tested_positive
10 115 0 0 0 35.3 0.134 29 tested_negative
2 197 70 45 543 30.5 0.158 53 tested_positive
8 125 96 0 0 0 0.232 54 tested_positive
4 110 92 0 0 37.6 0.191 30 tested_negative
10 168 74 0 0 38 0.537 34 tested_positive
10 139 80 0 0 27.1 1.441 57 tested_negative
1 189 60 23 846 30.1 0.398 59 tested_positive
5 166 72 19 175 25.8 0.587 51 tested_positive
13
14
15
EXPERIMENT -3
Load a Dataset
16
Opens a scatter plot matrix
You can:
o Adjust jitter to spread overlapping points
o Change coloring based on class attribute
o Click on a cell to zoom into a 2D plot
Class Nominal — — —
Visual plots show clear separation between Iris Setosa, Versicolour, and Virginica
17
Cluster Output:
EM
==
18
Cluster
Attribute 0
(1)
=====================================================================
===================================
-0.578temperature+0.571outlook=rainy-0.506outlook=sunny-0.227windy=FALSE-
0.164humidity...
mean -0
std. dev. 1.3436
-
0.68outlook=overcast+0.443humidity+0.424outlook=rainy+0.334windy=FALSE+0.217outlook=
sunny...
mean 0
std. dev. 1.2144
0.567outlook=sunny-0.443windy=FALSE-0.432outlook=overcast-0.414humidity-
0.312temperature...
mean -0
std. dev. 1.0953
0.738windy=FALSE-0.667humidity-0.077temperature-
0.052outlook=overcast+0.033outlook=rainy...
mean -0
std. dev. 0.8579
-0.748temperature+0.4 humidity-
0.348outlook=rainy+0.308windy=FALSE+0.191outlook=overcast...
mean 0
std. dev. 0.5964
19
play
yes 10
no 6
[total] 16
Clustered Instances
0 14 (100%)
Evaluator: [Link]
Search: [Link] -T -1.7976931348623157E308 -N -1
Relation: weather_principal components-
[Link]-R0.95-A5-M-1
Instances: 14
Attributes: 6
-0.578temperature+0.571outlook=rainy-0.506outlook=sunny-0.227windy=FALSE-
0.164humidity...
20
-
0.68outlook=overcast+0.443humidity+0.424outlook=rainy+0.334windy=FALSE+0.217outlook=
sunny...
0.567outlook=sunny-0.443windy=FALSE-0.432outlook=overcast-0.414humidity-
0.312temperature...
0.738windy=FALSE-0.667humidity-0.077temperature-
0.052outlook=overcast+0.033outlook=rainy...
-0.748temperature+0.4 humidity-
0.348outlook=rainy+0.308windy=FALSE+0.191outlook=overcast...
play
Evaluation mode: evaluate on all training data
Search Method:
Attribute ranking.
21
Selected attributes: 4,2,3,1,5 : 5
22
EXPERIMENT -4
ObjectiveTo apply and observe the effects of data preprocessing techniques such as:
23
o Filter: [Link]
1. Load [Link]
2. Apply Discretize to temperature and humidity
3. Use Normalize on numeric attributes
4. Apply AttributeSelection to reduce features
5. Save the final dataset for classification or clustering
24
Associator Output:
Apriori
=======
25
Size of set of large itemsets L(3): 4
26
27
EXPERIMENT-5
To demonstrate feature selection in WEKA and identify prominent attribute subsets from
various datasets, you can design an experiment using the Select Attributes tab in WEKA
Explorer. Here's how to do it:
Objective
To apply different attribute evaluators and search methods in WEKA to select the most
relevant features from datasets like:
Step-by-Step Procedure
28
| CfsSubsetEval | Selects features highly correlated with the class and low inter correlation |
Click Start
WEKA will output:
o Selected attributes
o Evaluation metrics
o Option to visualize results
29
Example: Agricultural Dataset
Evaluator: CfsSubsetEval
Search: BestFirst
Result: Selected attributes like soil_type, rainfall, fertilizer_use
These features showed strong correlation with crop_yield and minimal redundancy
Classifier Output:
outlook = sunny
| humidity = high: no (3.0)
| humidity = normal: yes (2.0)
outlook = overcast: yes (4.0)
outlook = rainy
| windy = TRUE: no (2.0)
| windy = FALSE: yes (3.0)
30
Number of Leaves : 5
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area
Class
0.556 0.600 0.625 0.556 0.588 -0.043 0.633 0.758 yes
0.400 0.444 0.333 0.400 0.364 -0.043 0.633 0.457 no
Weighted Avg. 0.500 0.544 0.521 0.500 0.508 -0.043 0.633 0.650
a b <-- classified as
5 4 | a = yes
3 2 | b = no
31
Attribute selection output:
=== Run information ===
Search Method:
Attribute ranking.
Ranked attributes:
0 4 windy
0 3 humidity
0 2 temperature
0 1 outlook
32
33
EXPERIMENT-6
To measure how much each attribute (e.g., Outlook, windy, humidity, temperature)
Choose:
o Evaluator: InfoGainAttributeEval
o Search Method: Ranker
Click Start,WEKA will rank attributes based on their information gain with respect to
the class
Interpret Results
34
Example:
Attribute Info Gain
Outlook 0.2467
Windy 0.481
humidity 0.0
temperature 0.0
Evaluator: [Link]
Search: [Link] -T -1.7976931348623157E308 -N -1
Relation: [Link]
Instances: 14
Attributes: 5
outlook
temperature
humidity
windy
play
Evaluation mode: evaluate on all training data
Search Method:
Attribute ranking.
35
Attribute Evaluator (supervised, Class (nominal): 5 play):
Information Gain Ranking Filter
Ranked attributes:
0.2467 1 outlook
0.1518 3 humidity
0.0481 4 windy
0.0292 2 temperature
36
37
EXPERIMENT-7
Handle missing values: Filter -> Choose -> Unsupervised -> Attribute ->
ReplaceMissingValues.
Normalize data (optional): Filter -> Unsupervised -> Attribute -> Normalize.
Remove irrelevant attributes: Filter -> Unsupervised -> Attribute -> Remove.
(Optional)
38
Step 6: Visualize the Decision Tree
Additional Tips
Output:
Play=no
Play=yes
Play=no
39
EXPERIMENT-8
What is ID3?
4. Go to classify tab:
40
Recommended: 10-fold cross-validation.
Alternatively: Use percentage split or training set.
Click start.
WEKA will output:
Decision tree structure
Classification accuracy
Confusion matrix
Detailed statistics (precision, recall, F-measure)
Classifier Output:
41
=== Classifier model (full training set) ===
outlook = sunny
| humidity = high: no (3.0)
| humidity = normal: yes (2.0)
outlook = overcast: yes (4.0)
outlook = rainy
| windy = TRUE: no (2.0)
| windy = FALSE: yes (3.0)
Number of Leaves : 5
42
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area
Class
0.556 0.600 0.625 0.556 0.588 -0.043 0.633 0.758 yes
0.400 0.444 0.333 0.400 0.364 -0.043 0.633 0.457 no
Weighted Avg. 0.500 0.544 0.521 0.500 0.508 -0.043 0.633 0.650
a b <-- classified as
5 4 | a = yes
3 2 | b = no
Attribute selection output:
=== Run information ===
Search Method:
Attribute ranking.
43
Using Wrapper Subset Evaluator
Learning scheme: [Link]
Scheme options:
Subset evaluation: classification accuracy
Number of folds for accuracy estimation: 5
Ranked attributes:
0 4 windy
0 3 humidity
0 2 temperature
0 1 outlook
44
45
EXPERIMENT-9
Click Open file and choose a dataset in .arff format (e.g., [Link]).
You’ll see the dataset summary with attributes and instances.
Ensure the class attribute (the one you want to predict) is correctly set.
o Use the dropdown at the bottom to select the class attribute if needed.
You can also filter or transform attributes using the Preprocess tab.
46
o Confusion matrix
o Accuracy
o Precision, Recall, F-measure
o Class-wise predictions
Click on the Save model button to export the trained classifier for future use.
Classify:
47
humidity
windy
play
Test mode: 10-fold cross-validation
=== Classifier model (full training set) ===
Naive Bayes Classifier
Class
Attribute yes no
(0.63) (0.38)
=============================
outlook
sunny 3.0 4.0
overcast 5.0 1.0
rainy 4.0 3.0
[total] 12.0 8.0
temperature
hot 3.0 3.0
mild 5.0 3.0
cool 4.0 2.0
[total] 12.0 8.0
humidity
high 4.0 5.0
normal 7.0 2.0
[total] 11.0 7.0
windy
TRUE 4.0 4.0
FALSE 7.0 3.0
[total] 11.0 7.0
Time taken to build model: 0 seconds
=== Stratified cross-validation ===
=== Summary ===
Correctly Classified Instances 8 57.1429 %
Incorrectly Classified Instances 6 42.8571 %
48
Kappa statistic -0.0244
Mean absolute error 0.4374
Root mean squared error 0.4916
Relative absolute error 91.8631 %
Root relative squared error 99.6492 %
Total Number of Instances 14
=== Detailed Accuracy By Class ===
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area
Class
0.778 0.800 0.636 0.778 0.700 -0.026 0.578 0.697 yes
0.200 0.222 0.333 0.200 0.250 -0.026 0.578 0.557 no
Weighted Avg. 0.571 0.594 0.528 0.571 0.539 -0.026 0.578 0.647
=== Confusion Matrix ===
a b <-- classified as
7 2 | a = yes
4 1 | b = no
49
EXPERIMENT -10
Click Open file and select a dataset in .arff format (e.g., [Link], [Link]).
Weka will display the dataset summary with attributes and instances.
Ensure the class attribute (the one you want to predict) is correctly set.
o Use the dropdown at the bottom to select the class attribute if needed.
You can apply filters to normalize or standardize features (recommended for k-NN).
50
o Percentage split (e.g., 70% training, 30% testing).
o Use training set – not ideal for generalization.
Click Save model to export the trained classifier for future use.
Try setting k=3 and using 10-fold cross-validation to see how well k-NN performs on this classic
dataset.
51
Classify:
52
0.920 0.030 0.939 0.920 0.929 0.895 0.958 0.919 Iris-virginica
Weighted Avg. 0.953 0.023 0.953 0.953 0.953 0.930 0.974 0.943
=== Confusion Matrix ===
a b c <-- classified as
50 0 0 | a = Iris-setosa
0 47 3 | b = Iris-versicolor
0 4 46 | c = Iris-virginica
53
EXPERIMENT-11
learningRate: Controls how much weights and biases are updated per iteration.
momentum: Helps accelerate learning and avoid local minima.
trainingTime: Number of epochs (iterations) for training.
hiddenLayers: Structure of hidden layers (e.g., “a” for (attributes+classes)/2).
decay: If set to true, learning rate decays over time.
These parameters directly affect how weights and biases are updated during backpropagation.
After training, you can inspect the network structure and weights:
o Right-click the result in the Result list.
54
o Choose "Visualize classifier errors" or "View model" to see the network.
Switch to KnowledgeFlow.
Use components like ArffLoader, Classifier, and ModelPerformanceChart to observe
training and ROC curves.
Classifier output:
55
Threshold 1.0692845992273177
Node 3 3.8988736877894024
Node 4 -9.768910360340264
Node 5 -8.599134493151348
Sigmoid Node 2
Inputs Weights
Threshold -1.007176238343649
Node 3 -4.2184061338270356
Node 4 -3.626059686321118
Node 5 8.805122981737854
Sigmoid Node 3
Inputs Weights
Threshold 3.382485556685675
Attrib sepallength 0.9099827458022276
Attrib sepalwidth 1.5675138827531276
Attrib petallength -5.037338107319895
Attrib petalwidth -4.915469682506087
Sigmoid Node 4
Inputs Weights
Threshold -3.330573592291832
Attrib sepallength -1.1116750023770083
Attrib sepalwidth 3.125009686667653
Attrib petallength -4.133137022912305
Attrib petalwidth -4.079589727871456
Sigmoid Node 5
Inputs Weights
Threshold -7.496091023618089
Attrib sepallength -1.2158878822058787
Attrib sepalwidth -3.5332821317534897
Attrib petallength 8.401834252274096
Attrib petalwidth 9.460215580472827
Class Iris-setosa
Input
56
Node 0
Class Iris-versicolor
Input
Node 1
Class Iris-virginica
Input
Node 2
Time taken to build model: 0.08 seconds
=== Stratified cross-validation ===
=== Summary ===
Correctly Classified Instances 146 97.3333 %\
Incorrectly Classified Instances 4 2.6667 %
Kappa statistic 0.96
Mean absolute error 0.0327
Root mean squared error 0.1291
Relative absolute error 7.3555 %
Root relative squared error 27.3796 %
Total Number of Instances 150
=== Detailed Accuracy By Class ===
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area
Class
1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 Iris-setosa
0.960 0.020 0.960 0.960 0.960 0.940 0.996 0.993 Iris-versicolor
0.960 0.020 0.960 0.960 0.960 0.940 0.996 0.993 Iris-virginica
Weighted Avg. 0.973 0.013 0.973 0.973 0.973 0.960 0.998 0.995
=== Confusion Matrix ===
a b c <-- classified as
50 0 0 | a = Iris-setosa
0 48 2 | b = Iris-versicolor
0 2 48 | c = Iris-virginica
57
Classifier Visualizer:
58
Experiment -12
K-Means clustering in Weka using its Explorer interface. This is one of the most intuitive ways
to understand unsupervised learning,
Tip: Make sure your dataset contains numeric attributes, as K-Means relies on distance
calculations.
Click on the text box next to SimpleKMeans to open the configuration window.
Set the number of clusters (K) — for example, 3 for the iris dataset.
You can also adjust:
o Seed (for random initialization)
o MaxIterations
o PreserveInstancesOrder (useful for mapping cluster assignments)
59
Click Start to begin clustering.
Weka will output cluster centroids, instance assignments, and statistics.
Weka displays:
o Cluster centroids (mean values for each attribute)
o Number of instances per cluster
o Percentage distribution
Use this to interpret how well the algorithm grouped your data.
Cluster:
60
class
Test mode: evaluate on training data
=== Clustering model (full training set) ===
kMeans
======
Number of iterations: 7
Within cluster sum of squared errors: 62.1436882815797
Initial starting points (random):
Cluster 0: 6.1,2.9,4.7,1.4,Iris-versicolor
Cluster 1: 6.2,2.9,4.3,1.3,Iris-versicolor
Missing values globally replaced with mean/mode
Final cluster centroids:
Cluster#
Attribute Full Data 0 1
(150.0) (100.0) (50.0)
==================================================================
sepallength 5.8433 6.262 5.006
sepalwidth 3.054 2.872 3.418
petallength 3.7587 4.906 1.464
petalwidth 1.1987 1.676 0.244
class Iris-setosa Iris-versicolor Iris-setosa
Time taken to build model (full training data) : 0.01 seconds
=== Model and evaluation on training set ===
Clustered Instances
0 100 ( 67%)
1 50 ( 33%)
61
Cluster Visulizer:
62
EXPERIMENT-13
In Weka is a classic data mining task that helps uncover hidden associations in transactional
datasets—like discovering that people who buy bread and butter often also buy jam.
3. Configure Parameters
63
Output:
64
6. biscuits=t frozen foods=t vegetables=t total=high 797 ==> bread and cake=t 725
<conf:(0.91)> lift:(1.26) lev:(0.03) [151] conv:(3.06)
7. baking needs=t biscuits=t vegetables=t total=high 772 ==> bread and cake=t 701
<conf:(0.91)> lift:(1.26) lev:(0.03) [145] conv:(3.01)
8. biscuits=t fruit=t total=high 954 ==> bread and cake=t 866 <conf:(0.91)> lift:(1.26)
lev:(0.04) [179] conv:(3)
9. frozen foods=t fruit=t vegetables=t total=high 834 ==> bread and cake=t 757 <conf:(0.91)>
lift:(1.26) lev:(0.03) [156] conv:(3)
10. frozen foods=t fruit=t total=high 969 ==> bread and cake=t 877 <conf:(0.91)> lift:(1.26)
lev:(0.04) [179] conv:(2.92)
65
EXPERIMENT -14
These parameters shape the frequent itemsets and association rules that FP-Growth will discover.
66
Output:
Relation: supermarket
Instances: 4627
Attributes: 217
1. [fruit=t, frozen foods=t, biscuits=t, total=high]: 788 ==> [bread and cake=t]: 723 <conf:(0.92)>
lift:(1.27) lev:(0.03) conv:(3.35)
2. [fruit=t, baking needs=t, biscuits=t, total=high]: 760 ==> [bread and cake=t]: 696 <conf:(0.92)>
lift:(1.27) lev:(0.03) conv:(3.28)
3. [fruit=t, baking needs=t, frozen foods=t, total=high]: 770 ==> [bread and cake=t]: 705 <conf:(0.92)>
lift:(1.27) lev:(0.03) conv:(3.27)
4. [fruit=t, vegetables=t, biscuits=t, total=high]: 815 ==> [bread and cake=t]: 746 <conf:(0.92)>
lift:(1.27) lev:(0.03) conv:(3.26)
5. [fruit=t, party snack foods=t, total=high]: 854 ==> [bread and cake=t]: 779 <conf:(0.91)> lift:(1.27)
lev:(0.04) conv:(3.15)
6. [vegetables=t, frozen foods=t, biscuits=t, total=high]: 797 ==> [bread and cake=t]: 725 <conf:(0.91)>
lift:(1.26) lev:(0.03) conv:(3.06)
7. [vegetables=t, baking needs=t, biscuits=t, total=high]: 772 ==> [bread and cake=t]: 701
<conf:(0.91)> lift:(1.26) lev:(0.03) conv:(3.01)
67
8. [fruit=t, biscuits=t, total=high]: 954 ==> [bread and cake=t]: 866 <conf:(0.91)> lift:(1.26) lev:(0.04)
conv:(3)
9. [fruit=t, vegetables=t, frozen foods=t, total=high]: 834 ==> [bread and cake=t]: 757 <conf:(0.91)>
lift:(1.26) lev:(0.03) conv:(3)
10. [fruit=t, frozen foods=t, total=high]: 969 ==> [bread and cake=t]: 877 <conf:(0.91)> lift:(1.26)
lev:(0.04) conv:(2.92)
68
EXPERIMENT-15
Experiment to compare the performance of various data mining algorithms
on the give database.
69
Review metrics like:
o Accuracy: % of correctly classified instances.
o Kappa Statistic: Agreement beyond chance.
o Confusion Matrix: Breakdown of predictions.
o ROC Area: Quality of probabilistic predictions.
Classifier Output:
70
=== Classifier model (full training set) ===
71
| | | | | | | pedi > 0.396: tested_negative (3.0)
| | | | | | pres > 82: tested_negative (4.0)
| | | | age > 61: tested_negative (4.0)
| mass > 29.9
| | plas <= 157
| | | pres <= 61: tested_positive (15.0/1.0)
| | | pres > 61
| | | | age <= 30: tested_negative (40.0/13.0)
| | | | age > 30: tested_positive (60.0/17.0)
| | plas > 157: tested_positive (92.0/12.0)
Number of Leaves : 20
72
TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area
Class
0.814 0.403 0.790 0.814 0.802 0.417 0.751 0.811 tested_negative
0.597 0.186 0.632 0.597 0.614 0.417 0.751 0.572 tested_positive
Weighted Avg. 0.738 0.327 0.735 0.738 0.736 0.417 0.751 0.727
a b <-- classified as
407 93 | a = tested_negative
108 160 | b = tested_positive
73
74