0% found this document useful (0 votes)
3 views2 pages

Practical2.Ipynb - Colab

The document outlines a practical implementation of the FIND-S algorithm using a synthetic dataset related to weather conditions and their corresponding outcomes. It creates a DataFrame, saves it as a CSV file, and then loads it back to extract features and the target variable. The final specific hypothesis derived from the dataset indicates that the conditions leading to a 'Yes' outcome are 'Sunny', 'Warm', 'Normal', 'Strong', 'Warm', and 'Same'.

Uploaded by

Tania Jamdar
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)
3 views2 pages

Practical2.Ipynb - Colab

The document outlines a practical implementation of the FIND-S algorithm using a synthetic dataset related to weather conditions and their corresponding outcomes. It creates a DataFrame, saves it as a CSV file, and then loads it back to extract features and the target variable. The final specific hypothesis derived from the dataset indicates that the conditions leading to a 'Yes' outcome are 'Sunny', 'Warm', 'Normal', 'Strong', 'Warm', and 'Same'.

Uploaded by

Tania Jamdar
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/ 2

11/30/24, 3:54 PM Practical2.

ipynb - Colab

# Import required libraries


import pandas as pd
import numpy as np

# Create a synthetic dataset


data = {
'Sky': ['Sunny', 'Sunny', 'Rainy', 'Sunny', 'Rainy'],
'Temperature': ['Warm', 'Cold', 'Warm', 'Warm', 'Cold'],
'Humidity': ['Normal', 'High', 'High', 'Normal', 'Normal'],
'Wind': ['Strong', 'Strong', 'Weak', 'Strong', 'Weak'],
'Water': ['Warm', 'Warm', 'Cool', 'Warm', 'Cool'],
'Forecast': ['Same', 'Same', 'Change', 'Same', 'Change'],
'Condition': ['Yes', 'No', 'No', 'Yes', 'No'] # Target variable
}
# Convert the dataset to a DataFrame
df = pd.DataFrame(data)
# Save the dataset to a CSV file
df.to_csv('training_data.csv', index=False)
# Display the dataset
print("Dataset:")
print(df)

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

# Load the dataset from CSV


dataset = pd.read_csv('training_data.csv')
# Display the dataset
print("\nLoaded Dataset:")
print(dataset)

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

# Apply the FIND-S algorithm


final_hypothesis = find_s(dataset)
# Display the final specific hypothesis
print("\nFinal Specific Hypothesis:")
print(final_hypothesis)

Final Specific Hypothesis:


['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same']

# Apply the FIND-S algorithm


final_hypothesis = find_s(dataset)
# Display the final specific hypothesis
print("\nFinal Specific Hypothesis:")
print(final_hypothesis)

https://colab.research.google.com/drive/1LUMKY7X7yNAYxxa8FRHNik3CyxcgBwmV#scrollTo=dEAWSwRimbLk&printMode=true 1/2
11/30/24, 3:54 PM Practical2.ipynb - Colab

Final Specific Hypothesis:


['Sunny', 'Warm', 'Normal', 'Strong', 'Warm', 'Same']

https://colab.research.google.com/drive/1LUMKY7X7yNAYxxa8FRHNik3CyxcgBwmV#scrollTo=dEAWSwRimbLk&printMode=true 2/2

You might also like