0% found this document useful (0 votes)
51 views1 page

ML Experiment - 1

The document outlines a Python program designed to compute central tendency measures including mean, median, mode, variance, and standard deviation. It provides a step-by-step procedure and includes example code that processes a sample dataset. The output displays the calculated values for the dataset, demonstrating the program's functionality.

Uploaded by

s.dineshwar1231
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views1 page

ML Experiment - 1

The document outlines a Python program designed to compute central tendency measures including mean, median, mode, variance, and standard deviation. It provides a step-by-step procedure and includes example code that processes a sample dataset. The output displays the calculated values for the dataset, demonstrating the program's functionality.

Uploaded by

s.dineshwar1231
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1.

Write a python program to compute Central Tendency Measures: Mean, Median,

AIM: a python program to compute Central Tendency Measures: Mean, Median

PROCEDURE: to compute central tendency measures mean median mode measure of dispersion variance, standard deviation

PROGRAM:

import statistics
def calculate_mean(data):
return sum(data) / len(data)
def calculate_median(data):
sorted_data = sorted(data)
n = len(sorted_data)
if n % 2 == 0:
middle1 = sorted_data[n // 2 - 1]
middle2 = sorted_data[n // 2]
return (middle1 + middle2) / 2
else:
return sorted_data[n // 2]
def calculate_mode(data):
return statistics.mode(data)
def calculate_variance(data):
mean_value = calculate_mean(data)
squared_diff_sum = sum((x - mean_value) ** 2 for x in data)
return squared_diff_sum / (len(data) - 1)
def calculate_standard_deviation(data):
variance_value = calculate_variance(data)
return variance_value ** 0.5
# Example dataset
dataset = [10, 20, 30, 40, 50]
mean_value = calculate_mean(dataset)
median_value = calculate_median(dataset)
mode_value = calculate_mode(dataset)
variance_value = calculate_variance(dataset)
std_deviation_value = calculate_standard_deviation(dataset)
print(f"Dataset: {dataset}")
print(f"Mean: {mean_value:.2f}")
print(f"Median: {median_value:.2f}")
print(f"Mode: {mode_value}")
print(f"Variance: {variance_value:.2f}")
print(f"Standard Deviation: {std_deviation_value:.2f}")
output : Dataset: [10, 20, 30, 40, 50]
Mean: 30.00
Median: 30.00
Mode: 10
Variance: 250.00
Standard Deviation: 15.81
OUTPUT:
Dataset: [10, 20, 30, 40, 50]
Mean: 30.00 Median: 30.00
Mode: 10
Variance: 250.00
Standard Deviation: 15.81

RESULT: calculating the values of mean mode and variance and standard deviation for sample data set

You might also like