Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd # Import pandas for data manipulation
- # Load the dataset
- data = pd.read_csv("P2Data.csv") # Load CSV file into a DataFrame
- print(data) # Print the dataset to understand its structure
- # Extract attributes and target
- attributes = data.iloc[:, :-1].values # Extract all columns except
- the last (features)
- print("The attributes are:", attributes) # Print the attributes
- target = data.iloc[:, -1].values # Extract the last column (target
- labels)
- print("The target is:", target) # Print the target
- # Define the Find-S algorithm
- def find_s(attributes, target):
- for i, value in enumerate(target): # Look for the first positive
- example
- if value == "Yes":
- hypothesis = attributes[i].copy() # Initialize the
- hypothesis
- break
- for i, value in enumerate(target): # Iterate through all examples
- if value == "Yes": # Consider only positive examples
- for j in range(len(hypothesis)): # Iterate through
- attributes
- if attributes[i][j]!= hypothesis[j]: # If attributes
- differ
- hypothesis[j] = '?' # Generalize to '?'
- return hypothesis # Return the final hypothesis
- # Find and print the final hypothesis
- final_hypothesis = find_s(attributes, target)
- print("The final hypothesis is:", final_hypothesis)
Advertisement
Add Comment
Please, Sign In to add comment