-
Notifications
You must be signed in to change notification settings - Fork 0
/
test2b1.py
32 lines (23 loc) · 1.01 KB
/
test2b1.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
import pandas as pd
import numpy as np
df = pd.read_csv(r"C:\Users\dbda\Downloads\cars.csv")
dum_df = pd.get_dummies(df, drop_first=True)
from sklearn.model_selection import train_test_split
X = dum_df.iloc[:,2:]
y = dum_df.iloc[:,0]
# Create training and test sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3,
random_state=2018)
from sklearn.ensemble import GradientBoostingRegressor
clf = GradientBoostingRegressor(random_state=1200)
clf.fit(X_train,y_train)
y_pred = clf.predict(X_test)
#def mean_absolute_percentage_error(y_true, y_pred):
# y_true, y_pred = np.array(y_true), np.array(y_pred)
# return np.mean(np.abs((y_true - y_pred) / y_true))
#
#print(mean_absolute_percentage_error(y_test,y_pred))
from sklearn.metrics import mean_squared_error,mean_absolute_error,r2_score
print(mean_squared_error(y_test, y_pred))
print(mean_absolute_error(y_test, y_pred))
print(r2_score(y_test, y_pred))