diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index 51086b4..fb11651 100644 Binary files a/__pycache__/__init__.cpython-36.pyc and b/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_myXGBoost/__pycache__/__init__.cpython-36.pyc b/q01_myXGBoost/__pycache__/__init__.cpython-36.pyc index 05966ae..6798050 100644 Binary files a/q01_myXGBoost/__pycache__/__init__.cpython-36.pyc and b/q01_myXGBoost/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_myXGBoost/__pycache__/build.cpython-36.pyc b/q01_myXGBoost/__pycache__/build.cpython-36.pyc index 73181f1..e0a9f98 100644 Binary files a/q01_myXGBoost/__pycache__/build.cpython-36.pyc and b/q01_myXGBoost/__pycache__/build.cpython-36.pyc differ diff --git a/q01_myXGBoost/build.py b/q01_myXGBoost/build.py index db3654a..a82b0f6 100644 --- a/q01_myXGBoost/build.py +++ b/q01_myXGBoost/build.py @@ -1,8 +1,11 @@ +# %load q01_myXGBoost/build.py import pandas as pd from xgboost import XGBClassifier from sklearn.model_selection import train_test_split from sklearn.model_selection import GridSearchCV from sklearn.metrics import accuracy_score +from unittest import TestCase +from inspect import getargspec # load data dataset = pd.read_csv('data/loan_clean_data.csv') @@ -11,13 +14,38 @@ 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): + gs_cv = GridSearchCV(estimator = model, param_grid= param_grid, cv = Kfold) + gs_cv.fit(X_train, y_train) + + # make predictions for test data + y_pred = gs_cv.predict(X_test) + predictions = [round(value) for value in y_pred] + accuracy = accuracy_score(y_test, predictions) + #print('Accuracy: %.2f%%' % (accuracy * 100.0)) + + return accuracy, gs_cv.best_params_ + +xgb = XGBClassifier(seed=9) +gs_cv_accuracy, gs_cv_best_params = myXGBoost(X_train, X_test, y_train, y_test, xgb, param_grid1, 3) +expected_best_params = {'subsample': 0.8, 'colsample_bytree': 0.7, 'max_depth': 2, 'min_child_weight': 4} +expected_accuracy = 0.796703296703 + +print (gs_cv_accuracy) +print (gs_cv_best_params) + +args = getargspec(myXGBoost) +print (len(args[0])) +print (args[3]) +print (type(gs_cv_accuracy)) +print (type(gs_cv_best_params)) diff --git a/q01_myXGBoost/tests/__pycache__/__init__.cpython-36.pyc b/q01_myXGBoost/tests/__pycache__/__init__.cpython-36.pyc index 8dfa197..4715cd7 100644 Binary files a/q01_myXGBoost/tests/__pycache__/__init__.cpython-36.pyc and b/q01_myXGBoost/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_myXGBoost/tests/__pycache__/test_q01_myXGBoost.cpython-36.pyc b/q01_myXGBoost/tests/__pycache__/test_q01_myXGBoost.cpython-36.pyc index c955d76..380c23d 100644 Binary files a/q01_myXGBoost/tests/__pycache__/test_q01_myXGBoost.cpython-36.pyc and b/q01_myXGBoost/tests/__pycache__/test_q01_myXGBoost.cpython-36.pyc differ diff --git a/q02_param2/__pycache__/__init__.cpython-36.pyc b/q02_param2/__pycache__/__init__.cpython-36.pyc index 65aae62..1ff0163 100644 Binary files a/q02_param2/__pycache__/__init__.cpython-36.pyc and b/q02_param2/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_param2/__pycache__/build.cpython-36.pyc b/q02_param2/__pycache__/build.cpython-36.pyc index 265965e..99e392b 100644 Binary files a/q02_param2/__pycache__/build.cpython-36.pyc and b/q02_param2/__pycache__/build.cpython-36.pyc differ diff --git a/q02_param2/build.py b/q02_param2/build.py index 8391570..39aec6d 100644 --- a/q02_param2/build.py +++ b/q02_param2/build.py @@ -17,4 +17,7 @@ } -# Write your solution here : +def param2(X_train, X_test, y_train, y_test, xgb, param_grid, **kwargs): + #Include parameters used for earlier call as well. + accuracy, best_params_ = myXGBoost(X_train, X_test, y_train, y_test, xgb, param_grid, colsample_bytree=0.7, subsample=0.8, max_depth=2, min_child_weight=4) + return accuracy, best_params_ diff --git a/q02_param2/tests/__pycache__/__init__.cpython-36.pyc b/q02_param2/tests/__pycache__/__init__.cpython-36.pyc index 19bc1aa..4c810b2 100644 Binary files a/q02_param2/tests/__pycache__/__init__.cpython-36.pyc and b/q02_param2/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_param2/tests/__pycache__/test_q02_param2.cpython-36.pyc b/q02_param2/tests/__pycache__/test_q02_param2.cpython-36.pyc index 18c07a7..9b719f1 100644 Binary files a/q02_param2/tests/__pycache__/test_q02_param2.cpython-36.pyc and b/q02_param2/tests/__pycache__/test_q02_param2.cpython-36.pyc differ diff --git a/q03_xgboost/__pycache__/__init__.cpython-36.pyc b/q03_xgboost/__pycache__/__init__.cpython-36.pyc index 2e9c375..a78960c 100644 Binary files a/q03_xgboost/__pycache__/__init__.cpython-36.pyc and b/q03_xgboost/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_xgboost/__pycache__/build.cpython-36.pyc b/q03_xgboost/__pycache__/build.cpython-36.pyc index 4c997b3..99abfbb 100644 Binary files a/q03_xgboost/__pycache__/build.cpython-36.pyc and b/q03_xgboost/__pycache__/build.cpython-36.pyc differ diff --git a/q03_xgboost/build.py b/q03_xgboost/build.py index 7905a04..d1acce0 100644 --- a/q03_xgboost/build.py +++ b/q03_xgboost/build.py @@ -12,6 +12,16 @@ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=9) -# Write your solution here : - - +def xgboost(X_train, X_test, y_train, y_test, **kwargs): + + xgb = XGBClassifier(subsample=0.8, + colsample_bytree=0.7, max_depth=2, + min_child_weight=4, reg_alpha=0, reg_lambda=1.0, + gamma=0,n_estimators=100,learning_rate=0.01) + xgb.fit(X_train, y_train) + y_pred = xgb.predict(X_test) + y_pred = predictions = [round(value) for value in y_pred] + + acc = accuracy_score(y_test, y_pred) + + return acc diff --git a/q03_xgboost/tests/__pycache__/__init__.cpython-36.pyc b/q03_xgboost/tests/__pycache__/__init__.cpython-36.pyc index e887bf7..fcb02a6 100644 Binary files a/q03_xgboost/tests/__pycache__/__init__.cpython-36.pyc and b/q03_xgboost/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q03_xgboost/tests/__pycache__/test_q03_xgboost.cpython-36.pyc b/q03_xgboost/tests/__pycache__/test_q03_xgboost.cpython-36.pyc index 77271df..aa4dda1 100644 Binary files a/q03_xgboost/tests/__pycache__/test_q03_xgboost.cpython-36.pyc and b/q03_xgboost/tests/__pycache__/test_q03_xgboost.cpython-36.pyc differ