-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (28 loc) · 1.15 KB
/
main.py
File metadata and controls
43 lines (28 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import matplotlib.pyplot as plt
import numpy as np
from sklearn import datasets, linear_model
from sklearn.metrics import mean_squared_error
diabetes = datasets.load_diabetes()
# (['data', 'target', 'frame', 'DESCR', 'feature_names', 'data_filename', 'target_filename'])
# print(diabetes.keys())
# print(diabetes.data)
# print(diabetes.DESCR)
diabetes_x = diabetes.data # [:, np.newaxis, 2] # for plotting line
diabetes_x_train = diabetes_x[:-30] # slicing from data
diabetes_x_test = diabetes_x[-20:]
diabetes_y_train = diabetes.target[:-30] # slicing from data
diabetes_y_test = diabetes.target[-20:]
model = linear_model.LinearRegression() # using regression model
model.fit(diabetes_x_train, diabetes_y_train)
diabetes_y_predict = model.predict(diabetes_x_test)
print("Mean squared error is : ", mean_squared_error(diabetes_y_test, diabetes_y_predict))
print("Weights: ", model.coef_)
print("Intercept: ", model.intercept_)
# for plotting a line
# plt.scatter(diabetes_x_test, diabetes_y_test)
# plt.plot(diabetes_x_test, diabetes_y_predict)
#
# plt.show()
# Mean squared error is : 2561.3204277283867
# Weights: [941.43097333]
# Intercept: 153.39713623331698