0% found this document useful (0 votes)
8 views

Machine Learning

The document provides a step-by-step guide to install Python and the numpy library, create a folder and a Python file, and run a statistical program. The program demonstrates basic statistical measures such as mean, median, mode, variance, standard deviation, range, interquartile range, and percentiles using sample datasets. Users are instructed to use specific commands for Windows and Linux environments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Machine Learning

The document provides a step-by-step guide to install Python and the numpy library, create a folder and a Python file, and run a statistical program. The program demonstrates basic statistical measures such as mean, median, mode, variance, standard deviation, range, interquartile range, and percentiles using sample datasets. Users are instructed to use specific commands for Windows and Linux environments.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

Install Python from here https://www.python.org/ftp/python/3.8.10/python-3.8.10-amd64.

exe
Open command prompt
Install numpy by typing “pip install numpy”
Create a folder named as “pyeg” using command
For Windows type: “md pyeg”
For Linux type: “mkdir pyeg”
Create a file named as “eg1.py” using below command
For Windows type: “notepad eg1.py”
For Linux type: “gedit eg1.py” or “nano eg1.py” or “vim eg1.py”
Type the below program, save it and run using “python eg1.py” or “py eg1.py”
Program:

# Import necessary modules


import statistics # For basic statistical calculations
import numpy as np # For advanced calculations like percentiles and IQR

# ----- Basic Statistical Measures -----


print("--------------------------------------------------")

# Mean (Average)
data = [12, 15, 18, 20, 22] # Sample dataset
mean_value = statistics.mean(data) # Calculate mean
print("Mean:", mean_value) # Output the result
print("--------------------------------------------------")

# Median (Middle Value)


data = [10, 15, 20, 25, 30] # Sample dataset
median_value = statistics.median(data) # Calculate median
print("Median:", median_value) # Output the result
print("--------------------------------------------------")

# Mode (Most Frequent Value)


data = [10, 15, 20, 15, 25, 30, 15] # Sample dataset with repeated values
mode_value = statistics.mode(data) # Calculate mode
print("Mode:", mode_value) # Output the result
print("--------------------------------------------------")

# Variance (Spread of Data Around the Mean)


data = [5, 8, 10, 12, 15] # Sample dataset
variance_value = statistics.variance(data) # Calculate variance
print("Variance:", variance_value) # Output the result
print("--------------------------------------------------")

# Standard Deviation (Average Deviation from Mean)


data = [5, 8, 10, 12, 15] # Sample dataset
std_deviation_value = statistics.stdev(data) # Calculate standard deviation
print("Standard Deviation:", std_deviation_value) # Output the result
print("--------------------------------------------------")

# ----- Measures of Distribution -----

# Range (Difference Between Max and Min)


data = [15, 20, 12, 25, 30] # Sample dataset
data_range = max(data) - min(data) # Calculate range
print("Range:", data_range) # Output the result
print("--------------------------------------------------")

# Interquartile Range (Middle 50% Spread of Data)


data = [10, 15, 20, 25, 30, 35, 40] # Sample dataset
q1 = np.quantile(data, 0.25) # First quartile (25th percentile)
q3 = np.quantile(data, 0.75) # Third quartile (75th percentile)
iqr = q3 - q1 # Calculate interquartile range
print("Interquartile Range (IQR):", iqr) # Output the result
print("--------------------------------------------------")

# Percentiles (Dividing Data into Portions)


data = [5, 10, 15, 20, 25, 30, 35, 40] # Sample dataset
percentile_25 = np.percentile(data, 25) # 25th percentile
percentile_75 = np.percentile(data, 75) # 75th percentile
print("25th Percentile:", percentile_25) # Output the result
print("75th Percentile:", percentile_75) # Output the result
print("--------------------------------------------------")
Output:

You might also like