DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
EXPERIMENT: 3.1
Student Name: VASU UID: 21BCS1452
Branch: CSE Section/Group: 617/A
Semester: 5th Date of Performance: 27/10/2023
Subject Name: ARTIFICIAL INTELLIGENCE Subject Code: 21CSH-316
& MACHINE LEARNING WITH LAB
Aim: Write a python program to compute Mean, Median, Mode, Variance and Standard
Deviation using Datasets.
Objective: The objective of this experiment is to analyse the given dataset.
Theory:
Mean: The average of a set of numbers calculated by adding them together and dividing by
the count of numbers.
Median: The middle value in a set of data when arranged in ascending order, or the average
of the two middle values for an even number of elements.
Mode: The value that appears most frequently in a set of data.
Variance: A measure of the spread or dispersion of values in a dataset around the mean.
Standard Deviation: A measure of the amount of variation or dispersion of a set of values
from the mean.
Algorithm:
1. Import the required libraries.
2. Load the iris dataset.
3. Calculate the mean, median, mode, variance and standard deviation.
4. Display the results.
Code:
import pandas as pd
import numpy as np
from scipy import stats
# Load the Iris dataset
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
column_names = ["sepal_length", "sepal_width", "petal_length", "petal_width", "class"]
iris_data = pd.read_csv(url, names=column_names)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
# Calculate the mean for each feature
mean_values = iris_data.mean()
# Calculate the median for each feature
median_values = iris_data.median()
# Calculate the mode for each feature
mode_values = iris_data.mode().iloc[0] # Use the first mode in case of multiple modes
# Calculate the variance for each feature
variance_values = iris_data.var()
# Calculate the standard deviation for each feature
std_deviation_values = iris_data.std()
# Display the results
print("Mean:")
print(mean_values)
print("\nMedian:")
print(median_values)
print("\nMode:")
print(mode_values)
print("\nVariance:")
print(variance_values)
print("\nStandard Deviation:")
print(std_deviation_values)
Observation and outcomes:
1. I learned about how to load an iris dataset.
2. I learned about how to calculate mean, median, mode, variance and standard deviation.
3. I learned about how to display these values.