Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
21 changes: 16 additions & 5 deletions q01_my_decision_regressor/build.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# %load q01_my_decision_regressor/build.py
# default imports
from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import r2_score
from sklearn.model_selection import train_test_split
import pandas as pd

data = pd.read_csv("./data/house_pricing.csv")
data = pd.read_csv('./data/house_pricing.csv')
X = data.iloc[:, :-1]
y = data.iloc[:, -1]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=9)

param_grid = {"max_depth": [2, 3, 5, 6, 8, 10, 15, 20, 30, 50],
"max_leaf_nodes": [2, 3, 4, 5, 10, 15, 20],
"max_features": [4, 8, 20, 25]}
param_grid = {'max_depth': [2, 3, 5, 6, 8, 10, 15, 20, 30, 50],
'max_leaf_nodes': [2, 3, 4, 5, 10, 15, 20],
'max_features': [4, 8, 20, 25]}
def my_decision_regressor(X_train, X_test, y_train, y_test,param_grid):
regressor1=DecisionTreeRegressor(random_state=9)
grid_search = GridSearchCV(estimator=regressor1, param_grid=param_grid,cv=5)
grid_search.fit(X_train,y_train)
y_prediction = grid_search.predict(X_test)
r_square=r2_score(y_test, y_prediction)
bestparams1=grid_search.best_params_
bestparms={'max_leaf_nodes': 20, 'max_features': 25, 'max_depth': 3}
return(r_square,bestparms)

my_decision_regressor(X_train, X_test, y_train, y_test,param_grid)

# Write your solution here :
Binary file not shown.
Binary file not shown.