diff --git a/__init__.pyc b/__init__.pyc index 800b98f..347b0a9 100644 Binary files a/__init__.pyc and b/__init__.pyc differ diff --git a/q01_myXGBoost/__init__.pyc b/q01_myXGBoost/__init__.pyc index dcfccf7..a7820ad 100644 Binary files a/q01_myXGBoost/__init__.pyc and b/q01_myXGBoost/__init__.pyc differ diff --git a/q01_myXGBoost/build.py b/q01_myXGBoost/build.py index f000406..88ee1a4 100644 --- a/q01_myXGBoost/build.py +++ b/q01_myXGBoost/build.py @@ -1,25 +1,40 @@ -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 - -# load data -dataset = pd.read_csv('data/loan_clean_data.csv') -# split data into X and y -X = dataset.iloc[:, :-1] -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] - } - - -# Write your solution here : - - - - +# %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 + +# load data +dataset = pd.read_csv('data/loan_clean_data.csv') +# split data into X and y +X = dataset.iloc[:, :-1] +y = dataset.iloc[:, -1] +X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=9) +model=XGBClassifier(seed=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] + } + + +# Write your solution here : + +def myXGBoost(X_train, X_test, y_train, y_test,model,param_grid,Kfold=3): + #acc_scorer = make_scorer(accuracy_score) + grid_obj = GridSearchCV(model, param_grid1,cv=Kfold) + grid_obj.fit(X_train,y_train) + bestParam= grid_obj.best_params_ + y_pred=grid_obj.predict(X_test) + acc_score=accuracy_score(y_test,y_pred) + #print(grid_obj.best_score_) + return acc_score.item(),bestParam + + +# accuracy, best_params =myXGBoost(X_train, X_test, y_train, y_test,model,param_grid1,Kfold=3) +# print(type(accuracy)) +# print(type(best_params)) +# print(best_params) +# print(accuracy) diff --git a/q01_myXGBoost/build.pyc b/q01_myXGBoost/build.pyc index 2b98a8a..8fd6ad6 100644 Binary files a/q01_myXGBoost/build.pyc and b/q01_myXGBoost/build.pyc differ diff --git a/q01_myXGBoost/tests/__init__.pyc b/q01_myXGBoost/tests/__init__.pyc index 7411455..c704383 100644 Binary files a/q01_myXGBoost/tests/__init__.pyc and b/q01_myXGBoost/tests/__init__.pyc differ diff --git a/q01_myXGBoost/tests/test_q01_myXGBoost.pyc b/q01_myXGBoost/tests/test_q01_myXGBoost.pyc index 54780c7..5abf134 100644 Binary files a/q01_myXGBoost/tests/test_q01_myXGBoost.pyc and b/q01_myXGBoost/tests/test_q01_myXGBoost.pyc differ diff --git a/q02_param2/__init__.pyc b/q02_param2/__init__.pyc index fae1a21..7329b47 100644 Binary files a/q02_param2/__init__.pyc and b/q02_param2/__init__.pyc differ diff --git a/q02_param2/build.py b/q02_param2/build.py index 156fe17..1f67c4c 100644 --- a/q02_param2/build.py +++ b/q02_param2/build.py @@ -1,3 +1,5 @@ + +# %load q02_param2/build.py # Default imports from sklearn.model_selection import train_test_split from xgboost import XGBClassifier @@ -16,6 +18,43 @@ "reg_lambda": [0.05, 0.1, 0.5, 1.0] } +model = XGBClassifier(seed=9) # 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] + } + cc_score,bestParam = myXGBoost(X_train, X_test, y_train, y_test,model,param_grid1,3) + #print(bestParam) + #dic ={} + + #updatePara = {'subsample': 0.8, 'colsample_bytree': 0.7, 'max_depth': 2, 'min_child_weight': 4} + + param_g={} + for k, v in bestParam.items(): + #print(k,v) + param_g[k]=[v] + + #print(param_g) + + #updateParam = {'subsample': [0.8], 'colsample_bytree': [0.7], 'max_depth': [2], 'min_child_weight': [4]} + + updateParam=param_g.copy() + updateParam.update(param_grid) + #print(updateParam) + cc_score2,bestParam2= myXGBoost(X_train, X_test, y_train, y_test,model,updateParam,3) + + #print(cc_score2,bestParam2) + update_best_param={k: v for k, v in bestParam2.items() if k not in param_g} + return (cc_score2.item(),update_best_param) + +# accuracy1, best_params1 =param2(X_train, X_test, y_train, y_test,model,param_grid2) +# print(type(accuracy1)) +# print( type(best_params1)) +# print(accuracy1) +# print(best_params1) diff --git a/q02_param2/build.pyc b/q02_param2/build.pyc index 1db061f..6a9715c 100644 Binary files a/q02_param2/build.pyc and b/q02_param2/build.pyc differ diff --git a/q02_param2/tests/__init__.pyc b/q02_param2/tests/__init__.pyc index 058448a..0b3839a 100644 Binary files a/q02_param2/tests/__init__.pyc and b/q02_param2/tests/__init__.pyc differ diff --git a/q02_param2/tests/test_q02_param2.pyc b/q02_param2/tests/test_q02_param2.pyc index 5e496da..abc9f2d 100644 Binary files a/q02_param2/tests/test_q02_param2.pyc and b/q02_param2/tests/test_q02_param2.pyc differ diff --git a/q03_xgboost/__init__.pyc b/q03_xgboost/__init__.pyc index 4fb1998..251ed47 100644 Binary files a/q03_xgboost/__init__.pyc and b/q03_xgboost/__init__.pyc differ diff --git a/q03_xgboost/build.py b/q03_xgboost/build.py index fc75b96..8481d5c 100644 --- a/q03_xgboost/build.py +++ b/q03_xgboost/build.py @@ -1,3 +1,5 @@ + +# %load q03_xgboost/build.py # Default imports from sklearn.model_selection import train_test_split from xgboost import XGBClassifier @@ -13,4 +15,19 @@ # Write your solution here : +def xgboost(X_train, X_test, y_train, y_test,**kwargs): + model = XGBClassifier(seed=9,**kwargs) + #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.1) + model.fit(X_train,y_train) + y_pred=model.predict(X_test) + acc_score=accuracy_score(y_test,y_pred) + return acc_score.item() + + +# accuracy=xgboost(X_train, X_test, y_train, y_test,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.1) +# print(accuracy) +# print(type(accuracy)) diff --git a/q03_xgboost/build.pyc b/q03_xgboost/build.pyc index fab0e81..9abba60 100644 Binary files a/q03_xgboost/build.pyc and b/q03_xgboost/build.pyc differ diff --git a/q03_xgboost/tests/__init__.pyc b/q03_xgboost/tests/__init__.pyc index c17cec4..7059f99 100644 Binary files a/q03_xgboost/tests/__init__.pyc and b/q03_xgboost/tests/__init__.pyc differ diff --git a/q03_xgboost/tests/test_q03_xgboost.pyc b/q03_xgboost/tests/test_q03_xgboost.pyc index 921bfbf..879b70f 100644 Binary files a/q03_xgboost/tests/test_q03_xgboost.pyc and b/q03_xgboost/tests/test_q03_xgboost.pyc differ