Loading data...

vtucircle » BCSL606 Program 4

BCSL606 Program 4

PROGRAM: download csv file click here

import pandas as pd


def find_s_algorithm(file_path):
    data = pd.read_csv(file_path)

    print("Training data:")
    print(data)

    attributes = data.columns[:-1]
    class_label = data.columns[-1]

    hypothesis = ['?' for _ in attributes]

    for index, row in data.iterrows():
        if row[class_label] == 'Yes':
            for i, value in enumerate(row[attributes]):
                if hypothesis[i] == '?' or hypothesis[i] == value:
                    hypothesis[i] = value
                else:
                    hypothesis[i] = '?'

    return hypothesis


file_path = 'training_data.csv'
hypothesis = find_s_algorithm(file_path)
print("\nThe final hypothesis is:", hypothesis)

OUTPUT:

Training data:

     Outlook  Temperature  Humidity  Windy  PlayTennis
0     Sunny         Hot     High     False       No
1     Sunny         Hot     High     True        No
2  Overcast         Hot     High     False       Yes
3      Rain        Cold     High     False       Yes
4      Rain        Cold     High     True        No
5  Overcast         Hot     High     True        Yes
6     Sunny         Hot     High     False       No


The final hypothesis is: ['Overcast', 'Hot', 'High', '?']
guest
2 Comments
Inline Feedbacks
View all comments
Prashanth
Prashanth
15-03-2025 11:52 AM

The output is incorrect.

It should be [‘?’, ‘?’, ‘high’, ‘?’].

Try doing it manually—some changes need to be made:
1.Initialize hypothesis = None.
2.Use a for loop.
3.Add an if condition:
If hypothesis == None, set hypothesis = list(row[attributes]).
Please correct your code, as it has issues.

chota bheem
chota bheem
21-04-2025 2:58 PM

sir try to give us the question paper of the BDA subject ,vtu question paper

2
0
Would love your thoughts, please comment.x
()
x