Notes 1
Notes 1
known like mean, median, mode, standard deviation, mean deviation, variance, percentile,
correlation, bar chart, histogram plot, pie chart, scatter plot etc. based on which analysis can be
given. The tools are described below.
∑𝑛
𝑖=1 𝑥𝑖
Calculation of Mean: For some numbers 𝑥𝑖 , 𝑖 ∈ [1, 𝑛], 𝑚𝑒𝑎𝑛 = 𝑛
Calculation of Mean with frequencies: For some numbers 𝑥𝑖 , 𝑖 ∈ [1, 𝑛], with frequencies 𝑓𝑖 , 𝑚𝑒𝑎𝑛 =
∑𝑛
𝑖=1 𝑓𝑖 𝑥𝑖
∑𝑛
𝑖=1 𝑓𝑖
Calculation of mean with some approximate mean: For some numbers 𝑥𝑖 , 𝑖 ∈ [1, 𝑛], with frequencies
𝑓𝑖 , if the approximate mean is known (say A), then 𝑥𝑖 = 𝐴 + 𝑑𝑖 where 𝑑𝑖 is the difference of A from 𝑥𝑖 ,
∑𝑛
𝑖=1 𝑓𝑖 𝑥𝑖 ∑𝑛
𝑖=1 𝑓𝑖 (𝐴+𝑑𝑖 ) ∑𝑛 𝑛
𝑖=1 𝑓𝑖 𝐴+∑𝑖=1 𝑓𝑖 𝑑𝑖 ∑𝑛
𝑖=1 𝑓𝑖 𝑑𝑖
then 𝑚𝑒𝑎𝑛 = ∑𝑛
= ∑𝑛
= ∑𝑛
=𝐴+ ∑𝑛
𝑖=1 𝑓𝑖 𝑖=1 𝑓𝑖 𝑖=1 𝑓𝑖 𝑖=1 𝑓𝑖
Calculation of median: For some numbers 𝑥𝑖 , 𝑖 ∈ [1, 𝑛], at first we need to check whether n is even of
𝑥𝑛 +𝑥𝑛
+1
2 2
odd. If n is even then 𝑚𝑒𝑑𝑖𝑎𝑛 = . If n is odd then 𝑚𝑒𝑑𝑖𝑎𝑛 = 𝑥𝑛+1 .
2 2
Calculation of Mode: For some numbers 𝑥𝑖 , 𝑖 ∈ [1, 𝑛], the mode is the number which is repeated
maximum times in the sequence of 𝑥𝑖 .
Simple program for Mean calculation (with frequency greater than 1):
Simple program for Mean calculation (Using Numpy library):
∑𝑛
𝑖=1 𝑥𝑖
Calculation of Standard Deviation: For some numbers 𝑥𝑖 , 𝑖 ∈ [1, 𝑛], 𝑚𝑒𝑎𝑛 = . Standard
𝑛
∑𝑛
𝑖=1(𝑥𝑖 −𝑚𝑒𝑎𝑛)
2
Deviation, 𝑠𝑡𝑑 = √ .
𝑛
∑𝑛
𝑖=1 𝑥𝑖
Calculation of Variance: For some numbers 𝑥𝑖 , 𝑖 ∈ [1, 𝑛], 𝑚𝑒𝑎𝑛 = . variance, 𝑣𝑎𝑟 =
𝑛
∑𝑛
𝑖=1(𝑥𝑖 −𝑚𝑒𝑎𝑛)
2
.
𝑛
Data Distribution: Consider a dataset which has random numbers between 0 and 10. Now we need to
segregate the number of numbers between 0 and 1, 1 and 2, 2 and 3 and so on. Here histogram plot can be
done to do so and this is called data analysis.
Simple Program for data distribution and plotting using Numpy and Matplotlib libraries: Here 10000
numbers have been generated between 0 to 10 and 50 plots have been shown.
Simple Program for normal or Gaussian distribution and plotting using Numpy and Matplotlib
libraries: Here 10000 numbers have been generated 10 with a scale of 1 and 50 plots have been shown.
Pie Chart for Data Analysis: Consider a banking feedback system where 4 comments are there:
“Excellent”,”Good”,”Fair”,”Bad”. Suppose total 120 people have given the feedback whose data is given
below.
Scatter Plot for Data Analysis: Consider the equipments of an industry whose efficiency in terms of speed
changes with the ages.
Ages 1 2 3 4 5 6 7 8
Efficiency (in 96 93 90 85 80 75 71 65
terms of
RPM)
Now using these two parameters scatter plot can be designed for analysis.
Linear Regression using Scipy and Matplotlib Library: Consider car speed with respect to the ages.
Ages 5 7 8 7 2 17 2 9 4 11 12 9 6
Car Speed 99 86 87 88 111 86 103 87 94 78 77 85 86
From this data we need to predict the other car speed whose age is given but speed is unknown.
Here “r” is the correlation value. Now the year of an unknown car is given in the “line_graph()” function
then the predicted speed can be calculated.
Polynomial Regression:
Correlation: If x and y are two variables then the correlation between them can be given by the formula
shown below.
Reading CSV files using Python: Here there is a database of many cars whose model, weight, volume and
CO2 consumption are present. From these data, some prediction analysis will be done.
CSV File:
Reading CSV file:
Now if a car has some weight and volume then some analysis should be done regarding its consumption to
CO2. Therefore the following code is written to get the data about the cars’ weight and volume.
Multiple Linear Regression: The following piece of codes using the independent parameters “Weight”
and “Volume” and dependent parameter “CO2” will create a prediction model.
Now if a car has weight 1700 unit and volume 2500 unit, then its CO2 consumption can be predicted from
the model.
Description of Sensors and Actuators
IR Sensor (Infrared Proximity Sensor):
TinkerCAD circuit for IR sensor internal circuit (Video Link: video link)
Ultrasonic Sensor:
Calculation of distance: From Trigger pin ultrasound is produced and it returns to Echo pin after
being reflected from the object. First of all, the overall time of traverse is calculated (using pulseIn
𝑣𝑠 ×𝑡
function). Thus the distance 𝑑 = where 𝑣𝑠 =velocity of sound (343 m/sec), 𝑡=total time
2
traversed and since the sound traverse the distance twice therefore divide by 2 operation is
performed.
Ultrasonic Sensor interfacing with arduino (Video Link: Ultrasonic Sensor Arduino interfacing)