Vikhyath_11

a2

Dec 12th, 2024
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. import pandas as pd # Import pandas for data manipulation
  2. # Load the dataset
  3. data = pd.read_csv("P2Data.csv") # Load CSV file into a DataFrame
  4. print(data) # Print the dataset to understand its structure
  5. # Extract attributes and target
  6. attributes = data.iloc[:, :-1].values # Extract all columns except
  7. the last (features)
  8. print("The attributes are:", attributes) # Print the attributes
  9. target = data.iloc[:, -1].values # Extract the last column (target
  10. labels)
  11. print("The target is:", target) # Print the target
  12. # Define the Find-S algorithm
  13. def find_s(attributes, target):
  14. for i, value in enumerate(target): # Look for the first positive
  15. example
  16. if value == "Yes":
  17. hypothesis = attributes[i].copy() # Initialize the
  18. hypothesis
  19. break
  20. for i, value in enumerate(target): # Iterate through all examples
  21. if value == "Yes": # Consider only positive examples
  22. for j in range(len(hypothesis)): # Iterate through
  23. attributes
  24. if attributes[i][j]!= hypothesis[j]: # If attributes
  25. differ
  26. hypothesis[j] = '?' # Generalize to '?'
  27.  
  28. return hypothesis # Return the final hypothesis
  29. # Find and print the final hypothesis
  30. final_hypothesis = find_s(attributes, target)
  31. print("The final hypothesis is:", final_hypothesis)
Advertisement
Add Comment
Please, Sign In to add comment