Matplot Lib Practicals artificial intelligence.pptx

PianoPianist 43 views 24 slides Apr 29, 2025
Slide 1
Slide 1 of 24
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24

About This Presentation

cbse ai practical


Slide Content

Python Programming Statistical Learning with Python

Mean – Mean is the average of the given numbers and is calculated by dividing the sum of given numbers by the total number of numbers. Mean = (Sum of all the observations/Total number of observations) Median – Median is defined as the middle value in a given set of numbers or data Median is defined as the middle value in a given set of numbers or data Median = [(n/2) th term + {(n/2)+1} th term]/2 Standard Deviation – Standard Deviation is a measure which shows how much variation (such as spread, dispersion, spread,) from the mean exists. The standard deviation indicates a “typical” deviation from the mean. Variance-Variance is the measure of how notably a collection of data is spread out. If all the data values are identical, then it indicates the variance is zero.

import statistics marks = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ] m= statistics.mean (marks) me= statistics.median (marks) sd = statistics.stdev (marks) v= statistics.variance (marks) print ( round (m, 2 )) print ( round (me, 2 )) print ( round (sd, 2 )) print ( round (v, 2 ))

Matplot Lib Data Visualisation in Python

Matplotlib is a powerful plotting library in Python used for creating static, animated, and interactive visualizations. Matplotlib’s primary purpose is to provide users with the tools and functionality to represent data graphically, making it easier to analyze and understand. It was originally developed by John D. Hunter in 2003 and is now maintained by a large community of developers. Key Features of Matplotlib: Versatility : Matplotlib can generate a wide range of plots, including line plots, scatter plots, bar plots, histograms, pie charts, and more. Customization : It offers extensive customization options to control every aspect of the plot, such as line styles, colors, markers, labels, and annotations. Integration with NumPy : Matplotlib integrates seamlessly with NumPy, making it easy to plot data arrays directly. Publication Quality : Matplotlib produces high-quality plots suitable for publication with fine-grained control over the plot aesthetics. Extensible : Matplotlib is highly extensible, with a large ecosystem of add-on toolkits and extensions like Seaborn, Pandas plotting functions, and Basemap for geographical plotting. Cross-Platform : It is platform-independent and can run on various operating systems, including Windows, macOS, and Linux. Interactive Plots : Matplotlib supports interactive plotting through the use of widgets and event handling, enabling users to explore data dynamically. 5

Bar Charts A bar chart that presents categorical data with rectangular bars with heights or lengths proportional to the values that they represent. The bars can be plotted vertically or horizontally.

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

#Bar Plot import matplotlib.pyplot as plt import numpy as np x = np.array ([ "A" , "B" , "C" , "D" ]) y = np.array ([ 3 , 8 , 1 , 10 ]) plt.title ( "Bar Plot" ) plt.xlabel ( "Bar Number" ) plt.ylabel ( "Bar Height" ) plt.bar ( x,y ) plt.show ()

#Bar Plot import matplotlib.pyplot as plt import numpy as np x = np.array ([ "A" , "B" , "C" , "D" ]) y = np.array ([ 3 , 8 , 1 , 10 ]) c=[ " r" , "y" , "g" , "b " ] plt.title ( "Bar Plot" ) plt.xlabel ( "Bar Number" ) plt.ylabel ( "Bar Height" ) plt.bar ( x,y,width = 0.5 ,color= c,label = " mygraph " ) #plt.legend() plt.show ()

Scatter Plots A scatter plot  is a type of plot or mathematical diagram using Cartesian coordinates (X-axis & Y-axis) to display values for typically two variables for a set of data.

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 () plt.scatter (x, y, color =  ’red' )

Pie - Charts A pie chart is a type of graph that represents the data in the circular graph . The slices of pie show the relative size of the data. It is a type of  pictorial representation of data.

import   matplotlib.pyplot   as   plt import   numpy   as  np y = np.array ([ 35 ,  25 ,  25 ,  15 ]) mylabels = [ " Laptops" ,  "Desktops" ,  " palmtop " ,  "Dates" ] plt.pie ( y,labels = mylabels ) plt.show () 

Histograms A histogram is a graphical display of data using bars of different heights . In a histogram, each bar groups numbers into ranges. A histogram displays the shape of a data.

#Histogram import matplotlib.pyplot as plt import numpy as np x= np.random.randint ( 10 , 50 ,( 50 )) print (x) plt.hist (x) Plt.title (my graph”) plt.show ()

Line Graphs A line graph is a type of chart used to show information that changes over time . We plot line graphs using several points connected by straight lines. The line graph comprises of two axes known as 'x' axis and 'y' axis.  

# importing the required module import matplotlib.pyplot as plt # x axis values x = [ 1 , 2 , 3 ] # corresponding y axis values y = [ 4 , 5 , 1 ] # plotting the points plt.plot (x, y) # naming the x axis plt.xlabel ( 'x - axis' ) # naming the y axis plt.ylabel ( 'y - axis' ) # giving a title to my graph plt.title ( 'My first graph!' ) # function to show the plot plt.show ()

Box plot (Whisker Plot) A box and whisker plot—also called a box plot—displays the five-number summary of a set of data. The five-number summary is the minimum, first quartile, median, third quartile, and maximum.

#boxplot import matplotlib.pyplot as plt import numpy as np x = [ 10 , 20 , 30 , 40 , 50 ] plt.boxplot (x) plt.show ()
Tags