- Machine Learning for Developers
- Rodolfo Bonnin
- 255字
- 2021-07-02 15:46:46
Mean
This is one of the most intuitive and most frequently used concepts in statistics. Given a set of numbers, the mean of that set is the sum of all the elements divided by the number of elements in the set.
The formula that represents the mean is as follows:

Although this is a very simple concept, we will write a Python code sample in which we will create a sample set, represent it as a line plot, and mark the mean of the whole set as a line, which should be at the weighted center of the samples. It will serve as an introduction to Python syntax, and also as a way of experimenting with Jupyter notebooks:
import matplotlib.pyplot as plt #Import the plot library
def mean(sampleset): #Definition header for the mean function
total=0
for element in sampleset:
total=total+element
return total/len(sampleset)
myset=[2.,10.,3.,6.,4.,6.,10.] #We create the data set
mymean=mean(myset) #Call the mean funcion
plt.plot(myset) #Plot the dataset
plt.plot([mymean] * 7) #Plot a line of 7 points located on the mean
This program will output a time series of the dataset elements, and will then draw a line at the mean height.
As the following graph shows, the mean is a succinct (one value) way of describing the tendency of a sample set:

In this first example, we worked with a very homogeneous sample set, so the mean is very informative regarding its values. But let's try the same sample with a very dispersed sample set (you are encouraged to play with the values too):

- Vue.js設(shè)計(jì)與實(shí)現(xiàn)
- FuelPHP Application Development Blueprints
- Java范例大全
- Learn to Create WordPress Themes by Building 5 Projects
- PHP程序設(shè)計(jì)(慕課版)
- 新編Premiere Pro CC從入門到精通
- Python Network Programming Cookbook(Second Edition)
- Serverless架構(gòu)
- Getting Started with Gulp
- 機(jī)器學(xué)習(xí)與R語(yǔ)言實(shí)戰(zhàn)
- 深入分布式緩存:從原理到實(shí)踐
- Android系統(tǒng)級(jí)深入開(kāi)發(fā)
- Android玩家必備
- Python Data Science Cookbook
- 鴻蒙OS應(yīng)用編程實(shí)戰(zhàn)