0% found this document useful (0 votes)
25 views10 pages

Smita ML Labbbb-11-20

The document provides a series of Python code examples for data visualization using Matplotlib, including various types of plots such as scatter plots, bar graphs, histograms, and pie charts. It also includes practical exercises related to data analysis and visualization on a Diwali sales dataset, demonstrating data loading, cleaning, and basic descriptive statistics. The content is structured for a Machine Learning course in a B. Tech program.

Uploaded by

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

Smita ML Labbbb-11-20

The document provides a series of Python code examples for data visualization using Matplotlib, including various types of plots such as scatter plots, bar graphs, histograms, and pie charts. It also includes practical exercises related to data analysis and visualization on a Diwali sales dataset, demonstrating data loading, cleaning, and basic descriptive statistics. The content is structured for a Machine Learning course in a B. Tech program.

Uploaded by

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

COMPUTER SCIENCE AND ENGINEERING

FACULTY OF ENGINEERING AND TECHONLOGY


MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

Output:

 Plotting the points:

Code:
import matplotlib.pyplot as plt
import numpy as np
xpoints = np.array([1, 8])
ypoints = np.array([3, 10])
plt.plot(xpoints, ypoints, 'o')
plt.show()

Output:

 Plot with the Marker:

Code:
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10])
plt.plot(ypoints, marker = 'o')
plt.show()

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

Output:

 Plot with Dotted Line:

Code:
import matplotlib.pyplot as plt
import numpy as np
ypoints = np.array([3, 8, 1, 10])
plt.plot(ypoints, linestyle = 'dotted')
plt.show()

Output:

 Plot with Dashed Line:

Code:
plt.plot(ypoints, ls = '--')

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

Output:

 Plot with Labels:

Code:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
plt.plot(x, y)
plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.show()

Output:

 Plot with Title:

Code:
import numpy as np
import matplotlib.pyplot as plt
x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
plt.plot(x, y)
plt.title("Sports Watch Data")
plt.xlabel("Average Pulse")

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

plt.ylabel("Calorie Burnage")
plt.show()

Output:

 Plot with Grids:

Code:
import matplotlib.pyplot as plt
x = np.array([80, 85, 90, 95, 100, 105, 110, 115, 120, 125])
y = np.array([240, 250, 260, 270, 280, 290, 300, 310, 320, 330])
plt.title("Sports Watch Data")
plt.xlabel("Average Pulse")
plt.ylabel("Calorie Burnage")
plt.plot(x, y)
plt.grid()
plt.show()

Output:

 Multiple Plots:

Code:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([0, 1, 2, 3])
y = np.array([3, 8, 1, 10])

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

plt.subplot(1, 2, 1)
plt.plot(x,y)
x = np.array([0, 1, 2, 3])
y = np.array([10, 20, 30, 40])
plt.subplot(1, 2, 2)
plt.plot(x,y)
plt.show()

Output:

 Scattered Plot:

Code:
import matplotlib.pyplot as plt
import numpy as np
x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y)
plt.show()

Output:

 Multiple scattered Plot:

Code:
import matplotlib.pyplot as plt
import numpy as np

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

x = np.array([5,7,8,7,2,17,2,9,4,11,12,9,6])
y = np.array([99,86,87,88,111,86,103,87,94,78,77,85,86])
plt.scatter(x, y)
x = np.array([2,2,8,1,15,8,12,9,7,3,11,4,7,14,12])
y = np.array([100,105,84,105,90,99,90,95,94,100,79,112,91,80,85])
plt.scatter(x, y)
plt.show()

Output:

 Bar-Graph:

Code:
import matplotlib.pyplot as plt
import numpy as np
x = np.array(["A", "B", "C", "D"])
y = np.array([3, 8, 1, 10])
plt.bar(x,y)
plt.show()

Output:

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

 Histogram:

Code:
import matplotlib.pyplot as plt
import numpy as np
x = np.random.normal(170, 10, 250)
plt.hist(x)
plt.show()

Output:

 Pie Chart:

Code:
import matplotlib.pyplot as plt
import numpy as np
y = np.array([35, 25, 25, 15])
mylabels = ["Apples", "Bananas", "Cherries", "Dates"]
plt.pie(y, labels = mylabels)
plt.show()

Output:

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

Practical - 02
Aim: - Data Analysis & Visualization on Diwali Sales Dataset.

// Importing python libraries


from google.colab import drive
drive.mount(‘/content/drive’)

Output:
Mounted at /content/drive

//Importing csv file


df=pd.read_csv(r'/content/drive/MyDrive/Diwali Sales Data.csv' ,encoding= 'unicode_escape')

Code:
df.shape()

Output:
(11251,15)

Code:
df.head()

Output:

Code:
df.tail()

Output:

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

Code:
df.info()

Output:

Code:
df.drop(['Status', 'unnamed1'], axis=1,
inplace=True) pd.isnull(df).sum()

Output:

Code:

Page |
COMPUTER SCIENCE AND ENGINEERING
FACULTY OF ENGINEERING AND TECHONLOGY
MACHINE LEARNING (303105354) B. TECH 3RD YEAR
ENROLLMENT NO: - 2203031241233

df.dropna(inplace=True)
df['Amount'] = df['Amount'].astype('int')
df['Amount'].dtypes

Output:
Dtype(‘int64’)

Code:
df.columns()

Output:
Index(['User_ID', 'Cust_name', 'Product_ID', 'Gender', 'Age Group', 'Age',
'Marital_Status', 'State', 'Zone', 'Occupation', 'Product_Category','Orders',
'Amount'],
dtype='object')

Code:
df.rename(columns= {'Marital_Status':'Married'})

Output:

Code:
df.describe()

Output:

Code:

Page |

You might also like