Machine learning lab file
Practical No1
Aim:- Implement and demonstrate the FIND-S algorithm for finding the most specific hypothesis based on a given set of training data sample
Algorithm:-
1. Initialize h to the most specific hypothesis in H
2. For each positive training instance x
For each attribute constraint a, in h
If the constraint a, is satisfied by x
Then do nothing
Else replace a, in h by the next more general constraint that is satisfied by x
3. Output hypothesis h
Input value table
Source code :-
#Initialize the hypothesis with the most general values
hypothesis = []
# Define the training data (attributes and target)
training_data = [(
'Green','Hard','No','Wrinkled','Yes'),
('Green','Hard','Yes','Smooth','No'),
('Brown','Soft','No','Wrinkled','No'),
('Orange','Hard','No','Wrinkled','Yes'),
('Green','Soft','Yes','Smooth','Yes'),
('Green','Hard','Yes','Wrinkled','Yes'),
('Orange','Hard','No','Wrinkled','Yes')]
#Intialize the hypothesis with the first positive example
for i in range(len(training_data[0])-1):
hypothesis.append(training_data[0][i])
#implement the find -s algorithm
for example in training_data:
if example[-1]=='Yes': #positive example
for i in range(len(example)-1):
if example[i]!=hypothesis[i]:
hypothesis[i] ='?' #replace with "?" if not consitent
#print the final hypothesis
print("final hypothesis:",hypothesis)
Output:-
Practical No 2
Aim:-create confusion matrix using examples
A confusion matrix is a matrix that summarizes the performance of a machine learning model on a set of test data. It is often used to measure the performance of classification models, which aim to predict a categorical label for each input instance. The matrix displays the number of true positives (TP), true negatives (TN), false positives (FP), and false negatives (FN) produced by the model on the test data.
For binary classification, the matrix will be of a 2X2 table, For multi-class classification, the matrix shape will be equal to the number of classes i.e for n classes it will be nXn.
A 2X2 Confusion matrix is shown below for the image recognization having a Dog image or Not Dog image.
True Positive (TP): It is the total counts having both predicted and actual values are Dog.
True Negative (TN): It is the total counts having both predicted and actual values are Not Dog.
False Positive (FP): It is the total counts having prediction is Dog while actually Not Dog.
False Negative (FN): It is the total counts having prediction is Not Dog while actually, it is Dog.
output/input
Practical No3
Aim:-calculate accuracy and precision based on confusion matrix
From the confusion matrix, we can find the following metrics
Accuracy: Accuracy is used to measure the performance of the model. It is the ratio of Total correct instances to the total instances
Precision: Precision is a measure of how accurate a model’s positive predictions are. It is defined as the ratio of true positive predictions to the total number of positive predictions made by the model
Output/input
Comments
Post a Comment