Вы находитесь на странице: 1из 6

import numpy as np

from scipy import stats


import matplotlib.pyplot as plt

speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]

x = np.mean(speed)

print(x)

89.76923076923077

x = np.median(speed)
x

87.0

x = stats.mode(speed)
x

ModeResult(mode=86, count=3)

x = np.std(speed)
x

9.258292301032677

ages = [5,31,43,48,50,41,7,11,15,39,80,82,32,2,8,6,25,36,27,61,31]

x = np.percentile(ages, 75)

print(x)

43.0

x = np.random.uniform(0.0, 5.0, 250)


print(x)
plt.hist(x, 5)
plt.show()

[2.41372569 0.93263825 2.6786071 2.5805323 1.75751235 2.54662165


3.65867239 1.10061694 2.7134957 4.37309419 1.51495284 1.14094133
1.40445293 0.54039979 3.01669142 0.99436013 0.06915335 4.72452733
3.65844867 3.42829244 4.45990467 0.01829921 4.3778951 3.84036514
0.52355692 2.3827785 3.54762636 2.01906361 0.66449167 2.49118749
2.2701849 3.52716075 3.85269889 4.29577021 0.81061894 1.8008877
1.47174675 3.35639003 0.19575772 3.33652964 0.20808369 4.31788341
3.78788698 4.58830107 1.04082284 3.65197976 0.40101822 4.34493194
2.38312792 0.82021805 1.16828038 3.88033486 1.64570231 3.23665013
3.48653421 2.17413673 2.44471954 3.96430542 2.52701541 3.98578534
4.35594063 2.63623638 2.25401971 0.41011012 4.62507417 0.92073534
2.20737541 4.59030302 3.24357502 0.04255261 4.99308442 4.35003355
0.72611804 1.01850826 4.12984372 2.87511815 3.40188063 1.0176177
2.15954722 0.49392982 0.19430455 3.47630355 1.20413469 0.21354493
1.54964756 0.60457384 4.46710566 3.64120885 3.17722862 0.34065674
1.30031351 1.24698569 4.64834803 3.11041311 2.66534347 2.2615038
0.85577978 3.11652351 2.95245747 3.6797197 3.20901268 3.05956407
2.74721831 2.50446679 2.27093818 0.19615347 2.21363605 4.47224561
4.0085606 1.57096308 1.80238064 2.29190922 2.27745264 0.72302707
1.52160541 2.04445745 0.17668951 0.94625369 0.49049521 0.09612072
2.50291276 1.16012551 3.91918883 4.17461134 4.48741368 0.79404788
4.00519785 4.77468081 3.25124897 2.6898407 3.02265345 4.68225108
0.37366401 3.19072146 1.37409315 2.43618566 0.87814992 1.87864413
3.21035906 4.23535843 2.38188638 1.97971558 4.78608962 1.07282213
1.28279698 2.85588252 4.44064645 1.48691598 2.4950998 0.83618451
4.95146043 3.08120722 1.88186113 4.71873744 4.28276046 4.27786134
2.19592534 1.49837713 1.77243498 1.39051079 4.11637998 0.3358451
2.28455844 3.16674 4.78612908 0.2958198 1.83827636 0.82142262
0.26693962 1.92839789 1.71131502 4.44833751 0.68704552 1.84216505
2.39915665 1.97920831 2.28094054 2.79266006 3.11897108 1.71676875
2.76321534 4.92689055 2.59650043 3.9729484 0.53522558 4.27610937
1.65331821 1.74784658 2.99753083 0.02958332 0.66421897 3.44858791
1.61778048 2.56412338 0.85954727 3.25250351 1.48242805 4.52829851
3.20119137 1.2597195 3.91449639 1.9748359 1.44590301 3.07461338
1.12079153 1.88630299 1.77926343 4.90125419 2.06242296 1.55609779
2.35135331 0.3569796 0.12759176 2.71183376 2.6516446 4.47217984
1.2442209 3.07301279 4.46787009 3.45513853 4.96849953 1.28544108
4.80539245 2.76088706 1.29640006 3.01707076 0.0146418 3.64546797
1.40854032 1.48360596 2.9761339 3.18408698 1.24728339 0.22381348
2.74695815 0.3167204 3.81290152 4.87383218 2.54138165 2.16174943
4.15211654 4.66466204 0.71611619 2.78514541 0.23634551 3.49557367
2.444353 0.14498478 1.02703804 4.33391744]
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]

plt.scatter(x, y)
plt.show()
#LINEAR REGRESSION
# 1. Import the modules you need. (Scipy and Matplotlib)
# 2. Create the arrays that represent the values of the x and y axis
# 3. xecute a method that returns some important key values of Linear
Regression.
# 4. Create a function that uses the slope and intercept values to
return a new value. This new value represents where on the y-axis the
corresponding x value will be placed.
# 5. Run each value of the x array through the function. This will
result in a new array with new values for the y-axis.
# 6. Draw the original scatter plot.
# 7. Draw the line of linear regression.
# 8. Display the diagram.
slope, intercept, r, p, std_err = stats.linregress(x, y)

def myfunc(x):
return slope * x + intercept

mymodel = list(map(myfunc, x))

plt.scatter(x, y)
plt.plot(x, mymodel)
plt.show()
x = [5,7,8,7,2,17,2,9,4,11,12,9,6]
y = [99,86,87,88,111,86,103,87,94,78,77,85,86]

slope, intercept, r, p, std_err = stats.linregress(x, y)

print(r)
#It is important to know how the relationship between the values of
the x-axis and the values of the y-axis is, if there are no
relationship the linear regression can not be used to predict
anything.

#This relationship - the coefficient of correlation - is called r.

#The r value ranges from -1 to 1, where 0 means no relationship, and 1


(and -1) means 100% related.

# Bad Fit
x = [89,43,36,36,95,10,66,34,38,20,26,29,48,64,6,5,36,66,72,40]
y = [21,46,3,35,67,95,53,72,58,10,26,34,90,33,38,20,56,2,47,15]

slope, intercept, r, p, std_err = stats.linregress(x, y)

def myfunc(x):
return slope * x + intercept

mymodel = list(map(myfunc, x))


plt.scatter(x, y)
plt.plot(x, mymodel)
plt.show()

print(r)

Вам также может понравиться