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.
9 changes: 7 additions & 2 deletions q01_myXGBoost/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@


# Write your solution here :


def myXGBoost(X_train, X_test, y_train, y_test, model, param_grid, KFold=3, **kwargs):
grid_cv = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=3, cv=KFold)
grid_cv.fit(X_train, y_train)
y_pred_test = grid_cv.predict(X_test)
acc_score = accuracy_score(y_true=y_test, y_pred=y_pred_test)
best_params = grid_cv.best_params_
return acc_score, best_params
Binary file modified q01_myXGBoost/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file modified q02_param2/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_param2/__pycache__/build.cpython-36.pyc
Binary file not shown.
20 changes: 20 additions & 0 deletions q02_param2/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,23 @@


# Write your solution here :
def param2(X_train, X_test, y_train, y_test, model, param_grid):
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]
}
acc_score, best_params = myXGBoost(X_train, X_test, y_train, y_test, model=model, param_grid=param_grid1, KFold=3)
# Get the best parameters from iteration-1
# Append the best parameters and the new parameters to create
# new set of parameters
param_grid3 = { key_: [val_] for key_, val_ in best_params.items() }
param_grid3.update(param_grid)
# Use previous function with new set of parameters (iteration-1 best params and new params param-grid)
acc_score1, best_params1 = myXGBoost(X_train, X_test, y_train, y_test, model=model, param_grid=param_grid3)
# Return only specific_params that were passed as part of param_grid in dictionary
specific_params = {}
for key_, value_ in best_params1.items():
if key_ not in best_params.keys():
specific_params[key_] = best_params1[key_]
return acc_score1, specific_params
Binary file modified q02_param2/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q02_param2/tests/__pycache__/test_q02_param2.cpython-36.pyc
Binary file not shown.
Binary file modified q03_xgboost/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_xgboost/__pycache__/build.cpython-36.pyc
Binary file not shown.
10 changes: 8 additions & 2 deletions q03_xgboost/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier
import pandas as pd
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import accuracy_score

# load data
Expand All @@ -13,5 +14,10 @@


# Write your solution here :


# exercise -3
def xgboost(X_train, X_test, y_train, y_test, **kwargs):
kwargs['random_state'] = 9
xgb = XGBClassifier(**kwargs)
xgb.fit(X_train, y_train)
y_pred_test = xgb.predict(X_test)
return accuracy_score(y_true=y_test, y_pred=y_pred_test)
Binary file modified q03_xgboost/tests/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file modified q03_xgboost/tests/__pycache__/test_q03_xgboost.cpython-36.pyc
Binary file not shown.