0% found this document useful (0 votes)
11 views78 pages

Data Mining Lab

The document is a laboratory manual for the Data Mining Laboratory at Baba Institute of Technology and Sciences, detailing various experiments using the WEKA tool for data mining. It includes instructions for loading datasets, applying classification algorithms, and visualizing results, along with examples of datasets like Iris and weather data. The manual serves as a guide for students to perform practical exercises in data mining techniques.

Uploaded by

dhanushadas2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views78 pages

Data Mining Lab

The document is a laboratory manual for the Data Mining Laboratory at Baba Institute of Technology and Sciences, detailing various experiments using the WEKA tool for data mining. It includes instructions for loading datasets, applying classification algorithms, and visualizing results, along with examples of datasets like Iris and weather data. The manual serves as a guide for students to perform practical exercises in data mining techniques.

Uploaded by

dhanushadas2
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

BABA INSTITUTE OF TECHNOLOGY AND SCIENCES

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

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

DATA MINING LABORATORY MANUAL

BABA INSTITUTE OF TECHNOLOGY AND SCIENCES


AUTONOMOUS
(Approved by AICTE New Delhi, NAAC Accredited, Affiliated to JNTU Kakinada, ISO 9001-2015 Certified)
Bakkannapalem Village, Madhurawada Post, Visakhapatnam – 530 048
BABA INSTITUTE OF TECHNOLOGY AND SCIENCES (A)
Promoted by Ambedkar Educational & Welfare Society
(Approved by AICTE New Delhi, Accredited by NAAC with “A ‘Grade, Affiliated to JNTU GV)
An ISO 9001:2015 Certified Institution
P. M. Palem, Madhurawada Post, Visakhapatnam – 530 048
Phone: Off: 0891-2569933
Email: principal@[Link]
Website: [Link]

Estd: 2008

CERTIFICATE

This is to certify that this is a bonified record of _______________________________________

Performed by Mr. / Ms. __________________________________________________________

of [Link]. / [Link]. ________________________ Reg. No. _________________________

Year ________________________

No. of Exercises/ Practicals/ Programs performed : ____________________________________

Signature

Faculty-In-Charge Head of the Department

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.

Implementation / Usage of WEKA for classification


2 of datasets such as customer’s data, weather 7-15
forecasting data, agricultural data etc.
Experiment to summarize and visualization of
3 16-22
various datasets.
Experiment to demonstrate various data pre-
4 23-27
processing techniques
Experiment to select prominent feature subsets of
5 28-33
various datasets
Experiment to Evaluate Information Gain of an
6 34-37
attribute in the student database
Demonstration of classification rule process using
7 38-39
j48 decision tree algorithm
Demonstration of classification rule process using
8 40-45
ID3 decision tree algorithm
Experiment to predict the class using the Bayesian
9 46-49
classification
Experiment to predict the class using the k-Nearest
10 50-53
Neighbor classification
Experiment to implement weight & bias updating
11 54-58
using the Back propagation Neural Network
Demonstration of clustering process using k-means
12 59-62
algorithm
Demonstration of mining frequent patterns using
13 63-65
Apriori algorithm
Demonstration of mining frequent patterns using FP-
14 66-68
Growth algorithm
Experiment to compare the performance of various
15 69-74
data mining algorithms on the give database.
WEKA
Waikato Environment for Knowledge Analysis (Weka)
It is a suite of machine learning software developed at the University of Waikato, New Zealand. The
program is written in Java. It contains a Collection of visualization tools and algorithms for data analysis
and predictive modeling coupled with graphical user interface.
Weka supports several standard data mining tasks, more specifically:
Data pre-processing,
Clustering,
Classification,
Regressing,
Visualization and
Feature selection.

Let’s Start Weka


If you installed a successful weka tool you get an image looks like on your desktop or by double clicking
on the [Link] file. This is a GUI window.(WEKA GUI Chooser). This window displays four types of
options :
Explorer
Experimenter
Knowledge Flow
Simple CLI (Command line interface)

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].

Sample Weka Data Sets


Below are some sample WEKA data sets, in arff format.
· [Link]
· [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”.

3. You will be presented with an empty ARFF-Viewer window.

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.

2. Lauch the Weka Explorer by clicking the “ Explorer” button.

3. Click the “Open File “ button.

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

Sepal Length Sepal Width Petal Length Petal Width Class


5.1 3.5 1.4 0.2 Iris - Setosa
4.9 3.0 1.4 0.2 Iris – Setosa
4.7 3.2 1.3 0.2 Iris – Setosa
4.6 3.1 1.5 0.2 Iris – Setosa
5.0 3.6 1.4 0.2 Iris - Setosa

3
7.0 3.2 4.7 1.4 Iris-versicolor

6.4 3.2 4.5 1.5 Iris-versicolor

6.9 3.1 4.9 1.5 Iris-versicolor

5.5 2.3 4.0 1.3 Iris-versicolor

6.5 2.8 4.6 1.5 Iris-versicolor

6.3 3.3 6.0 2.5 Iris-virginica


5.8 2.7 5.1 1.9 Iris-virginica
7.1 3.0 5.9 2.1 Iris-virginica
6.3 2.9 5.6 1.8 Iris-virginica
6.5 3.0 5.8 2.2 Iris-virginica

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.

Load Your Dataset


 Format: Use .arff or .csv files.
 Open WEKA → Explorer → Preprocess tab → Click Open file.
 Example datasets:
o [Link] for weather forecasting
o [Link] for agricultural data
o Custom customer datasets (e.g., bank loan data)
Preprocess the Data
 Handle missing values using filters.
 Normalize or discretize attributes if needed.
 Select relevant features using attribute selection.
Choose a Classification Algorithm
 Go to the Classify tab.
 Click Choose and select a classifier:
o trees → J48 (Decision Tree) – great for interpretability
o bayes → NaiveBayes – fast and effective for probabilistic models
o functions → MultilayerPerceptron – for neural network-based classification
o meta → RandomForest – robust ensemble method
Set Evaluation Method
 Options:
o Cross-validation (e.g., 10-fold) – recommended for general performance testing.
o Percentage split – divide data into training/testing sets.
o Use training set – for quick testing.
Run the Classifier
 Click Start to train and test the model.
 Review output:
o Accuracy
o Confusion matrix

7
o Precision, recall, F-measure
Visualize Results
 Right-click on the result → Choose Visualize tree or Visualize classify

Classifier output of Iris Dataset

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

Experiment to summarize and visualization of various datasets .

Load a Dataset

 Open WEKA → Click Explorer


 Go to the Preprocess tab
 Click Open file and choose a dataset (.arff or .csv)
 Example datasets:
o [Link] – flower classification
o [Link] – weather prediction
o [Link] – political voting data

Summarize the Dataset

 After loading, WEKA displays:


o Number of instances (rows)
o Number of attributes (columns)
o For each attribute:
 Type (numeric or nominal)
 Missing values
 Distinct values
 Mean, min, max (for numeric)
 Class distribution (for target variable)

Visualize Individual Attributes

 In the Preprocess tab, click on an attribute


 WEKA shows a histogram of its distribution
 Use this to spot skewed data, outliers, or class imbalance

Visualize All Attributes

 Click Visualize All (bottom of Preprocess tab)

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

Visualize Classification or Clustering Results

 After running a model (e.g., J48 or KMeans):


o Right-click the result in the Result list
o Choose Visualize classifier errors or Visualize cluster assignments
o Misclassified points are boxed in predicted class color
o Cluster plots show groupings and centroids

Example Visualization: Iris Dataset

Attribute Type Mean Std Dev Class Correlation

Sepal Length Numeric 5.84 0.83 0.78

Petal Width Numeric 1.20 0.76 0.95 (high!)

Class Nominal — — —

 Visual plots show clear separation between Iris Setosa, Versicolour, and Virginica

Tips for Better Visualization

 Use jitter to reveal overlapping points


 Filter out irrelevant attributes before plotting
 Try Principal Component Analysis (PCA) for dimensionality reduction
 Use color coding to highlight class or cluster membership

17
Cluster Output:

=== Run information ===

Scheme: [Link] -I 100 -N -1 -X 10 -max -1 -ll-cv 1.0E-6 -ll-iter 1.0E-6 -M


1.0E-6 -K 10 -num-slots 1 -S 100
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...
-
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
Test mode: evaluate on training data

=== Clustering model (full training set) ===

EM
==

Number of clusters selected by cross validation: 1


Number of iterations performed: 2

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

Time taken to build model (full training data) : 0.03 seconds

=== Model and evaluation on training set ===

Clustered Instances

0 14 (100%)

Log likelihood: -7.6577

Attribute selection output:

=== Run information ===

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

=== Attribute Selection on all input data ===

Search Method:
Attribute ranking.

Attribute Evaluator (supervised, Class (nominal): 6 play):


Correlation Ranking Filter
Ranked attributes:
0.444 4 0.738windy=FALSE-0.667humidity-0.077temperature-
0.052outlook=overcast+0.033outlook=rainy...
0.399 2 -
0.68outlook=overcast+0.443humidity+0.424outlook=rainy+0.334windy=FALSE+0.217outlook=
sunny...
0.301 3 0.567outlook=sunny-0.443windy=FALSE-0.432outlook=overcast-0.414humidity-
0.312temperature...
0.135 1 -0.578temperature+0.571outlook=rainy-0.506outlook=sunny-0.227windy=FALSE-
0.164humidity...
0.133 5 -0.748temperature+0.4 humidity-
0.348outlook=rainy+0.308windy=FALSE+0.191outlook=overcast...

21
Selected attributes: 4,2,3,1,5 : 5

22
EXPERIMENT -4

Experiment to demonstrate various data pre-processing techniques

To design an experiment in WEKA to demonstrate various data preprocessing techniques


using a sample dataset like [Link] or [Link]:

ObjectiveTo apply and observe the effects of data preprocessing techniques such as:

 Handling missing values


 Normalization and standardization
 Discretization
 Attribute selection
 Data transformation

Step 1: Load the Dataset

 Open WEKA → Explorer → Preprocess tab


 Click Open file and select a dataset (.arff or .csv)
 WEKA will display:
o Number of instances and attributes
o Summary statistics for each attribute

Step 2: Handle Missing Values

 Use filter: [Link]


 Apply it to fill missing values with mean/mode
 Alternatively, remove instances with missing values using RemoveWithValues

Step 3: Normalize or Standardize Data

 Normalize: Scales values to [0,1]


o Filter: [Link]
 Standardize: Centers data to mean 0 and standard deviation 1

23
o Filter: [Link]

Step 4: Discretize Numeric Attributes

 Converts numeric values into categorical bins


 Filter: [Link]
 Useful for algorithms that require nominal data (e.g., Apriori)

Step 5: Attribute Selection

 Removes irrelevant or redundant attributes


 Filter: [Link]
 Improves model performance and reduces complexity

Step 6: Data Transformation

 Convert string attributes to numeric: StringToNominal or StringToWordVector


 Add new attributes: AddExpression or Add

Step 7: Visualize Preprocessed Data

 Use Visualize All to inspect attribute distributions


 Check for outliers, skewness, and class balance

Sample Experiment Flow

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:

=== Run information ===

Scheme: [Link] -N 10 -T 0 -C 0.9 -D 0.05 -U 1.0 -M 0.1 -S -1.0 -c -1


Relation: [Link]-
[Link]-Rfirst-last-S1-P0.1-
[Link]-S1.0-T0.0-
[Link]-
B10-M-1.0-Rfirst-last-precision6
Instances: 14
Attributes: 5
outlook
temperature
humidity
windy
play
=== Associator model (full training set) ===

Apriori
=======

Minimum support: 0.25 (3 instances)


Minimum metric <confidence>: 0.9
Number of cycles performed: 15

Generated sets of large itemsets:

Size of set of large itemsets L(1): 12

Size of set of large itemsets L(2): 20

25
Size of set of large itemsets L(3): 4

Best rules found:

1. humidity=normal 6 ==> play=yes 6 <conf:(1)> lift:(1.56) lev:(0.15) [2] conv:(2.14)


2. outlook=overcast 4 ==> play=yes 4 <conf:(1)> lift:(1.56) lev:(0.1) [1] conv:(1.43)
3. humidity=normal windy=FALSE 4 ==> play=yes 4 <conf:(1)> lift:(1.56) lev:(0.1) [1]
conv:(1.43)
4. temperature=hot 3 ==> windy=FALSE 3 <conf:(1)> lift:(1.75) lev:(0.09) [1] conv:(1.29)
5. outlook=sunny play=no 3 ==> humidity=high 3 <conf:(1)> lift:(2) lev:(0.11) [1] conv:(1.5)
6. outlook=sunny humidity=high 3 ==> play=no 3 <conf:(1)> lift:(2.8) lev:(0.14) [1]
conv:(1.93)
7. outlook=rainy play=yes 3 ==> windy=FALSE 3 <conf:(1)> lift:(1.75) lev:(0.09) [1]
conv:(1.29)
8. outlook=rainy windy=FALSE 3 ==> play=yes 3 <conf:(1)> lift:(1.56) lev:(0.08) [1]
conv:(1.07)
9. temperature=cool play=yes 3 ==> humidity=normal 3 <conf:(1)> lift:(2.33) lev:(0.12) [1]
conv:(1.71)
10. temperature=cool humidity=normal 3 ==> play=yes 3 <conf:(1)> lift:(1.56) lev:(0.08) [1]
conv:(1.07)

26
27
EXPERIMENT-5

Experiment to select prominent feature subsets of various datasets.

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:

 [Link] (weather prediction)


 [Link] (customer segmentation)
 [Link] (agricultural analysis)

Step-by-Step Procedure

Load the Dataset

 Open WEKA → Explorer → Preprocess tab


 Click Open file and select your dataset (.arff or .csv)
 Review attribute summary (type, missing values, etc.)

Go to Select Attributes Tab

 This tab allows you to choose:


o Attribute Evaluator: Measures relevance of features
o Search Method: Finds optimal subset of features

Choose Attribute Evaluator

Some popular evaluators: | Evaluator | Description | |-----------|-------------|

28
| CfsSubsetEval | Selects features highly correlated with the class and low inter correlation |

| InfoGainAttributeEval | Measures information gain of each attribute |

| GainRatioAttributeEval | Normalized version of InfoGain |

| ReliefFAttributeEval | Evaluates based on instance-based learning |

| PrincipalComponents | Reduces dimensionality using PCA |

Choose Search Method

Search Method Description

GreedyStepwise Forward/backward greedy search

BestFirst Hill climbing with backtracking

Ranker Ranks attributes individually

GeneticSearch Uses genetic algorithms for subset selection

Run the Selection

 Click Start
 WEKA will output:
o Selected attributes
o Evaluation metrics
o Option to visualize results

Save Reduced Dataset

 Use Preprocess tab to remove unselected attributes


 Save the reduced dataset for further modeling

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:

=== Run information ===

Scheme: [Link].J48 -C 0.25 -M 2


Relation: [Link]
Instances: 14
Attributes: 5
outlook
temperature
humidity
windy
play
Test mode: 10-fold cross-validation

=== Classifier model (full training set) ===

J48 pruned tree


------------------

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

Size of the tree : 8

Time taken to build model: 0 seconds

=== Stratified cross-validation ===


=== Summary ===

Correctly Classified Instances 7 50 %


Incorrectly Classified Instances 7 50 %
Kappa statistic -0.0426
Mean absolute error 0.4167
Root mean squared error 0.5984
Relative absolute error 87.5 %
Root relative squared error 121.2987 %
Total Number of Instances 14

=== Detailed Accuracy By Class ===

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

=== Confusion Matrix ===

a b <-- classified as
5 4 | a = yes
3 2 | b = no

31
Attribute selection output:
=== Run information ===

Evaluator: [Link] -execution-slots 1 -B


[Link] -F 5 -T 0.01 -R 1 -E DEFAULT --
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

=== Attribute Selection on all input data ===

Search Method:
Attribute ranking.

Attribute Evaluator (supervised, Class (nominal): 5 play):


Classifier feature evaluator

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

Selected attributes: 4,3,2,1 : 4

32
33
EXPERIMENT-6

Experiment to Evaluate Information Gain of an attribute in the weather


database

To measure how much each attribute (e.g., Outlook, windy, humidity, temperature)

Contributes to predicting outcomes using InfoGainAttributeEval.

Prepare the Weather Dataset

 Format: .arff or .csv


 Include attributes like:
o Outlook, windy, humidity, temperature, , play
 Ensure the class attribute (e.g., play is clearly defined

Load Dataset in WEKA

 Open WEKA → Explorer → Preprocess tab


 Click Open file and select your student dataset

Go to Select Attributes Tab

 Choose:
o Evaluator: InfoGainAttributeEval
o Search Method: Ranker

Run the Evaluation

 Click Start,WEKA will rank attributes based on their information gain with respect to
the class

Interpret Results

 Output shows IG scores for each attribute


 Higher IG = more predictive power

34
 Example:
 Attribute Info Gain
 Outlook 0.2467
 Windy 0.481
 humidity 0.0
 temperature 0.0

Use Selected Features

 You can remove low-IG attributes to simplify your model


 Save the reduced dataset for classification or clustering

Attribute selection output:

== Run information ===

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

=== Attribute Selection on all input 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

Selected attributes: 1,3,4,2 : 4

36
37
EXPERIMENT-7

Demonstration of classification rule process using J48 decision tree algorithm

Step 1: Load Your Dataset

 Open Weka and select the "Explorer" option.


 Click on "Open file" and choose your dataset (e.g., [Link]).

Step 2: Preprocess Your Data

 Handle missing values: Filter -> Choose -> Unsupervised -> Attribute ->
ReplaceMissingValues.
 Normalize data (optional): Filter -> Unsupervised -> Attribute -> Normalize.
 Remove irrelevant attributes: Filter -> Unsupervised -> Attribute -> Remove.

Step 3: Select the J48 Classifier

 Go to the "Classify" tab.


 Click on the "Choose" button and select trees -> J48.

Step 4: Configure Model Settings

(Optional)

 Click on the J48 classifier and adjust parameters, such as:


 Confidence Threshold: Set the confidence threshold for pruning (default: 0.25).
 Minimum Number of Instances per Leaf: Set the minimum number of instances per leaf
(default: 2).

Step 5: Train and Evaluate the Model

 Click "Start" to run the classification.


 Weka will display accuracy, precision, recall, and confusion matrix.

38
Step 6: Visualize the Decision Tree

 Right-click on the result in the "Result list" section.


 Select "Visualize tree" to see the decision tree.

Additional Tips

 Use 10-fold cross-validation for better performance evaluation.


 Experiment with different [the rest of the text is cut off]

Output:

If outlook=sunny and humidity=high

Play=no

If outlook=overcast then play=yes

If outlook=rainy and windy=false

Play=yes

If outlook=rainy and windy=true

Play=no

39
EXPERIMENT-8

Demonstrate of classification rules process using ID3 decision tree algorithm

What is ID3?

 ID3 (Iterative dichotomiser 3) is a classic decision tree algorithm developed by Ross


Quinlan.
 It builds a tree by selecting attributes with the highest information gain to split the data.
 ID3 works only with nominal attributes and does not support missing values.

Step-by-step classification using ID3 in WEKA

1. Prepare your data set:

 Format: Use .arff file with nominal attributes only.


 Example: [Link] is a popular dataset for ID3.
 Ensure the class attribute (e.g., Play) is defined as the last column.

2. Load data set in WEKA:

 Open WEKA -> click Explorer.


 Go to the preprocess tab.
 Click open file and select your .arff dataset.

3. Set the class Attribute:

 Confirm the class (last attribute) is selected as the class/target variable.

4. Go to classify tab:

 Click choose -> trees -> Id3.


 This selects the ID3 algorithm for classification.

5. Select Evaluation method:

40
 Recommended: 10-fold cross-validation.
 Alternatively: Use percentage split or training set.

6. Run the classifier:

 Click start.
 WEKA will output:
 Decision tree structure
 Classification accuracy
 Confusion matrix
 Detailed statistics (precision, recall, F-measure)

7. Visualize the tree:

 Right-click the result in the result list.


 Choose visualize tree.
 You will see a graphical representation of the decision rules.

Classifier Output:

=== Run information ===

Scheme: [Link].J48 -C 0.25 -M 2


Relation: [Link]
Instances: 14
Attributes: 5
outlook
temperature
humidity
windy
play
Test mode: 10-fold cross-validation

41
=== Classifier model (full training set) ===

J48 pruned tree


------------------

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

Size of the tree : 8

Time taken to build model: 0 seconds

=== Stratified cross-validation ===


=== Summary ===

Correctly Classified Instances 7 50 %


Incorrectly Classified Instances 7 50 %
Kappa statistic -0.0426
Mean absolute error 0.4167
Root mean squared error 0.5984
Relative absolute error 87.5 %
Root relative squared error 121.2987 %
Total Number of Instances 14

=== Detailed Accuracy By Class ===

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

=== Confusion Matrix ===

a b <-- classified as
5 4 | a = yes
3 2 | b = no
Attribute selection output:
=== Run information ===

Evaluator: [Link] -execution-slots 1 -B


[Link] -F 5 -T 0.01 -R 1 -E DEFAULT --
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

=== Attribute Selection on all input data ===

Search Method:
Attribute ranking.

Attribute Evaluator (supervised, Class (nominal): 5 play):


Classifier feature evaluator

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

Selected attributes: 4,3,2,1 : 4

44
45
EXPERIMENT-9

Experiment to predict the class using the Bayesian classification

Step 1: Launch Weka

 Open the Weka GUI Chooser.


 Select Explorer to begin working with datasets.

Step 2: Load Your Dataset

 Click Open file and choose a dataset in .arff format (e.g., [Link]).
 You’ll see the dataset summary with attributes and instances.

Step 3: Preprocess the Data

 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.

Step 4: Choose the Classifier

 Go to the Classify tab.


 Click the Choose button.
 Select: bayes > NaiveBayes

Step 5: Set Evaluation Method

 Under Test options, choose one:


o Use training set: trains and tests on the same data (not recommended).
o Percentage split: e.g., 66% training, 34% testing.
o Cross-validation: e.g., 10-fold (recommended for small datasets).

Step 6: Run the Experiment

 Click Start to train and evaluate the model.


 Weka will display results in the right panel:

46
o Confusion matrix
o Accuracy
o Precision, Recall, F-measure
o Class-wise predictions

Step 7: Interpret the Results

 Look at the Summary:


o High accuracy and F-measure indicate good performance.
 Analyze the Confusion Matrix to see how well each class was predicted.

Optional: Save the Model

 Click on the Save model button to export the trained classifier for future use.

Example Dataset: [Link]

This classic dataset includes attributes like:

 Outlook (sunny, rainy, overcast)


 Temperature (hot, mild, cool)
 Humidity (high, normal)
 Windy (true, false)
 Play (yes, no) ← class to predict

Classify:

=== Run information ===


Scheme: [Link]
Relation: [Link]
Instances: 14
Attributes: 5
outlook
temperature

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

Experiment to predict the class using the k-Nearest Neighbor classification

Step 1: Launch Weka

 Open the Weka GUI Chooser.


 Click on Explorer to begin working with your dataset.

Step 2: Load Your Dataset

 Click Open file and select a dataset in .arff format (e.g., [Link], [Link]).
 Weka will display the dataset summary with attributes and instances.

Step 3: Preprocess the Data

 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).

Step 4: Choose the k-NN Classifier

 Go to the Classify tab.


 Click Choose → lazy > IBk (this is Weka’s implementation of k-NN).

Step 5: Configure k Value

 Click on the name IBk to open its configuration.


 Set the value of k (e.g., k=3 for 3 nearest neighbors).
 You can also choose the distance weighting method and search algorithm (e.g., linear
or KD-tree).

Step 6: Set Evaluation Method

 Under Test options, choose one:


o Cross-validation (e.g., 10-fold) – recommended for reliable evaluation.

50
o Percentage split (e.g., 70% training, 30% testing).
o Use training set – not ideal for generalization.

Step 7: Run the Experiment

 Click Start to train and evaluate the model.


 Weka will display:
o Accuracy
o Confusion matrix
o Precision, Recall, F-measure
o Class-wise prediction details

Step 8: Analyze the Results

 Review the Summary output:


o High accuracy and F-measure indicate good performance.
 Use the Confusion Matrix to understand misclassifications.

Optional: Save the Model

 Click Save model to export the trained classifier for future use.

Example Dataset: [Link]

This dataset includes:

 Features: Sepal length, Sepal width, Petal length, Petal width


 Class: Iris-setosa, Iris-versicolor, Iris-virginica

Try setting k=3 and using 10-fold cross-validation to see how well k-NN performs on this classic
dataset.

51
Classify:

=== Run information ===


Scheme: [Link] -K 3 -W 0 -A
"[Link] -A \"[Link] -R first-last\""
Relation: iris
Instances: 150
Attributes: 5
sepallength
sepalwidth
petallength
petalwidth
class
Test mode: 10-fold cross-validation
=== Classifier model (full training set) ===
IB1 instance-based classifier
using 3 nearest neighbour(s) for classification
Time taken to build model: 0 seconds
=== Stratified cross-validation ===
=== Summary ===
Correctly Classified Instances 143 95.3333 %
Incorrectly Classified Instances 7 4.6667 %
Kappa statistic 0.93
Mean absolute error 0.04
Root mean squared error 0.1703
Relative absolute error 9.0013 %
Root relative squared error 36.1192 %
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.940 0.040 0.922 0.940 0.931 0.896 0.963 0.910 Iris-versicolor

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

To implement weight and bias updating using a Backpropagation Neural


Network .

1. Load Your Dataset

 Open Weka Explorer.


 Click "Open file" and load a dataset (e.g., [Link] or your custom dataset).

2. Select the Classifier

 Go to the "Classify" tab.


 Choose functions > MultilayerPerceptron.

3. Configure the Neural Network

Click on the MultilayerPerceptron to open its configuration panel. Key parameters:

 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.

4. Run the Classifier

 Click "Start" to train the model.


 Weka will display performance metrics like accuracy, confusion matrix, etc.

5. View the Network Structure

 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.

Optional: Use KnowledgeFlow for Visualization

If you want to visualize the training process:

 Switch to KnowledgeFlow.
 Use components like ArffLoader, Classifier, and ModelPerformanceChart to observe
training and ROC curves.

Classifier output:

=== Run information ===


Scheme: [Link] -L 0.3 -M 0.2 -N 500 -V 0 -S 0 -E
20 -H a
Relation: iris
Instances: 150
Attributes: 5
sepallength
sepalwidth
petallength
petalwidth
class
Test mode: 10-fold cross-validation
=== Classifier model (full training set) ===
Sigmoid Node 0
Inputs Weights
Threshold -3.5015971588434014
Node 3 -1.0058110853859945
Node 4 9.07503844669134
Node 5 -4.107780453339234
Sigmoid Node 1
Inputs Weights

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

Demonstration of clustering process using k-means algorithm

K-Means clustering in Weka using its Explorer interface. This is one of the most intuitive ways
to understand unsupervised learning,

1. Load Your Dataset

 Open Weka Explorer.


 Go to the Preprocess tab.
 Click Open file… and select a dataset in .arff format (e.g., [Link] is a popular choice).
 You’ll see the attributes and instance count displayed.

Tip: Make sure your dataset contains numeric attributes, as K-Means relies on distance
calculations.

2. Select the Clustering Algorithm

 Switch to the Cluster tab.


 Click the Choose button.
 Select SimpleKMeans from the list of clustering algorithms.

3. Configure K-Means Parameters

 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)

4. Run the Clustering Algorithm

 In the Cluster Mode panel, select Use training set.

59
 Click Start to begin clustering.
 Weka will output cluster centroids, instance assignments, and statistics.

5. Visualize Cluster Assignments

 Right-click on the result in the Result list.


 Choose Visualize cluster assignments.
 You can change axes to explore how clusters are distributed across features.

6. Analyze the Output

 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.

7. Experiment with Different K Values

 Try different values of K to see how clustering changes.


 Observe how the centroids shift and how instance assignments vary.

Cluster:

=== Run information ===


Scheme: [Link] -init 0 -max-candidates 100 -periodic-pruning
10000 -min-density 2.0 -t1 -1.25 -t2 -1.0 -N 2 -A "[Link] -R first-last" -I
500 -num-slots 1 -S 10
Relation: iris
Instances: 150
Attributes: 5
sepallength
sepalwidth
petallength
petalwidth

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

Mining frequent patterns using the Apriori algorithm.

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.

1. Prepare Your Dataset

 Use a transactional dataset (e.g., supermarket purchases).


 Ensure attributes are nominal or binary—Apriori doesn’t work with numeric data
directly.
 Format the dataset as .arff and load it into Weka via the Explorer.

2. Open the Associate Tab

 In Weka Explorer, go to the "Associate" tab.


 Choose the Apriori algorithm from the list.

3. Configure Parameters

 You can tweak:


o minSupport: Minimum frequency threshold (e.g., 0.1 means 10%).
o minConfidence: Strength of the rule (e.g., 0.8 means 80% confidence).
o numRules: Number of rules to generate.
 Click Start to run the algorithm.

4. Interpret the Output

 Weka will display rules like:


 {Bread, Butter} => {Jam} (support=0.15, confidence=0.85)
 These rules show frequent itemsets and their associations.

63
Output:

=== Run information ===


Scheme: [Link] -N 10 -T 0 -C 0.9 -D 0.05 -U 1.0 -M 0.1 -S -1.0 -c -1
Relation: supermarket
Instances: 4627
Attributes: 217
[list of attributes omitted]
=== Associator model (full training set) ===
Apriori
=======
Minimum support: 0.15 (694 instances)
Minimum metric <confidence>: 0.9
Number of cycles performed: 17
Generated sets of large itemsets:
Size of set of large itemsets L(1): 44
Size of set of large itemsets L(2): 380
Size of set of large itemsets L(3): 910
Size of set of large itemsets L(4): 633
Size of set of large itemsets L(5): 105
Size of set of large itemsets L(6): 1
Best rules found:
1. biscuits=t frozen foods=t fruit=t total=high 788 ==> bread and cake=t 723 <conf:(0.92)>
lift:(1.27) lev:(0.03) [155] conv:(3.35)
2. baking needs=t biscuits=t fruit=t total=high 760 ==> bread and cake=t 696 <conf:(0.92)>
lift:(1.27) lev:(0.03) [149] conv:(3.28)
3. baking needs=t frozen foods=t fruit=t total=high 770 ==> bread and cake=t 705
<conf:(0.92)> lift:(1.27) lev:(0.03) [150] conv:(3.27)
4. biscuits=t fruit=t vegetables=t total=high 815 ==> bread and cake=t 746 <conf:(0.92)>
lift:(1.27) lev:(0.03) [159] conv:(3.26)
5. party snack foods=t fruit=t total=high 854 ==> bread and cake=t 779 <conf:(0.91)>
lift:(1.27) lev:(0.04) [164] conv:(3.15)

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

Mining frequent patterns using the FP-Growth algorithm.

In Weka is a powerful way to uncover hidden associations in transactional datasets—without


the overhead of candidate generation like Apriori.

1. Prepare Your Dataset

 Use a transactional dataset in .arff format.


 Ensure attributes are nominal or binary—FP-Growth doesn’t work with numeric
attributes directly.
 Example: Market basket data with items like {Milk, Bread, Butter}.

2. Open Weka Explorer

 Launch Weka and go to the "Associate" tab.


 Select the FPGrowth algorithm from the list of associators.

3. Configure FP-Growth Parameters

Click on the algorithm name to open its settings:

 minSupport: Minimum frequency threshold (e.g., 0.2 means 20%).


 numRulesToFind: Number of rules to generate.
 metricType: Choose between confidence, lift, leverage, etc.
 delta: Controls support decrement during rule generation.

These parameters shape the frequent itemsets and association rules that FP-Growth will discover.

4. Run the Algorithm

 Click "Start" to execute.


 Weka will output rules like:
 {Bread, Butter} => {Jam} (support=0.25, confidence=0.85)
 These rules reveal frequent co-occurrences and predictive relationships.

66
Output:

=== Run information ===

Scheme: [Link] -P 2 -I -1 -N 10 -T 0 -C 0.9 -D 0.05 -U 1.0 -M 0.1

Relation: supermarket

Instances: 4627

Attributes: 217

[list of attributes omitted]

=== Associator model (full training set) ===

FPGrowth found 16 rules (displaying top 10)

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.

1. Load Your Dataset

 Open Weka Explorer.


 Go to the Preprocess tab.
 Load your dataset (preferably in .arff format).

2. Choose Algorithms to Compare

You can compare multiple algorithms like:

 J48 (Decision Tree)


 Naive Bayes
 Random Forest
 Support Vector Machine (SMO)
 k-Nearest Neighbors (IBk)

3. Use the Experimenter Panel

 Switch to the Experimenter tab in Weka.


 Create a new experiment.
 Add your dataset.
 Add multiple algorithms for comparison.
 Choose cross-validation (e.g., 10-fold) for reliable performance metrics.
 Select evaluation metrics like accuracy, precision, recall, and F-measure.

4. Run the Experiment

 Click Run to start the comparison.


 Weka will train and test each algorithm and generate performance statistics.

5. Analyze the Results

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.

6. Explore Regression or Clustering (Optional)

If your task involves regression or clustering:

 Use algorithms like Linear Regression, K-Means, or EM.


 Evaluate using metrics like Mean Absolute Error or Cluster Purity.

Classifier Output:

== Run information ===

Scheme: [Link].J48 -C 0.25 -M 2


Relation: pima_diabetes
Instances: 768
Attributes: 9
preg
plas
pres
skin
insu
mass
pedi
age
class
Test mode: 10-fold cross-validation

70
=== Classifier model (full training set) ===

J48 pruned tree


------------------

plas <= 127


| mass <= 26.4: tested_negative (132.0/3.0)
| mass > 26.4
| | age <= 28: tested_negative (180.0/22.0)
| | age > 28
| | | plas <= 99: tested_negative (55.0/10.0)
| | | plas > 99
| | | | pedi <= 0.56: tested_negative (84.0/34.0)
| | | | pedi > 0.56
| | | | | preg <= 6
| | | | | | age <= 30: tested_positive (4.0)
| | | | | | age > 30
| | | | | | | age <= 34: tested_negative (7.0/1.0)
| | | | | | | age > 34
| | | | | | | | mass <= 33.1: tested_positive (6.0)
| | | | | | | | mass > 33.1: tested_negative (4.0/1.0)
| | | | | preg > 6: tested_positive (13.0)
plas > 127
| mass <= 29.9
| | plas <= 145: tested_negative (41.0/6.0)
| | plas > 145
| | | age <= 25: tested_negative (4.0)
| | | age > 25
| | | | age <= 61
| | | | | mass <= 27.1: tested_positive (12.0/1.0)
| | | | | mass > 27.1
| | | | | | pres <= 82
| | | | | | | pedi <= 0.396: tested_positive (8.0/1.0)

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

Size of the tree : 39

Time taken to build model: 0 seconds

=== Stratified cross-validation ===


=== Summary ===

Correctly Classified Instances 567 73.8281 %


Incorrectly Classified Instances 201 26.1719 %
Kappa statistic 0.4164
Mean absolute error 0.3158
Root mean squared error 0.4463
Relative absolute error 69.4841 %
Root relative squared error 93.6293 %
Total Number of Instances 768

=== Detailed Accuracy By Class ===

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

=== Confusion Matrix ===

a b <-- classified as
407 93 | a = tested_negative
108 160 | b = tested_positive

73
74

You might also like