Rudra Aiml 1.4

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1.4
Student Name:Rudra Shakti Kar UID: 21BCS7176
Branch: CSE Section/Group: IOT_633A
Semester: 5th Date of Performance: 12/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.

A. Pandas

1. Algorithm:

1. Import the pandas library as pd.


2. Create a DataFrame named data with the following columns:
3. Print the entire data DataFrame to the console.
4. Create a new DataFrame named data_row by selecting rows from data where the values in the "x2"
column are less than 20.
5. Print the data_row DataFrame to the console.
6. Create a new DataFrame named data_col by dropping the "x1" column from the data DataFrame along
the columns axis (axis=1).
7. Print the data_col DataFrame to the console.
8. Calculate the median of the "x5" column in the data DataFrame and store it in a variable named
data_med.
9. Print the value of data_med to the console.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

2. Source Code:
a)
import pandas as pd
import numpy as np
info = np.array(['R’,’U’,’D’,’R’,’A’])
a = pd.Series(info)
print(a)

b)
import pandas as pd
x = ['RUDRA','21BCS7176','633 A']
df = pd.DataFrame(x)
print(df)

3. Output:
a) b)
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
B. Matplotlibs

1. Algoritm:
1. Import the matplotlib.pyplot module as plot.
2. Import the numpy module as nup.
3. Create a numpy array k using the linspace function, ranging from 1 to 3 (inclusive), with 2
evenly spaced values.
4. Create a numpy array r using the linspace function, ranging from 2 to 1 (inclusive), with 3
evenly spaced values.
5. Create a numpy array q using the linspace function, ranging from 3 to 2 (inclusive), with 1
evenly spaced value.
6. Use the plot.plot() function to plot the arrays k, r, and q. Each array is plotted against itself,
and a label is assigned for each plot: "k" for k, "r" for r, and "q" for q.
7. Add a legend to the plot using plot.legend() to display labels for each plotted line.
8. Display the plot using plot.show().

2. Source Code:
a)
import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([0, 7])
ypoints = np.array([0, 260])
plt.plot(xpoints, ypoints)
plt.show()
b)
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10])
plt.title("21BCS7176")
plt.plot(ypoints, marker = 'o')
plt.show()
c)
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10])
plt.plot(ypoints, linestyle = 'dotted')
plt.show()
DEPARTMENT OF
COMPUTER
d)
SCIENCE & ENGINEERING
import matplotlib.pyplot as plt
import numpy as np
y = np.array([35, 25, 25, 15])
plt.title("UID:21BCS7176")
plt.pie(y)
plt.show()

3. Output:
a) b)

c) d)

4. Learning Outcomes:
Understanding of creating and manipulating Data Frames in pandas.
Knowledge of adding columns with different data types to a Data Frame.
Proficiency in creating and customizing plots using Matplotlib.

You might also like