0% found this document useful (0 votes)
17 views53 pages

ML Lab Manual

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)
17 views53 pages

ML Lab Manual

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
You are on page 1/ 53

INDEX SHEET

S.NO DATE EXPERIMENT NAME PAGE NO SIGNATURE

1 Data Preprocessing with Python

Building Decision Trees for Soybean


2
classification model using Weka

Generating association rules on


3
Weather data using Weka

Exploring machine learning models


including classification and
4
clustering using
Weka

Build Neural Network Classifier


5
using Weka

Supervisely - Perform Data Labeling


6 for various images using object
recognition

7 Image Classifier using OpenCV

Automatic Facial recognition using


8 OpenCV
Experiment-1

Data Pre-processing with Python

#import the libraries


import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
data=pd.read_csv('Placement_Data.csv')
x = data.iloc[:, :-2].values
y = data.iloc[:, -1].values

print(data)

ssc_p hsc_p hsc_s degree_p workex etest_p mba_p status


0 67.00 91.00 Commerce 58.00 No 55.0 58.80 Placed
1 79.33 78.33 Science 77.48 Yes 86.5 66.28 Placed
2 65.00 68.00 Arts 64.00 No 75.0 57.80 Placed
3 56.00 52.00 Science 52.00 No 66.0 59.43 Not Placed
4 85.80 73.60 Commerce 73.30 No 96.8 55.50 Placed
.. ... ... ... ... ... ... ... ...
210 80.60 82.00 Commerce 77.60 No 91.0 74.49 Placed
211 58.00 60.00 Science 72.00 No 74.0 53.62 Placed
212 67.00 67.00 Commerce 73.00 Yes 59.0 69.72 Placed
213 74.00 66.00 Commerce 58.00 No 70.0 60.23 Placed
214 62.00 58.00 Science 53.00 No 89.0 60.22 Not Placed

salary
0 270000.0
1 200000.0
2 250000.0
3 NaN
4 425000.0
.. ...
210 400000.0
211 275000.0
212 295000.0
213 204000.0
214 NaN

print(x)

[[67.0 91.0 'Commerce' ... 'No' 55.0 58.8]


[79.33 78.33 'Science' ... 'Yes' 86.5 66.28]
[65.0 68.0 'Arts' ... 'No' 75.0 57.8]
...
[67.0 67.0 'Commerce' ... 'Yes' 59.0 69.72]
[74.0 66.0 'Commerce' ... 'No' 70.0 60.23]
[62.0 58.0 'Science' ... 'No' 89.0 60.22]]
print(y)

[270000. 200000. 250000. nan 425000. nan nan 252000. 231000.


nan 260000. 250000. nan 218000. nan 200000. 300000. nan
nan 236000. 265000. 393000. 360000. 300000. 360000. nan 240000.
265000. 350000. nan 250000. nan 278000. 260000. nan 300000.
nan 320000. 240000. 411000. 287000. nan nan 300000. 200000.
nan nan 204000. 250000. nan 200000. nan nan 450000.
216000. 220000. 240000. 360000. 268000. 265000. 260000. 300000. 240000.
nan 240000. nan 275000. 275000. nan 275000. 360000. 240000.
240000. 218000. 336000. nan 230000. 500000. 270000. nan 240000.
300000. nan 300000. 300000. 400000. 220000. nan 210000. 210000.
300000. nan 230000. nan 260000. 420000. 300000. nan 220000.
nan nan 380000. 300000. 240000. 360000. nan nan 200000.
300000. nan 250000. nan 250000. 280000. 250000. 216000. 300000.
240000. 276000. 940000. nan 250000. 236000. 240000. 250000. 350000.
210000. 250000. 400000. 250000. nan 360000. 300000. 250000. 250000.
200000. nan 225000. 250000. 220000. 265000. nan 260000. 300000.
nan 400000. 233000. 300000. 240000. nan 690000. 270000. 240000.
340000. 250000. nan 255000. 300000. nan nan 300000. nan
285000. 500000. 250000. nan 240000. nan nan nan nan
290000. 300000. nan 500000. nan 220000. 650000. 350000. nan
265000. nan nan 276000. nan 252000. nan 280000. nan
nan nan 264000. 270000. 300000. nan 275000. 250000. 260000.
nan 265000. 300000. nan 240000. 260000. 210000. 250000. nan
300000. nan 216000. 400000. 275000. 295000. 204000. nan]

from sklearn.impute import SimpleImputer


imputer_y = SimpleImputer(missing_values=np.nan, strategy='mean')
imputer_y.fit(y.reshape(-1,1))
y = imputer_y.transform(y.reshape(-1,1))

print(y)

[[270000. ]
[200000. ]
[250000. ]
[288655.40540541]
[425000. ]
[288655.40540541]
[288655.40540541]
[252000. ]
[231000. ]
[288655.40540541]
[260000. ]
[250000. ]
[288655.40540541]
[218000. ]
[288655.40540541]
[200000. ]
[300000. ]
[288655.40540541]
[288655.40540541]
[236000. ]
[265000. ]
[393000. ]
[360000. ]
[300000. ]
[360000. ]
[288655.40540541]
[240000. ]
[265000. ]
[350000. ]
[288655.40540541]
[250000. ]
[288655.40540541]
[278000. ]
[260000. ]
[288655.40540541]
[300000. ]
[288655.40540541]
[320000. ]
[240000. ]
[411000. ]
[287000. ]
[288655.40540541]
[288655.40540541]
[300000. ]
[200000. ]
[288655.40540541]
[288655.40540541]
[204000. ]
[250000. ]
[288655.40540541]
[200000. ]
[288655.40540541]
[288655.40540541]
[450000. ]
[216000. ]
[220000. ]
[240000. ]
[360000. ]
[268000. ]
[265000. ]
[260000. ]
[300000. ]
[240000. ]
[288655.40540541]
[240000. ]
[288655.40540541]
[275000. ]
[275000. ]
[288655.40540541]
[275000. ]
[360000. ]
[240000. ]
[240000. ]
[218000. ]
[336000. ]
[288655.40540541]
[230000. ]
[500000. ]
[270000. ]
[288655.40540541]
[240000. ]
[300000. ]
[288655.40540541]
[300000. ]
[300000. ]
[400000. ]
[220000. ]
[288655.40540541]
[210000. ]
[210000. ]
[300000. ]
[288655.40540541]
[230000. ]
[288655.40540541]
[260000. ]
[420000. ]
[300000. ]
[288655.40540541]
[220000. ]
[288655.40540541]
[288655.40540541]
[380000. ]
[300000. ]
[240000. ]
[360000. ]
[288655.40540541]
[288655.40540541]
[200000. ]
[300000. ]
[288655.40540541]
[250000. ]
[288655.40540541]
[250000. ]
[280000. ]
[250000. ]
[216000. ]
[300000. ]
[240000. ]
[276000. ]
[940000. ]
[288655.40540541]
[250000. ]
[236000. ]
[240000. ]
[250000. ]
[350000. ]
[210000. ]
[250000. ]
[400000. ]
[250000. ]
[288655.40540541]
[360000. ]
[300000. ]
[250000. ]
[250000. ]
[200000. ]
[288655.40540541]
[225000. ]
[250000. ]
[220000. ]
[265000. ]
[288655.40540541]
[260000. ]
[300000. ]
[288655.40540541]
[400000. ]
[233000. ]
[300000. ]
[240000. ]
[288655.40540541]
[690000. ]
[270000. ]
[240000. ]
[340000. ]
[250000. ]
[288655.40540541]
[255000. ]
[300000. ]
[288655.40540541]
[288655.40540541]
[300000. ]
[288655.40540541]
[285000. ]
[500000. ]
[250000. ]
[288655.40540541]
[240000. ]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[290000. ]
[300000. ]
[288655.40540541]
[500000. ]
[288655.40540541]
[220000. ]
[650000. ]
[350000. ]
[288655.40540541]
[265000. ]
[288655.40540541]
[288655.40540541]
[276000. ]
[288655.40540541]
[252000. ]
[288655.40540541]
[280000. ]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[264000. ]
[270000. ]
[300000. ]
[288655.40540541]
[275000. ]
[250000. ]
[260000. ]
[288655.40540541]
[265000. ]
[300000. ]
[288655.40540541]
[240000. ]
[260000. ]
[210000. ]
[250000. ]
[288655.40540541]
[300000. ]
[288655.40540541]
[216000. ]
[400000. ]
[275000. ]
[295000. ]
[204000. ]
[288655.40540541]]

#Encoding categorical data that doesn't have binary result


from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder
ct = ColumnTransformer(transformers=[('encoder', OneHotEncoder(), [2])],
remainder='passthrough')
x = np.array(ct.fit_transform(x))
print(x)

[[0.0 1.0 0.0 ... 'No' 55.0 58.8]


[0.0 0.0 1.0 ... 'Yes' 86.5 66.28]
[1.0 0.0 0.0 ... 'No' 75.0 57.8]
...
[0.0 1.0 0.0 ... 'Yes' 59.0 69.72]
[0.0 1.0 0.0 ... 'No' 70.0 60.23]
[0.0 0.0 1.0 ... 'No' 89.0 60.22]]

#Encoding categorical data that have binary result


from sklearn.preprocessing import LabelEncoder
le = LabelEncoder()
x[:, 6] = le.fit_transform(x[:, 6])
print(x)

[[0.0 1.0 0.0 ... 0 55.0 58.8]


[0.0 0.0 1.0 ... 1 86.5 66.28]
[1.0 0.0 0.0 ... 0 75.0 57.8]
...
[0.0 1.0 0.0 ... 1 59.0 69.72]
[0.0 1.0 0.0 ... 0 70.0 60.23]
[0.0 0.0 1.0 ... 0 89.0 60.22]]

#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x = sc.fit_transform(x)

print(x)

[[-0.23221018 0.95008151 -0.85666269 ... -0.72444647 -1.29109087


-0.59764672]
[-0.23221018 -1.05254128 1.16732059 ... 1.38036423 1.08715679
0.6876202 ]
[ 4.30644338 -1.05254128 -0.85666269 ... -0.72444647 0.21890765
-0.76947385]
...
[-0.23221018 0.95008151 -0.85666269 ... 1.38036423 -0.98909117
1.27870553]
[-0.23221018 0.95008151 -0.85666269 ... -0.72444647 -0.15859198
-0.35193393]
[-0.23221018 -1.05254128 1.16732059 ... -0.72444647 1.27590661
-0.3536522 ]]

#Splitting the data into the Training set and Test set
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2,
random_state=42)

print(x_train)

[[-0.23221018 0.95008151 -0.85666269 ... -0.72444647 -0.00759213


-1.18014069]
[-0.23221018 -1.05254128 1.16732059 ... 1.38036423 -1.29109087
-0.04779991]
[-0.23221018 0.95008151 -0.85666269 ... 1.38036423 1.76363613
-0.02030757]
...
[-0.23221018 -1.05254128 1.16732059 ... -0.72444647 -0.00759213
-0.48252255]
[-0.23221018 -1.05254128 1.16732059 ... -0.72444647 0.25665761
1.69452718]
[-0.23221018 0.95008151 -0.85666269 ... 1.38036423 -1.10234106
-0.16636063]]
print(x_test)
[[-0.23221018 0.95008151 -0.85666269 0.15706399 -0.58251317 -0.18663291
-0.72444647 1.16643172 -1.62689123]
[-0.23221018 0.95008151 -0.85666269 -0.02808697 0.06133451 0.90304633
1.38036423 -0.98909117 1.27870553]
[-0.23221018 -1.05254128 1.16732059 1.36054521 -0.21460021 0.90304633
1.38036423 1.80440609 1.63095114]
[-0.23221018 0.95008151 -0.85666269 -0.7686908 -0.58251317 -1.41252206
-0.72444647 -1.29109087 -0.75229114]
[-0.23221018 0.95008151 -0.85666269 -0.21323793 0.79716044 0.35820671
1.38036423 -0.00759213 0.40926025]
[-0.23221018 -1.05254128 1.16732059 -1.50929463 -1.13438262 -0.73147253
-0.72444647 -0.91359124 -0.28148481]
[-0.23221018 0.95008151 -0.85666269 -1.78702107 -1.41031735 -1.14010225
1.38036423 -0.91359124 -0.59936499]
[-0.23221018 0.95008151 -0.85666269 -0.25026812 1.60932831 0.72869765
-0.72444647 1.04940683 -0.43441095]
[-0.23221018 0.95008151 -0.85666269 0.61994138 0.61320396 0.90304633
1.38036423 0.59640728 0.92989645]
[-0.23221018 0.95008151 -0.85666269 0.89766782 0.33726924 -1.00389234
1.38036423 -1.0645911 -1.34853128]
[-0.23221018 -1.05254128 1.16732059 -0.02808697 -0.30657845 -0.32284282
-0.72444647 -0.91359124 -0.07013744]
[-0.23221018 0.95008151 -0.85666269 -0.30581341 0.65919308 0.90304633
-0.72444647 -1.51759065 -0.95848369]
[-0.23221018 0.95008151 -0.85666269 -1.41671915 -0.21460021 -0.73147253
-0.72444647 -1.29109087 0.11199932]
[-0.23221018 0.95008151 -0.85666269 -0.86126628 0.33726924 -0.73147253
-0.72444647 -1.3665908 -1.7299875 ]
[-0.23221018 0.95008151 -0.85666269 1.2605637 1.11908429 0.0857869
-0.72444647 -0.25598689 -0.22134531]
[-0.23221018 -1.05254128 1.16732059 -0.39838889 -0.39855669 -0.18663291
-0.72444647 1.16265672 -0.27289345]
[-0.23221018 0.95008151 -0.85666269 1.17539426 1.25705165 0.76683642
1.38036423 -0.62744652 0.64638169]
[-0.23221018 0.95008151 -0.85666269 -0.39838889 -0.03064373 -0.32284282
-0.72444647 -0.30959184 0.30960052]
[-0.23221018 -1.05254128 1.16732059 -1.69444559 -0.67449142 -0.18663291
1.38036423 1.04940683 0.03467711]
[-0.23221018 -1.05254128 1.16732059 1.45312069 0.7051822 -0.05042301
-0.72444647 -0.2401319 -0.65606795]
[-0.23221018 -1.05254128 1.16732059 1.91599809 0.52122572 1.58409586
-0.72444647 0.74740713 1.57252992]
[-0.23221018 -1.05254128 1.16732059 1.63827165 -0.58251317 0.96161659
1.38036423 -0.91359124 -0.16979717]
[-0.23221018 -1.05254128 1.16732059 0.15706399 -0.39855669 -0.05042301
-0.72444647 0.21890765 0.98144459]
[-0.23221018 0.95008151 -0.85666269 -1.36302538 -1.07919568 -2.20253951
1.38036423 0.29440757 0.52438443]
[-0.23221018 -1.05254128 1.16732059 0.15706399 -0.30657845 -0.18663291
1.38036423 -1.29109087 -0.69558819]
[-0.23221018 -1.05254128 1.16732059 2.04560376 -0.06191633 0.664679
-0.72444647 -0.00759213 0.16354746]
[-0.23221018 0.95008151 -0.85666269 -1.2315682 1.03630387 0.38544869
-0.72444647 1.77798112 0.80102611]
[-0.23221018 0.95008151 -0.85666269 -0.39838889 -0.01224808 -0.10490697
1.38036423 -0.91359124 0.04498674]
[-0.23221018 -1.05254128 1.16732059 0.80509234 -0.21460021 0.76683642
-0.72444647 -1.0645911 0.73057699]
[-0.23221018 -1.05254128 1.16732059 0.34221495 -0.70576402 -1.14010225
1.38036423 -1.21559095 -0.1680789 ]
[-0.23221018 0.95008151 -0.85666269 -0.58353984 1.44100813 0.35820671
-0.72444647 0.89840698 -0.68184202]
[-0.23221018 -1.05254128 1.16732059 -0.63908513 0.02454322 -0.18663291
-0.72444647 -0.08309206 -1.64407394]
[-0.23221018 0.95008151 -0.85666269 -0.86126628 -0.49053493 -0.73147253
-0.72444647 -1.0645911 -1.43272657]
[-0.23221018 -1.05254128 1.16732059 -0.02808697 -0.49053493 0.76683642
-0.72444647 -0.00759213 -0.21790877]
[-0.23221018 -1.05254128 1.16732059 -0.02808697 0.42924748 -0.27789355
1.38036423 -0.61159154 -0.17495199]
[-0.23221018 -1.05254128 1.16732059 1.21242445 0.64999526 1.54595708
1.38036423 0.68700719 2.40245495]
[-0.23221018 0.95008151 -0.85666269 -0.7686908 -0.39855669 1.5159909
-0.72444647 0.14340772 0.81133574]
[-0.23221018 -1.05254128 1.16732059 0.43479043 -0.95042614 0.35820671
-0.72444647 -1.24579092 0.57593257]
[-0.23221018 -1.05254128 1.16732059 0.80509234 1.25705165 1.58409586
1.38036423 1.87990602 1.40929415]
[-0.23221018 0.95008151 -0.85666269 0.15706399 0.61320396 -0.18663291
-0.72444647 -0.15859198 -0.85366915]
[-0.23221018 -1.05254128 1.16732059 0.80509234 0.33726924 1.31167605
1.38036423 -0.46059169 0.37145829]
[-0.23221018 0.95008151 -0.85666269 -0.21323793 0.98111693 0.35820671
-0.72444647 -0.91359124 -0.07872879]
[-0.23221018 -1.05254128 1.16732059 0.89766782 0.79716044 0.90304633
-0.72444647 0.59640728 0.81992709]]

print(y_train)

[[288655.40540541]
[300000. ]
[420000. ]
[225000. ]
[400000. ]
[220000. ]
[285000. ]
[240000. ]
[240000. ]
[360000. ]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[236000. ]
[275000. ]
[288655.40540541]
[260000. ]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[240000. ]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[300000. ]
[350000. ]
[288655.40540541]
[288655.40540541]
[380000. ]
[233000. ]
[288655.40540541]
[250000. ]
[288655.40540541]
[230000. ]
[288655.40540541]
[300000. ]
[270000. ]
[250000. ]
[240000. ]
[300000. ]
[280000. ]
[350000. ]
[250000. ]
[500000. ]
[288655.40540541]
[204000. ]
[216000. ]
[300000. ]
[400000. ]
[288655.40540541]
[288655.40540541]
[236000. ]
[300000. ]
[360000. ]
[288655.40540541]
[940000. ]
[260000. ]
[250000. ]
[216000. ]
[288655.40540541]
[288655.40540541]
[265000. ]
[250000. ]
[288655.40540541]
[300000. ]
[425000. ]
[278000. ]
[288655.40540541]
[288655.40540541]
[300000. ]
[250000. ]
[250000. ]
[260000. ]
[240000. ]
[210000. ]
[255000. ]
[650000. ]
[270000. ]
[300000. ]
[500000. ]
[360000. ]
[288655.40540541]
[240000. ]
[200000. ]
[265000. ]
[287000. ]
[240000. ]
[300000. ]
[288655.40540541]
[270000. ]
[300000. ]
[411000. ]
[265000. ]
[204000. ]
[260000. ]
[250000. ]
[300000. ]
[240000. ]
[288655.40540541]
[288655.40540541]
[450000. ]
[250000. ]
[288655.40540541]
[288655.40540541]
[265000. ]
[288655.40540541]
[240000. ]
[288655.40540541]
[252000. ]
[250000. ]
[288655.40540541]
[300000. ]
[288655.40540541]
[275000. ]
[210000. ]
[231000. ]
[218000. ]
[265000. ]
[288655.40540541]
[360000. ]
[288655.40540541]
[240000. ]
[240000. ]
[288655.40540541]
[250000. ]
[350000. ]
[260000. ]
[288655.40540541]
[216000. ]
[200000. ]
[200000. ]
[500000. ]
[275000. ]
[288655.40540541]
[268000. ]
[250000. ]
[210000. ]
[393000. ]
[360000. ]
[300000. ]
[300000. ]
[280000. ]
[250000. ]
[320000. ]
[300000. ]
[260000. ]
[200000. ]
[288655.40540541]
[288655.40540541]
[288655.40540541]
[270000. ]
[240000. ]
[288655.40540541]
[300000. ]
[288655.40540541]
[240000. ]
[336000. ]
[250000. ]
[288655.40540541]
[265000. ]
[288655.40540541]
[240000. ]
[288655.40540541]
[288655.40540541]
[230000. ]
[288655.40540541]
[300000. ]]

[ ]
print(y_test)
[[300000. ]
[295000. ]
[250000. ]
[220000. ]
[200000. ]
[288655.40540541]
[288655.40540541]
[218000. ]
[210000. ]
[220000. ]
[288655.40540541]
[250000. ]
[288655.40540541]
[288655.40540541]
[275000. ]
[288655.40540541]
[290000. ]
[288655.40540541]
[340000. ]
[275000. ]
[252000. ]
[260000. ]
[288655.40540541]
[288655.40540541]
[360000. ]
[400000. ]
[288655.40540541]
[300000. ]
[288655.40540541]
[690000. ]
[300000. ]
[220000. ]
[250000. ]
[264000. ]
[250000. ]
[400000. ]
[288655.40540541]
[200000. ]
[276000. ]
[220000. ]
[300000. ]
[276000. ]
[240000. ]]
Experiment-2

Building Decision Trees for Soybean classification model using


Weka

Decision Tree Classification Algorithm


o Decision Tree is a Supervised learning technique that can be used
for both classification and Regression problems, but mostly it is
preferred for solving Classification problems. It is a tree-
structured classifier, where internal nodes represent the features
of a dataset, branches represent the decision rules and each leaf
node represents the outcome.
o In a Decision tree, there are two nodes, which are the Decision
Node and Leaf Node. Decision nodes are used to make any decision and
have multiple branches, whereas Leaf nodes are the output of those
decisions and do not contain any further branches.
o The decisions or the test are performed on the basis of features of
the given dataset.
o It is a graphical representation for getting all the possible
solutions to a problem/decision based on given conditions.
o It is called a decision tree because, similar to a tree, it starts
with the root node, which expands on further branches and constructs
a tree-like structure.
o In order to build a tree, we use the CART algorithm, which stands
for Classification and Regression Tree algorithm.
o A decision tree simply asks a question, and based on the answer
(Yes/No), it further split the tree into subtrees.
Decision Tree Algorithm
o Step-1: Begin the tree with the root node, says S, which contains
the complete dataset.
o Step-2: Find the best attribute in the dataset using Attribute
Selection Measure (ASM).
o Step-3: Divide the S into subsets that contains possible values for
the best attributes.
o Step-4: Generate the decision tree node, which contains the best
attribute.
o Step-5: Recursively make new decision trees using the subsets of the
dataset created in step -3. Continue this process until a stage is
reached where you cannot further classify the nodes and called the
final node as a leaf node.

Step:1

Open WEKA Tool.

Step2 : Click on Explorer it opens a WEKA explorer wizard to select the


Soybean data set from WEKA data folder
Data Set is opened and visualise the attributes
Step:4
Apply the Decision tree Classification algorithm by click the tab
Classify from the WEKA explorer wizard.
Classify Click on Choose Button  Select Trees  Select J48

Step: 5
Click on Start Button to apply the Decision Tree Algorithm
Output:
=== Run information ===
Scheme: weka.classifiers.trees.J48 -C 0.25 -M 2
Relation: soybean
Instances: 683
Attributes: 36
date
plant-stand
precip
temp
hail
crop-hist
area-damaged
severity
seed-tmt
germination
plant-growth
leaves
leafspots-halo
leafspots-marg
leafspot-size
leaf-shread
leaf-malf
leaf-mild
stem
lodging
stem-cankers
canker-lesion
fruiting-bodies
external-decay
mycelium
int-discolor
sclerotia
fruit-pods
fruit-spots
seed
mold-growth
seed-discolor
seed-size
shriveling
roots
class
Test mode: 10-fold cross-validation

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

J48 pruned tree


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

leafspot-size = lt-1/8
| canker-lesion = dna
| | leafspots-marg = w-s-marg
| | | seed-size = norm: bacterial-blight (21.0/1.0)
| | | seed-size = lt-norm: bacterial-pustule (3.23/1.23)
| | leafspots-marg = no-w-s-marg: bacterial-pustule (17.91/0.91)
| | leafspots-marg = dna: bacterial-blight (0.0)
| canker-lesion = brown: bacterial-blight (0.0)
| canker-lesion = dk-brown-blk: phytophthora-rot (4.78/0.1)
| canker-lesion = tan: purple-seed-stain (11.23/0.23)
leafspot-size = gt-1/8
| roots = norm
| | mold-growth = absent
| | | fruit-spots = absent
| | | | leaf-malf = absent
| | | | | fruiting-bodies = absent
| | | | | | date = april: brown-spot (5.0)
| | | | | | date = may: brown-spot (24.0/1.0)
| | | | | | date = june
| | | | | | | precip = lt-norm: phyllosticta-leaf-spot
(4.0)
| | | | | | | precip = norm: brown-spot (5.0/2.0)
| | | | | | | precip = gt-norm: brown-spot (21.0)
| | | | | | date = july
| | | | | | | precip = lt-norm: phyllosticta-leaf-spot
(1.0)
| | | | | | | precip = norm: phyllosticta-leaf-spot (2.0)
| | | | | | | precip = gt-norm: frog-eye-leaf-spot
(11.0/5.0)
| | | | | | date = august
| | | | | | | leaf-shread = absent
| | | | | | | | seed-tmt = none: alternarialeaf-spot
(16.0/4.0)
| | | | | | | | seed-tmt = fungicide
| | | | | | | | | plant-stand = normal: frog-eye-leaf-
spot (6.0)
| | | | | | | | | plant-stand = lt-normal:
alternarialeaf-spot (5.0/1.0)
| | | | | | | | seed-tmt = other: frog-eye-leaf-spot
(3.0)
| | | | | | | leaf-shread = present: alternarialeaf-spot
(2.0)
| | | | | | date = september
| | | | | | | stem = norm: alternarialeaf-spot (44.0/4.0)
| | | | | | | stem = abnorm: frog-eye-leaf-spot (2.0)
| | | | | | date = october: alternarialeaf-spot (31.0/1.0)
| | | | | fruiting-bodies = present: brown-spot (34.0)
| | | | leaf-malf = present: phyllosticta-leaf-spot (10.0)
| | | fruit-spots = colored
| | | | fruit-pods = norm: brown-spot (2.0)
| | | | fruit-pods = diseased: frog-eye-leaf-spot (62.0)
| | | | fruit-pods = few-present: frog-eye-leaf-spot (0.0)
| | | | fruit-pods = dna: frog-eye-leaf-spot (0.0)
| | | fruit-spots = brown-w/blk-specks
| | | | crop-hist = diff-lst-year: brown-spot (0.0)
| | | | crop-hist = same-lst-yr: brown-spot (2.0)
| | | | crop-hist = same-lst-two-yrs: brown-spot (0.0)
| | | | crop-hist = same-lst-sev-yrs: frog-eye-leaf-spot (2.0)
| | | fruit-spots = distort: brown-spot (0.0)
| | | fruit-spots = dna: brown-stem-rot (9.0)
| | mold-growth = present
| | | leaves = norm: diaporthe-pod-&-stem-blight (7.25)
| | | leaves = abnorm: downy-mildew (20.0)
| roots = rotted
| | area-damaged = scattered: herbicide-injury (1.1/0.1)
| | area-damaged = low-areas: phytophthora-rot (30.03)
| | area-damaged = upper-areas: phytophthora-rot (0.0)
| | area-damaged = whole-field: herbicide-injury (3.66/0.66)
| roots = galls-cysts: cyst-nematode (7.81/0.17)
leafspot-size = dna
| int-discolor = none
| | leaves = norm
| | | stem-cankers = absent
| | | | canker-lesion = dna: diaporthe-pod-&-stem-blight (5.53)
| | | | canker-lesion = brown: purple-seed-stain (0.0)
| | | | canker-lesion = dk-brown-blk: purple-seed-stain (0.0)
| | | | canker-lesion = tan: purple-seed-stain (9.0)
| | | stem-cankers = below-soil: rhizoctonia-root-rot (19.0)
| | | stem-cankers = above-soil: anthracnose (0.0)
| | | stem-cankers = above-sec-nde: anthracnose (24.0)
| | leaves = abnorm
| | | stem = norm
| | | | plant-growth = norm: powdery-mildew (22.0/2.0)
| | | | plant-growth = abnorm: cyst-nematode (4.3/0.39)
| | | stem = abnorm
| | | | plant-stand = normal
| | | | | leaf-malf = absent
| | | | | | seed = norm: diaporthe-stem-canker (21.0/1.0)
| | | | | | seed = abnorm: anthracnose (9.0)
| | | | | leaf-malf = present: 2-4-d-injury (3.0)
| | | | plant-stand = lt-normal
| | | | | fruiting-bodies = absent: phytophthora-rot
(50.16/7.61)
| | | | | fruiting-bodies = present
| | | | | | roots = norm: anthracnose (11.0/1.0)
| | | | | | roots = rotted: phytophthora-rot (12.89/2.15)
| | | | | | roots = galls-cysts: phytophthora-rot (0.0)
| int-discolor = brown
| | leaf-malf = absent: brown-stem-rot (35.73/0.73)
| | leaf-malf = present: 2-4-d-injury (3.15/0.68)
| int-discolor = black: charcoal-rot (22.22/2.22)
Number of Leaves : 61
Size of the tree : 93
Time taken to build model: 0.08 seconds

=== Stratified cross-validation ===


=== Summary ===

Correctly Classified Instances 625 91.5081 %


Incorrectly Classified Instances 58 8.4919 %
Kappa statistic 0.9068
Mean absolute error 0.0135
Root mean squared error 0.0842
Relative absolute error 14.0484 %
Root relative squared error 38.4134 %
Total Number of Instances 683

=== Detailed Accuracy By Class ===

TP Rate FP Rate Precision Recall F-Measure MCC


ROC Area PRC Area Class
0.950 0.002 0.950 0.950 0.950 0.948
0.974 0.873 diaporthe-stem-canker
1.000 0.000 1.000 1.000 1.000 1.000
1.000 1.000 charcoal-rot
0.950 0.002 0.950 0.950 0.950 0.948
0.974 0.951 rhizoctonia-root-rot
0.989 0.010 0.935 0.989 0.961 0.956
0.990 0.927 phytophthora-rot
1.000 0.000 1.000 1.000 1.000 1.000
1.000 1.000 brown-stem-rot
1.000 0.000 1.000 1.000 1.000 1.000
1.000 1.000 powdery-mildew
1.000 0.000 1.000 1.000 1.000 1.000
1.000 1.000 downy-mildew
0.924 0.012 0.924 0.924 0.924 0.912
0.995 0.949 brown-spot
1.000 0.002 0.952 1.000 0.976 0.975
0.999 0.924 bacterial-blight
0.950 0.000 1.000 0.950 0.974 0.974
0.973 0.951 bacterial-pustule
1.000 0.000 1.000 1.000 1.000 1.000
1.000 1.000 purple-seed-stain
0.909 0.005 0.930 0.909 0.920 0.914
0.973 0.925 anthracnose
0.700 0.005 0.824 0.700 0.757 0.753
0.972 0.853 phyllosticta-leaf-spot
0.934 0.035 0.802 0.934 0.863 0.843
0.968 0.869 alternarialeaf-spot
0.736 0.020 0.848 0.736 0.788 0.761
0.966 0.858 frog-eye-leaf-spot
1.000 0.001 0.938 1.000 0.968 0.968
0.999 0.845 diaporthe-pod-&-stem-blight
1.000 0.000 1.000 1.000 1.000 1.000
1.000 1.000 cyst-nematode
0.875 0.003 0.875 0.875 0.875 0.872
0.998 0.930 2-4-d-injury
0.375 0.000 1.000 0.375 0.545 0.610
0.915 0.646 herbicide-injury
Weighted Avg. 0.915 0.011 0.917 0.915 0.913 0.904
0.983 0.920

Step 6:
To Visualize Decision Tree: Right Click on tree J48 and Select
Visualize Tree option .
Experiment -3 Generating association rules on Weather data
using Weka

Apriori algorithm refers to an algorithm that is used in mining frequent


products sets and relevant association rules. Generally, the apriori
algorithm operates on a database containing a huge number of
transactions. For example, the items customers buy at a Big Bazar.

Components of Apriori algorithm.


1. Support
2. Confidence

Support

Support refers to the default popularity of any product. You find the
support as a quotient of the division of the number of transactions
comprising that product by the total number of transactions.

Support (item) = (Transactions relating item) / (Total transactions)

Confidence

Confidence refers to the possibility that the customers bought both item
i and item j together. So, you need to divide the number of transactions
that comprise both item I and item j by the total number of transactions
to get the confidence.

Hence,

Confidence = (Transactions relating both item I and item J) / (Total


transactions involving item i)

Steps for Apriori Algorithm

Step-1: Determine the support of itemsets in the transactional database,


and select the minimum support and confidence.

Step-2: Take all supports in the transaction with higher support value
than the minimum or selected support value.

Step-3: Find all the rules of these subsets that have higher confidence
value than the threshold or minimum confidence.

Step-4: Sort the rules as the decreasing order of lift.


Step:1
Open WEKA Tool.

Step2 : Click on Explorer it opens a WEKA explorer wizard to select the


Weather nominal data set from WEKA data folder
.

Step 3:
Apply Apriori algorithm by selecting Associate Tab  choose  Apriori
Step 4: Click on Start button to Generate Association rules
Output:
Experiment -4

Exploring machine learning models including classification and


clustering Weka

Naïve Bayes Classifier Algorithm

o Naïve Bayes algorithm is a supervised learning algorithm, which is


based on Bayes theorem and used for solving classification problems.
o It is mainly used in text classification that includes a high-
dimensional training dataset.
o Naïve Bayes Classifier is one of the simple and most effective
Classification algorithms which helps in building the fast machine
learning models that can make quick predictions.
o It is a probabilistic classifier, which means it predicts on the
basis of the probability of an object

Bayes' Theorem:
o Bayes' theorem is also known as Bayes' Rule or Bayes' law, which is
used to determine the probability of a hypothesis with prior
knowledge. It depends on the conditional probability.
o The formula for Bayes' theorem is given as:

Where,

P(A|B) is Posterior probability: Probability of hypothesis A on the


observed event B.

P(B|A) is Likelihood probability: Probability of the evidence given that


the probability of a hypothesis is true.

P(A) is Prior Probability: Probability of hypothesis before observing the


evidence.

P(B) is Marginal Probability: Probability of Evidence.


Step:1
Open WEKA Tool.

Step2 : Click on Explorer it opens a WEKA explorer wizard to select the


weather nominal data set from WEKA data folder
Step 3:
Click on Classify tab from WEKA explorer wizard choose file - Bayes -
naïve Bayes
Step : 4 Click on Start Button

Output:
Clustering
Hierarchical clustering is another unsupervised learning algorithm that
is used to group together the unlabeled data points having similar
characteristics. Hierarchical clustering algorithms falls into following
two categories.
Agglomerative hierarchical algorithms − In agglomerative hierarchical
algorithms, each data point is treated as a single cluster and then
successively merge or agglomerate (bottom-up approach) the pairs of
clusters. The hierarchy of the clusters is represented as a dendrogram or
tree structure.
Divisive hierarchical algorithms − On the other hand, in divisive
hierarchical algorithms, all the data points are treated as one big
cluster and the process of clustering involves dividing (Top-down
approach) the one big cluster into various small clusters.
Steps to Perform Agglomerative Hierarchical Clustering
 Step 1 − Treat each data point as single cluster. Hence, we will be
having, say K clusters at start. The number of data points will also
be K at start.
 Step 2 − Now, in this step we need to form a big cluster by joining
two closet datapoints. This will result in total of K-1 clusters.
 Step 3 − Now, to form more clusters we need to join two closet
clusters. This will result in total of K-2 clusters.
 Step 4 − Now, to form one big cluster repeat the above three steps
until K would become 0 i.e. no more data points left to join.
 Step 5 − At last, after making one single big cluster, dendrograms
will be used to divide into multiple clusters depending upon the
problem.
Step:1

Open WEKA Tool.

Step2 : Click on Explorer it opens a WEKA explorer wizard to select the


breast cancer data set from WEKA data folder
Step:3
Choose Hierarchical clustering from Cluster Tab and click on Start button
to continue.

Output:

To visualize cluster right click on hierarchical clustering to select


Visualize the model
Experiment -5

Build Neural Network Classifier using Weka


Step:1
Open WEKA Tool.

Step2 : Click on Explorer it opens a WEKA explorer wizard to select the


weather nominal data set from WEKA data folder
Step 3: Goto Classify tab and Choose Multilayer perception and click on
start button

Step 4: Right click on Multilayer perception and open show properties


Step 5: Set GUI property to true.. to visualise the results

Step 5: Result obtained is


Experiment- 6

Supervisely - Perform Data Labelling for various images using


object recognition

Step:1 Open google and search supervise.ly

Step 2:
Open the supervisely and click on login Option
If you open this for the first time signup and confirm with Registered
Mail id.

Step: 3 After successful login it opens the Dashboard to create a


project

Step 4: Click on Projects option to create a new project

Step 5: click on import images Option to select the images to the project
Use Drag and Drop option to upload the images.

Select the images to upload


After successful uploading images click on run option to create a project
at that time give the project name
It creates a workspace.

Double Click on Created Project to open annotation ToolBox.


Click on DATASET in BASIC IMAGE LABELING TOOL BOX

It opens Annotation toolbox wizard to Plot the objects


Create objects with Names after creating objects click on home button
Experiment 7

Image Classifier using Open CV

Step 1: Open Google colab and upload the required image and XML files to
run the code

Upload images into Google Colab Notebook.

https://drive.google.com/file/d/1_tNcvc4aUPehLt_hgwhzlKTvfd1hActT/view?us
p=share_link
https://drive.google.com/file/d/1iEi4KV7nAQRsqedevnC_SCTfIbn4diY5/view?us
p=share_link

import cv2

from matplotlib import pyplot as plt

# Opening image

img = cv2.imread("image.png")

# OpenCV opens images as BRG but we want it as RGB and we also need a
grayscale version

img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

# Creates the environment of the picture and shows it

plt.subplot(1, 1, 1)

plt.imshow(img_rgb)

plt.show()

# Use minSize because for not

# bothering with extra-small

# dots that would look like STOP signs

stop_data = cv2.CascadeClassifier('stop_data.xml')

found = stop_data.detectMultiScale(img_gray, minSize =(20, 20))

# Don't do anything if there's no sign


amount_found = len(found)

if amount_found != 0:

# There may be more than one sign in the image

for (x, y, width, height) in found:

# We draw a green rectangle around every recognized sign

cv2.rectangle(img_rgb, (x, y),

(x + height, y + width),

(0, 255, 0), 5)

# Creates the environment of

# the picture and shows it

plt.subplot(1, 1, 1)

plt.imshow(img_rgb)

plt.show()
Output:
Experiment-8

Automatic Facial recognition using Open CV

Step 1: Open Google colab and upload the required image and XML files to
run the code

Upload images into Google Colab Notebook.

https://drive.google.com/file/d/11QnT_0lzJX-
yLChDnys5izS30UyOjTeJ/view?usp=share_link

https://drive.google.com/file/d/1IYJHJqvFRG4PlvAe5eXOi53Km5OSknLT/view?us
p=share_link

https://drive.google.com/file/d/1CBdkHMSB_cGjoELlUa3jkueDp3sZGNdg/view?us
p=share_link

https://drive.google.com/file/d/11bnizOSJ2T3kZQ4oZLMKMs2KVCoa8T5x/view?us
p=share_link

https://drive.google.com/file/d/1W9L2TAACKAmNq4VaAPQcVjv3GcUJdbkF/view?us
p=share_link

Code:

import cv2

from matplotlib import pyplot as plt

face_cascade =
cv2.CascadeClassifier("haarcascade_frontalface_default.xml")

eye_cascade = cv2.CascadeClassifier("haarcascade_eye.xml")

img = cv2.imread("people.jpg")

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray, 1.3, 5)

for (x,y,w,h) in faces:

img1 = cv2.rectangle(img,(x, y),(x + w, y + h),(255,255,0),2)

roi_gray = gray[y: y + h, x: x + w]

roi_color = img[y: y + h, x: x + w]

eyes = eye_cascade.detectMultiScale(roi_gray)

for (ex, ey, ew, eh) in eyes:

cv2.rectangle(roi_color,(ex, ey), (ex + ew, ey + eh),


(0,255,0),2)
plt.subplot(1, 1, 1)

plt.imshow(img)

plt.show()

cat_face_cascade =
cv2.CascadeClassifier("haarcascade_frontalcatface.xml")

img = cv2.imread("cats.jpg")

img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)

faces = cat_face_cascade.detectMultiScale(img_rgb, 1.1, 4)

for (x,y,w,h) in faces:

img2 = cv2.rectangle(img_rgb,(x, y),(x + w, y + h),(255,255,0),5)

plt.subplot(1, 1, 1)

plt.imshow(img_rgb)

plt.show()

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy