-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuto_1.py
34 lines (26 loc) · 864 Bytes
/
tuto_1.py
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
# Use Linear Regression to estimate continuous values
import matplotlib.pyplot as plt
from sklearn import datasets, metrics
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
boston = datasets.load_boston()
print(boston.keys())
print(boston.feature_names)
print(boston.DESCR)
print(boston.data[:5])
print(boston.target[:5])
print(boston.data.shape)
print(boston.target.shape)
X = boston.data
y = boston.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=16)
model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
plt.scatter(y_test, predictions)
plt.xlabel("Actual prices")
plt.ylabel("Predicted prices")
plt.show()
print(predictions)
print(model.score(X_test, y_test))
print(metrics.mean_squared_error(y_test, predictions))