-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGDRegressor using houses data (data from excel).py
57 lines (35 loc) · 1.31 KB
/
SGDRegressor using houses data (data from excel).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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import numpy as np
import pandas as pd
dataset = pd.read_csv('houses.csv')
dataset.head(20)
from sklearn.impute import SimpleImputer
imp = SimpleImputer(missing_values=np.nan, strategy='mean')
imp = imp.fit(dataset)
dataset = imp.transform(dataset)
X = dataset[:, :-1]
y = dataset[:, -1]
X
y
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X = sc.fit_transform(X)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
X_train
X_test
y_train
y_test
from sklearn.linear_model import SGDRegressor
#clf = linear_model.SGDRegressor( penalty = 'l2' , max_iter=1000, tol=1e-3 , loss = 'huber')
sgd = SGDRegressor( penalty = 'l2' , max_iter=1000, tol=1e-3 , loss = 'squared_loss')
#clf = linear_model.SGDRegressor( penalty = 'l1' , max_iter=1000, tol=1e-3 , loss = 'huber')
#clf = linear_model.SGDRegressor( penalty = 'l1' , max_iter=1000, tol=1e-3 , loss = 'squared_loss')
sgd.fit(X_train, y_train)
y_pred = sgd.predict(X_test)
y_pred
sgd.score(X_train,y_train)
sgd.score(X_test,y_test)
from sklearn.metrics import mean_absolute_error
mean_absolute_error(y_test, y_pred)
from sklearn.metrics import mean_squared_error
mean_squared_error(y_test, y_pred)