DEPARTMENT OF
Experiment1.4
Student Name: Abhishek UID: 21BCS3967
Branch: CSE Section/Group: IOT_644-B
Semester: 5th Date of Performance: 19/09/23
Subject Name: AIML-Lab Subject Code: 21CSH-316
1. Aim: Implementation of Python Libraries for ML application such as Pandas
and Matplotlib.
2. Objective: The objective of this experiment is to demonstrate the implementation of
Python libraries for machine learning applications, specifically Pandas and Matplotlib.
3. Algorithm/Procedure:
The procedure for implementing the algorithm can be outlined as follows:
1. Import the required libraries.
2. Load the dataset into a pandas dataframe.
3. Handle missing data.
4. Perform exploratory data analysis.
5. Apply machine learning algorithms.
4. Code:
import pandas as pd
import matplotlib.pyplot as plt
DEPARTMENT OF
import numpy as np
# Creating the data table using Pandas
data = {
"country": ["Brazil", "Russia", "India", "China", "South Africa"],
"capital": ["Brasilia", "Moscow", "New Delhi", "Beijing", "Pretoria"],
"area": [8.516, 17.10, 3.286, 9.597, 1.221],
"population": [200.4, 143.5, 1252, 1357, 52.98]
}
data_table = pd.DataFrame(data)
print("----Sparsh Gupta 21BCS4907----")
print("Data Table:")
print(data_table)
# Creating a linear plot using Matplotlib
x = np.linspace(0, 10, 100)
plt.plot(x, x, label='linear')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.title('Linear Plot')
plt.legend()
plt.show()
Ploting PIE CHART
# Import libraries
from matplotlib import pyplot as plt
import numpy as np
# Creating dataset
cars = ['AUDI', 'BMW', 'FORD',
DEPARTMENT OF
'TESLA', 'JAGUAR', 'MERCEDES']
data = [27, 10, 40, 20, 7, 50]
# Creating plot
fig = plt.figure(figsize =(6, 7))
plt.pie(data, labels = cars)
# show plot
plt.show()
HISTOGRAM
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors
from matplotlib.ticker import PercentFormatter
# Creating dataset
np.random.seed(23685752)
N_points = 10000
n_bins = 20
# Creating distribution
x = np.random.randn(N_points)
y = .8 ** x + np.random.randn(10000) + 25
# Creating histogram
fig, axs = plt.subplots(1, 1,
figsize =(10, 5),
tight_layout =
True)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
axs.hist(x, bins = n_bins)
# Show plot
plt.show()
5. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
Learning Outcomes:
The observations and outcomes of the experiment will include:
• We Learned to use pandas.
• We Learned to plot pie chart.
• We Learned to plot histogram.
• We Learned to create distribution for histogram.