Practical2.Ipynb - Colab
Practical2.Ipynb - Colab
ipynb - Colab
Dataset:
Sky Temperature Humidity Wind Water Forecast Condition
0 Sunny Warm Normal Strong Warm Same Yes
1 Sunny Cold High Strong Warm Same No
2 Rainy Warm High Weak Cool Change No
3 Sunny Warm Normal Strong Warm Same Yes
4 Rainy Cold Normal Weak Cool Change No
Loaded Dataset:
Sky Temperature Humidity Wind Water Forecast Condition
0 Sunny Warm Normal Strong Warm Same Yes
1 Sunny Cold High Strong Warm Same No
2 Rainy Warm High Weak Cool Change No
3 Sunny Warm Normal Strong Warm Same Yes
4 Rainy Cold Normal Weak Cool Change No
def find_s(training_data):
# Extract the features and target
features = training_data.iloc[:, :-1].values # All columns except the last
target = training_data.iloc[:, -1].values # Last column (target variable)
# Initialize the most specific hypothesis
hypothesis = ['Ø'] * features.shape[1]
# Iterate through each example in the dataset
for i, example in enumerate(features):
if target[i] == 'Yes': # Consider only positive examples
for j in range(len(hypothesis)):
if hypothesis[j] == 'Ø': # Update the hypothesis initially
hypothesis[j] = example[j]
elif hypothesis[j] != example[j]: # Generalize if inconsistent
hypothesis[j] = '?'
return hypothesis # Added indentation here
https://colab.research.google.com/drive/1LUMKY7X7yNAYxxa8FRHNik3CyxcgBwmV#scrollTo=dEAWSwRimbLk&printMode=true 1/2
11/30/24, 3:54 PM Practical2.ipynb - Colab
https://colab.research.google.com/drive/1LUMKY7X7yNAYxxa8FRHNik3CyxcgBwmV#scrollTo=dEAWSwRimbLk&printMode=true 2/2