0% found this document useful (0 votes)
5 views4 pages

22011P0515 ML Assignment

The document contains three separate programs: one for statistical computations (mean, median, mode), another for reading a CSV file containing sports data, and a third for implementing the Find-S algorithm to derive a hypothesis from given data. Each program includes the necessary code and sample data for execution. The output of each program is printed to the console.

Uploaded by

NIHAL 2360
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)
5 views4 pages

22011P0515 ML Assignment

The document contains three separate programs: one for statistical computations (mean, median, mode), another for reading a CSV file containing sports data, and a third for implementing the Find-S algorithm to derive a hypothesis from given data. Each program includes the necessary code and sample data for execution. The output of each program is printed to the console.

Uploaded by

NIHAL 2360
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/ 4

1) Program to implement Statistical

Computations
def calculate_mean(data):
return sum(data) / len(data)

def calculate_median(data):
sorted_data = sorted(data)
n = len(sorted_data)
mid = n // 2
if n % 2 == 0:
return (sorted_data[mid - 1] + sorted_data[mid]) / 2
else:
return sorted_data[mid]

def calculate_mode(data):
frequency = {}
for value in data:
frequency[value] = frequency.get(value, 0) + 1
max_freq = max(frequency.values())
modes = [key for key, value in frequency.items() if value == max_freq]
return modes

data = [10, 20, 20, 30, 40, 50, 50, 50]

mean = calculate_mean(data)
median = calculate_median(data)
mode = calculate_mode(data)

print(f"Mean: {mean}")
print(f"Median: {median}")
print(f"Mode: {mode}")
Output:

2) Read CSV file of enjoy sport data

import pandas as pd

df = pd.read_csv('enjoy_sport.csv')
print(df)

Sample CSV File: enjoy_sport.csv


Output:

3) Program to implement find s algorithm

def find_s(data):
hypothesis = data[0][:-1]
for instance in data:
if instance[-1] == 'Yes':
for i in range(len(hypothesis)):
if hypothesis[i] != instance[i]:
hypothesis[i] = '?'
return hypothesis

data = [
['Sunny', 'Warm', 'Normal', 'Strong', 'Yes'],
['Sunny', 'Warm', 'High', 'Strong', 'Yes'],
['Rainy', 'Cold', 'High', 'Strong', 'No'],
['Sunny', 'Warm', 'High', 'Weak', 'Yes'],
]

result = find_s(data)
print("Final Hypothesis:", result)

Output:

You might also like