0% found this document useful (0 votes)
8 views4 pages

ML Practical 2 Worksheet

Uploaded by

Chandresh Yadav
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)
8 views4 pages

ML Practical 2 Worksheet

Uploaded by

Chandresh Yadav
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/ 4

Machine Learning

Practical # 2

Name Ninad Karlekar Roll Number 22306A1012

Subject/Course: Machine Learning Class M.Sc. IT – Sem III

Topic Concept Learning Batch Batch 1

Topic: Concept Learning / two-way classification / binary classification


a) AIM: Implement and demonstrate the find-s algorithm for finding the most specific.

DESCRIPTION:
1. Training dataset table (input data):

2.: Write the right hypothesis/function from historical data

One of the often-used statistical concepts in machine learning is the hypothesis.It is notably employed in
supervised machine learning, where an ML model uses a dataset to train a function that most effectively
translates input to related outputs.
In this code person enjoys sport if weather is sunny, airtemp is warm, wind is strong

3. How Does It Work?


It eliminates attribute that do not affect target column

4: Code and output:


import csv
num_attributes = 6
a = []

print("\n The Given Training Dataset \n")


with open('Book1.csv','r') as csvfile:
reader = csv.reader(csvfile)
count = 0
for row in reader:
if count == 0:
print(row)

Vidyalankar School of Information Technology


count+=1;
else:
a.append(row)
print(row)
count+=1

print("\n The initial value of hypothesis: ")


hypothesis = ['0'] * num_attributes
print(hypothesis)

for j in range(0,num_attributes):
hypothesis[j]= a[0][j];
print(hypothesis)

print("\n find S:finding a Maximally specific Hypothesis\n")


for i in range(0,len(a)):
if a[i][num_attributes]=="Yes":
for j in range(0,num_attributes):
if a[i][j]!=hypothesis[j]:
hypothesis[j]='?'
else:
hypothesis[j] = a[i][j]
print("for training example no :{0} the hypothesis is".format(i),hypothesis)

Vidyalankar School of Information Technology


import csv

a = []
with open('book2.csv', 'r') as csvfile:
next(csvfile)
for row in csv.reader(csvfile):
a.append(row)

for x in a:
print(x)

print("\nThe total number of training instances are : ",len(a))

num_attribute = len(a[0])-1
print("\nThe initial hypothesis is : ")
hypothesis = ['0']*num_attribute
print(hypothesis)

for i in range(0, len(a)):

if a[i][num_attribute] == 'yes':

print ("\nInstance ", i+1, "is", a[i], " and is Positive Instance")

for j in range(0, num_attribute):

if hypothesis[j] == '0' or hypothesis[j] == a[i][j]:

hypothesis[j] = a[i][j]

else:

hypothesis[j] = '?'

print("The hypothesis for the training instance", i+1, " is: " ,
hypothesis, "\n")

if a[i][num_attribute] == 'no':

Vidyalankar School of Information Technology


print ("\nInstance ", i+1, "is", a[i], " and is Negative Instance Hence
Ignored")

print("The hypothesis for the training instance", i+1, " is: " ,
hypothesis, "\n")

print("\nThe Maximally specific hypothesis for the training instance is ",


hypothesis)

Vidyalankar School of Information Technology

You might also like