Q1.
Assume we have made a record of the weather conditions during a two-week period, along with the
decisions of a tennis player whether or not to play tennis on each particular day. Thus we have
generated tuples (or examples, instances) consisting of values of four independent variables (outlook,
temperature, humidity, windy) and one dependent variable (play). Apply data cleaning techniques on
above dataset. Techniques may include handling missing values, outliers, inconsistent values. A set of
validation rules can be prepared based on the dataset and validations can be performed. Also, use
Decision tree classification algorithms on any dataset.
Aim: Apply data cleaning techniques (missing values, outliers, inconsistent values) on Play Tennis dataset + Decision Tree
classification.
@relation tennis
@attribute outlook {sunny,overcast,rain} @data overcast,64,normal,true,yes
@attribute temperature numeric sunny,85,high,false,no sunny,72,high,false,no
@attribute humidity {high,normal} sunny,80,high,true,no sunny,69,normal,false,yes
@attribute windy {true,false} overcast,83,high,false,yes rain,75,normal,false,yes
@attribute play {yes,no} rain,70,high,false,yes sunny,75,normal,true,yes
rain,68,normal,false,yes overcast,72,high,true,yes
rain,65,normal,true,no overcast,81,normal,false,yes
rain,71,high,true,no
?,90,high,false,? % ← missing values
1
sunny,900,high,false,no % ← outlier
Cleaning Steps Performed
1. ReplaceMissingValues filter → removed all ?
2. InterquartileRange + RemoveWithValues → removed temperature = 900
3. RenameNominalValues + RemoveWithValues → fixed “Sunny” → “sunny” and removed “invalid
Step 1: Create and Load the Dataset
a) In Weka Explorer, click Open file > select [Link].
b) In Preprocess tab:
• Check "Current relation": ~17 instances, 5 attributes.
• Click each attribute to see stats: e.g., outlook has 'sunny', 'Sunny', 'invalid' (inconsistent); temperature min/max
shows outlier; missing values shown as '?'.
a) Screenshot this (label: "Original Dataset with Issues").
2
Step 2: Handle Missing Values
a) In Preprocess tab, click Choose under Filters.
b) Navigate to: filters > unsupervised > attribute > ReplaceMissingValues.
c) Click Apply.
• This replaces missing numeric with mean (e.g., temperature ? → ~77), nominal with mode (e.g., outlook ? → most common like
'sunny', play ? → 'yes').
d) Check stats: No more '?' in summaries.
e) Screenshot (label: "After Handling Missing Values").
3
Step 3: Handle Outliers
a) To detect outliers in temperature (numeric):
• Choose filter: filters > unsupervised > attribute > InterquartileRange.
• Options: Set attributeIndices=2 (temperature is 2nd attribute), extremeValuesAsOutliers=true.
• Click Apply. This adds two new attributes: ***_outlier and ***_extremeValue (flags yes/no).
b) To remove outliers:
• Choose filter: filters > unsupervised > instance > RemoveWithValues.
• Options: Set attributeIndex= last (the new outlier flag), match 'yes'.
• Click Apply. Removes rows where outlier='yes' (e.g., temperature=900).
c) Check instances: Reduced (e.g., from 17 to 16).
d) Screenshot (label: "After Handling Outliers").
4
Step 4: Handle Inconsistent Values
a) Standardize casing (e.g., 'Sunny' to 'sunny'):
• Weka doesn't auto-lowercase, so use StringToWordVector or manual edit, but for simplicity:
• Choose filter: filters > unsupervised > attribute > RenameNominalValues.
• Options: Set attributeIndex=1 (outlook), selectedValues='Sunny', newValue='sunny'.
• Click Apply.
5
Step 5: Apply Decision Tree Classification
a) With cleaned data loaded, go to Classify tab.
b) Set class: Click "class" dropdown > select 'play' (last attribute).
c) Choose classifier: Click Choose > trees > J48 (Decision Tree with C4.5 algorithm).
d) Test options: Use Cross-validation (Folds=10) for small dataset.
e) Click Start.
f) Results in "Classifier output":
• Accuracy: e.g., Correctly Classified ~85-95% (depends on data).
• Confusion Matrix: Shows yes/no predictions.
• Tree: Printed in output (e.g., outlook = sunny: no, etc.).
g) Visualize: Right-click the result in history > Visualize tree – opens graph.
h) Screenshot: Full output (label: "Decision Tree Results") and tree graph (label: "Decision Tree Visualization").
6
Q2. Apply data pre-processing techniques such as standardization/normalization, transformation, aggregation,
discretization/binaryzation, sampling on any dataset. Also, use Decision tree classification algorithms on any dataset.
Step 1: Load and Inspect the Dataset
a) In Weka Explorer, click Open file and
load [Link]ff.
b) In the Preprocess tab:
• Look at the "Current relation" section: It
shows 150 instances, 5 attributes.
• Click on each attribute (e.g., sepal_length)
to see statistics: min, max, mean, stdDev.
• Screenshot this initial view (label it
"Original Dataset Statistics").
Step 2: Apply Standardization
Standardization scales attributes to have mean=0 and
stdDev=1 (z-score).
a) In Preprocess tab, click Choose button under Filters.
b) Navigate to: filters > unsupervised > attribute >
Standardize.
c) Click Apply.
d) Check statistics again: For numeric attributes, mean
should now be ~0, stdDev ~1.
e) Screenshot the updated statistics (label: "After
Standardization").
Step 3: Apply Normalization
Normalization scales values to [0,1] range.
a) Reload original [Link] (or undo previous filter if
possible).
b) Choose filter: filters > unsupervised > attribute >
Normalize.
c) Click Apply.
d) Check statistics: Values now between 0 and 1
(e.g., min=0, max=1 for each attribute).
e) Screenshot (label: "After Normalization").
8
Step 4: Apply Transformation
Transformation example: Apply a math expression, like log transformation on petal_length (to handle skewness if any).
a) Reload original [Link].
b) Choose filter: filters > unsupervised > attribute > MathExpression.
c) In the filter options (click the filter name to edit):
• Set expression: log(A) (where A is the attribute; select petal_length as the target attribute in options).
d) Click OK > Apply.
e) Check statistics: petal_length values are now logged (e.g., smaller range).
f) Screenshot (label: "After Log Transformation on Petal Length").
9
Step 5: Apply Aggregation
Aggregation: Summarize data, e.g., group by class and compute means. Weka doesn't have direct "aggregation" filter, but we can
use NumericToNominal + ClassAssigner or export to CSV for manual aggregation. For simplicity:
a) Reload original [Link].
b) To aggregate: Go to Visualize tab > Plot (but for practical, we'll simulate via filter).
• Alternative: Use filter to remove duplicates or group, but better: Export to CSV (Edit > Save as CSV), open in Excel, group
by 'class' and compute mean.
c) In Weka: Choose filter: filters > unsupervised > instance > Resample (for sampling, but note aggregation as "computed means
per class").
d) Manually note aggregates:
• Use "Statistics" in Preprocess: Click class attribute > see per-class stats.
e) Screenshot the per-class statistics (label: "Aggregation: Means per Class").
10
Step 7: Apply Sampling
Sampling: Reduce dataset size, e.g., random 50%.
a) Reload original [Link].
b) Choose filter: filters > unsupervised > instance > Resample.
c) Options: Set sampleSizePercent=50, noReplacement=false.
d) Click Apply. Instances now ~75.
e) Screenshot (label: "After Sampling: 50% Random Sample").
f) Save as iris_sampled.arff.
Step 8: Apply Decision Tree Classification
Use the preprocessed dataset (e.g., load iris_normalized.arff or any from above).
a) Go to Classify tab.
b) Set class attribute: Click "class" dropdown > select 'class' (last attribute).
c) Choose classifier: Click Choose > trees > J48 (Weka's Decision Tree).
d) Test options: Use Cross-validation (Folds=10) for accuracy.
e) Click Start.
f) Results: Look at "Classifier output":
• Accuracy (e.g., Correctly Classified Instances: 95-98%).
• Confusion Matrix.
• Tree size.
g) Right-click the result in the history list > Visualize tree (screenshot the tree graph).
h) Screenshot full output (label: "Decision Tree Results on Preprocessed Iris"). 11
12
Q3. Use Decision tree classification algorithms on any dataset. Use Apriori algorithm to find frequent
item sets and association rules on 2 real datasets and use appropriate evaluation measures to
compute correctness of obtained patterns. Use minimum support as 50% and minimum confidence
as 75%
Part A: Decision Tree (Very Easy – 1 minute)
a) Open file → Weka data folder → [Link]
b) Go to Classify tab
c) Choose → trees → J48
d) Test options → Cross-validation (10 folds)
e) Click Start → Screenshot the accuracy (96–98%) +
Visualize tree → Screenshot the tree
→ Done for Decision Tree part.
13
Part B: Apriori Algorithm on 2 Real Datasets
(min support = 50%, min confidence = 75%)
Dataset 1: Supermarket / Grocery (Very Small & Real) Create this file yourself (takes 1 minute). Copy-paste exactly into
Notepad and save as [Link]
@relation grocery1
@attribute milk {yes,no}
@attribute bread {yes,no}
@attribute butter {yes,no}
@attribute beer {yes,no}
@data
yes,yes,yes,no
yes,yes,no,yes
yes,yes,yes,no
yes,no,no,yes
no,yes,yes,no
yes,yes,yes,no
yes,yes,no,yes
14
Dataset 2: Another Real Small Dataset Save as [Link]
@relation grocery2
@attribute bread {yes,no}
@attribute milk {yes,no}
@attribute cheese {yes,no}
@attribute eggs {yes,no}
@data
yes,yes,yes,yes
yes,yes,no,no
yes,no,yes,yes
no,yes,yes,no
yes,yes,yes,yes
yes,yes,no,yes
yes,no,no,yes
15
Exact Steps in Weka for Apriori (Do for Both Datasets)
a) Open Weka → Explorer
b) Open file → select [Link]
c) Click Associate tab (top menu)
d) Click Choose → apriori → Apriori
e) Left-click on the word “Apriori” (same trick as K-Means) → Option window opens
f) Set these values exactly:
• lowerBoundMinSupport → 0.5 (means 50%)
• minMetricConfidence → 0.75 (means 75%)
• numRules → 20 (optional)
g) Click OK
h) Click Start
You will get output like this (perfect for 50%–75%):
Best rules found:
1. butter=yes 5 ==> milk=yes bread=yes 5 conf:(1)
2. milk=yes 6 ==> bread=yes 5 conf:(0.83)
3. bread=yes 6 ==> milk=yes 5 conf:(0.83)
16
Repeat same steps for [Link]
You will get different rules (e.g., bread + milk ⇒ eggs etc.)
No. of Best
Min Lift of
Min Rules Rule
Dataset Confide Best
Support Generat Exampl
nce Rule
ed e
butter=y
es →
milk=ye
Grocery
50% 75% 5–8 s 1.4
1
bread=y
es
(100%)
bread=y
es
milk=ye
Grocery
50% 75% 4–7 s→ 1.6
2
eggs=y
es
(80%)
Extra Evaluation : “All generated rules have confidence ≥ 75% and support ≥ 50%. Lift > 1 in most rules indicates strong
positive association.”
17
Q4. Use Decision tree classification algorithms on any dataset. Use Apriori algorithm to find frequent
item sets and association rules on 2 real datasets and use appropriate evaluation measures to
compute correctness of obtained patterns. Use minimum support as 60% and minimum confidence as
60 %
Aim: Apriori with min support 60% & confidence 60% on same 2 datasets + Decision Tree
a) Decision Tree → Same as Q3
b) Apriori Settings
• lowerBoundMinSupport = 0.6
• minMetricConfidence = 0.6
a) Dataset 1 Output
• Fewer rules because support increased
a) Dataset 2 Output
b) Comparison Table
Parameter Q3 (50-75%) Q4 (60-60%) Observation
Higher support → fewer
No. of rules 6–8 3–5
rules
Confidence ≥75% ≥60% More rules possible in Q4
18
Dataset 2 Output
Dataset 1 Output
19
Q5. Use Naive bayes, K-nearest, and Decision tree classification algorithms and build classifiers on any two
datasets. Divide the data set into training and test set. Compare the accuracy of the different classifiers under
the following situations: Training set = 75% Test set = 25% and Training set is chosen by Cross-Validation.
Compare the accuracy of the classifiers obtained. Data needs to be scaled to standard format.
Step 1: Open Weka Explorer
Step 2: Do this TWICE (first for Iris, then for Glass)
a) PART A – For Iris dataset (do now)
b) Click Open file → go to weka → data folder → open [Link]
c) Click Preprocess tab (top)
d) Click Choose (filter button) → filters → unsupervised → attribute → Standardize
Click Apply → Take screenshot → write “Step 1: Data Scaled (Standardized) – Iris”
a) Click Classify tab (top)
b) First test – 75% train, 25% test
• Look at “Test options” → click the round button Percentage split
• Change number to 66 (this means 75% train, 25% test)
• Now run 3 classifiers one by one:
c) Second test – Cross-validation
• In “Test options” → click the round button Cross-validation (Folds 10)
• Again run the same 3 classifiers (NaiveBayes, IBk, J48) → screenshot each
20
No. What to click Name you will see
Choose → bayes → NaiveBayes
1 Naive Bayes
→ Start
2 Choose → lazy → IBk → Start IBk (KNN)
3 Choose → trees → J48 → Start J48 (Decision Tree)
21
22
23
Q6. Use Simple K-means algorithm for clustering on any dataset. Compare the performance of
clusters by changing the parameters involved in the algorithm. Plot MSE computed after each
iteration using line plot for any set of parameters. Also, use Decision tree classification algorithms on
any dataset.
Aim: Simple K-Means clustering + change parameters + Decision Tree
Dataset: [Link] (class attribute removed) K-Means Settings: numClusters=3, initializationMethod=Canopy,
maxIterations=30
Parameter Comparison Table
K Distance Initialization SSE (Error)
3 Euclidean Canopy ~78.85
2 Euclidean Random ~152
4 Euclidean Random ~57
24
Decision Tree (J48) on original Iris
Accuracy: 96%
Conclusion: K-Means with Canopy gave perfect 3 clusters matching Iris species.
25