-
Notifications
You must be signed in to change notification settings - Fork 0
/
analysis_tree_regressor.py
executable file
·30 lines (25 loc) · 1.13 KB
/
analysis_tree_regressor.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
import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeRegressor
from sklearn.ensemble import AdaBoostRegressor
from sklearn.model_selection import cross_val_score
datafolder = 'data/working/'
outfolder = 'data/output/'
df_test = pd.read_csv(datafolder + 'test_normalized.csv')
df_train = pd.read_csv(datafolder + 'train_normalized.csv')
Xtrain = df_train.drop(['SalePrice','Id'], axis=1)
Xtest = df_test.drop(['Id'], axis=1)
y = np.log1p(df_train['SalePrice'])
model = DecisionTreeRegressor(min_samples_leaf=10,
max_depth=None)
adaboost = AdaBoostRegressor(model, n_estimators=500)
randstate = 2
#scores = cross_val_score(adaboost,
# Xtrain.sample(frac=1, random_state=randstate),
# y.sample(frac=1, random_state=randstate),
# cv=5,
# scoring='neg_mean_squared_log_error')
adaboost.fit(Xtrain, y)
predicted = adaboost.predict(Xtest)
submission = pd.DataFrame({'Id':df_test.Id, 'SalePrice':np.expm1(predicted)})
submission.to_csv(outfolder + 'submission4_adaboost_normalized.csv', index=False)