ML Lab Manual
ML Lab Manual
print(data)
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)
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]]
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
x = sc.fit_transform(x)
print(x)
#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)
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
Step:1
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
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
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
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.
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,
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 3:
Apply Apriori algorithm by selecting Associate Tab choose Apriori
Step 4: Click on Start button to Generate Association rules
Output:
Experiment -4
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,
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
Output:
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 5: click on import images Option to select the images to the project
Use Drag and Drop option to upload the images.
Step 1: Open Google colab and upload the required image and XML files to
run the code
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
# 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
plt.subplot(1, 1, 1)
plt.imshow(img_rgb)
plt.show()
stop_data = cv2.CascadeClassifier('stop_data.xml')
if amount_found != 0:
(x + height, y + width),
plt.subplot(1, 1, 1)
plt.imshow(img_rgb)
plt.show()
Output:
Experiment-8
Step 1: Open Google colab and upload the required image and XML files to
run the code
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
face_cascade =
cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
eye_cascade = cv2.CascadeClassifier("haarcascade_eye.xml")
img = cv2.imread("people.jpg")
roi_gray = gray[y: y + h, x: x + w]
roi_color = img[y: y + h, x: x + w]
eyes = eye_cascade.detectMultiScale(roi_gray)
plt.imshow(img)
plt.show()
cat_face_cascade =
cv2.CascadeClassifier("haarcascade_frontalcatface.xml")
img = cv2.imread("cats.jpg")
plt.subplot(1, 1, 1)
plt.imshow(img_rgb)
plt.show()