Yechish. Y ning X ga nisbatan regressiya tenglamasini tuzamiz. Shu maqsadda quyidagi jadvalni tuzamiz.
№
|
|
|
|
|
|
|
|
1
|
3,2
|
4,0
|
12,80
|
10,24
|
16,00
|
4,06
|
3,67
|
2
|
3,0
|
3,8
|
11,40
|
9,00
|
14,44
|
4,08
|
3,56
|
3
|
3,10
|
3,5
|
10,85
|
9,61
|
12,25
|
4,07
|
3,40
|
4
|
2,8
|
3,0
|
8,40
|
7,84
|
9,00
|
4,10
|
3,14
|
5
|
3,4
|
4,4
|
14,96
|
11,56
|
19,36
|
4,03
|
3,88
|
6
|
3,8
|
4,2
|
15,96
|
14,44
|
17,64
|
3,98
|
3,78
|
7
|
4,0
|
4,6
|
18,40
|
16,00
|
21,26
|
3,96
|
3,99
|
8
|
3,5
|
4,5
|
15,75
|
12,25
|
20,25
|
4,02
|
3,94
|
9
|
3,9
|
3,1
|
12,09
|
15,21
|
9,61
|
3,97
|
3,19
|
10
|
4,5
|
4,1
|
18,45
|
20,25
|
16,81
|
3,9
|
2,72
|
11
|
4,6
|
4,8
|
22,08
|
21,26
|
23,04
|
3,89
|
4,09
|
12
|
4,2
|
4,0
|
16,80
|
17,64
|
16,00
|
3,93
|
3,67
|
|
44
|
48
|
177,94
|
145,05
|
195,66
|
48
|
44
|
Shunday qilib, =-0,12x+4,44.
import matplotlib
matplotlib.use('TkAgg')
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from matplotlib import pyplot as plt
pima = pd.read_csv('data.csv')
pima.plot(kind = 'scatter', x='Period' , y="Count")
x_train, x_test, y_train, y_test = train_test_split(pima.Period,pima.Count)
plt.scatter(x_train,y_train, label = "O'rgatuvchi berilganlar", color = 'red')
plt.scatter(x_test,y_test, label = "Test berilganlar", color = 'green')
LR = LinearRegression()
LR.fit(x_train.values.reshape(-1,1), y_train.values)
prediction = LR.predict(x_test.values.reshape(-1,1))
plt.plot(x_test, prediction, label = "Chiziqli regressiya", color = "blue")
plt.scatter(x_test,y_test, label = "Test berilganlar", color = "green")
plt.legend()
plt.grid()
plt.show()
|