Page 203 - Robotics and AI class 10
P. 203
● Variance
It means how far each number in the given dataset is from the mean value. It is calculated as the average of the
squares of the differences between an individual value and the expected value or average squared deviation of
each number from the mean of a given data set.
The formula for calculation:
2 ∑ ( x - µ) 2
σ
variance = = r
n
To calculate Variance in Python:
import statistics
marks=[45,34,41,46,47,39,38,48,45,34,41,39,39]
m=statistics.variance(marks)
print("the variance of marks :",round(m,2))
Output:
the variance of marks : 21.69
Matplotlib
Matplotlib was created by John D. Hunter in 2003. It is a free and open source, data visualisation library used for
plotting graphs and visualisation in Python built on NumPy arrays and can be downloaded from https://www.
matplotlib.org. Using Matplotlib, with just a few lines of code we can generate graphs of any kind like plots,
histograms, bar charts, scatterplots, etc.
It comes with a wide variety of plots but the most used module of Matplotib is Pyplot which is used for creating
2D plots of arrays.
Visuals have more impact on human brains. So these plots created using Matplotlib help us understand the trends,
patterns, correlations of the data. They give us the quantitative information of data in a visual form. After the plots
are created, you can change the style, look and make them more descriptive and communicable.
Some types of graphs that we can make with this package are listed below:
Bar Graph Histogram Scatter Plot Area Plot Pie Plot
Installing Matplotlib
• To install it using pip:
python -m pip install -U pip
python -m pip install -U matplotlib
Or
pip install matplotlib
• To install using Anaconda
conda install matplotlib
Or
conda install -c conda-forge matplotlib
For plotting using Matplotlib, we need to import its Pyplot module as follows:
import matplotlib.pyplot as plt
Introduction to Data and Programming with Python 201

