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 modified __pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_myXGBoost/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q01_myXGBoost/__pycache__/build.cpython-36.pyc
Binary file not shown.
41 changes: 37 additions & 4 deletions q01_myXGBoost/build.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# %load q01_myXGBoost/build.py
import pandas as pd
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split
Expand All @@ -11,13 +12,45 @@
y = dataset.iloc[:, -1]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=9)

param_grid1 = {"max_depth": [2, 3, 4, 5, 6, 7, 9, 11],
"min_child_weight": [4, 6, 7, 8],
"subsample": [0.6, .7, .8, .9, 1],
"colsample_bytree": [0.6, .7, .8, .9, 1]
param_grid1 = {'max_depth': [2, 3, 4, 5, 6, 7, 9, 11],
'min_child_weight': [4, 6, 7, 8],
'subsample': [0.6, .7, .8, .9, 1],
'colsample_bytree': [0.6, .7, .8, .9, 1]
}


# Write your solution here :

def myXGBoost(X_train, X_test, y_train,y_test, model, param_grid, KFold=3, **kwargs):
if kwargs:
model.set_params(**kwargs)
gs_cv = GridSearchCV(model, param_grid=param_grid, cv=KFold, verbose=0)
gs_cv.fit(X_train, y_train)
best_params = gs_cv.best_params_
y_pred = gs_cv.predict(X_test)
accuracy = accuracy_score(y_pred, y_test)

return accuracy, best_params
param_grid1 = {'max_depth': [2, 3, 4, 5, 6, 7, 9, 11],
'min_child_weight': [4, 6, 7, 8],
'subsample': [0.6, .7, .8, .9, 1],
'colsample_bytree': [0.6, .7, .8, .9, 1]
}


def myXGBoost(X_train, X_test, y_train,y_test, model, param_grid, KFold=3, **kwargs):
if kwargs:
model.set_params(**kwargs)
gs_cv = GridSearchCV(model, param_grid=param_grid, cv=KFold, verbose=0)
gs_cv.fit(X_train, y_train)
best_params = gs_cv.best_params_
y_pred = gs_cv.predict(X_test)
accuracy = accuracy_score(y_pred, y_test)

return accuracy, best_params
#accuracy, best_params = myXGBoost(X_train, X_test, y_train, y_test, XGBClassifier(seed=9), param_grid1, 3)

#print (accuracy)
#print (best_params)


Binary file modified q01_myXGBoost/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.