From 2087ec4554b56149992b3ad163f02078cdcf418d Mon Sep 17 00:00:00 2001 From: bhushan45 Date: Tue, 12 Jun 2018 11:09:29 +0000 Subject: [PATCH 1/3] Done --- __pycache__/__init__.cpython-36.pyc | Bin 135 -> 147 bytes .../__pycache__/__init__.cpython-36.pyc | Bin 151 -> 163 bytes .../__pycache__/build.cpython-36.pyc | Bin 794 -> 1067 bytes q01_grid_search/build.py | 18 +++++++++++++----- .../tests/__pycache__/__init__.cpython-36.pyc | Bin 157 -> 169 bytes .../test_q01_grid_search.cpython-36.pyc | Bin 3729 -> 3740 bytes 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index 14812de5bbb2a004d139995a9d5f098ae50a00f5..7911605ad5f1e6077015796c20e36e72eab85b1a 100644 GIT binary patch delta 49 zcmZo?oXp5(%*)F)d*wtnOL+(VjQreG{iKZ2;*7*R6I1>0{G#mQg2d!h{p9?V)QLf+ E0B#8o1^@s6 delta 37 scmbQt*v`mi%*)HQxOgI)rLc*9Mt*Lpeo1O^iM~r}adt_5!NfRI0Ksqzn*aa+ diff --git a/q01_grid_search/__pycache__/__init__.cpython-36.pyc b/q01_grid_search/__pycache__/__init__.cpython-36.pyc index 9413fbb035692cba6960d05692dfdb9b5cbb7e65..e1a3b62a1ad92cfffc6e6eb1ee2899f39614e04a 100644 GIT binary patch delta 49 zcmbQvxR{a6n3tDp_R5KDmhu7m8Tq-X`bin3#TkitCZ_t~`9;~q1&PV2`pNkzsS|@- E0d_eMMgRZ+ delta 37 scmZ3?IGvHrn3tDpaq&bpOJNuNjQreG{gTw;5`CA{;_Q%^J)henpm!%7O}d&BVn0-9~j%jEV6p>JJOLL)_YP&gcbNkaJ5(sW{`YudCeq}-a)gYnmk@w_I49ERwq1^UWhsmcr21AXyDrJJDXoD zYjL0?hp;(@21@?}p+mGnVGhyPFBa4hxfI6r80mh}n@y-8&TUMG4~D6NU_wobWLjG! Z>S?q3R{sj-@3iHriA>eHKWvH(nSXR#eU|_L delta 197 zcmZ3@F^f&vn3tDpaj|^#TqXvF#|%h-4ajx?;^Ivcl_NyOTA9+ABpIT3Qn|9YQy5bi zTbWYCCr)r>WejG}l-T%$iIMw15EMxOb!ZAtwr1}1yTu+6Us9BqnRkl~$Ve?Nxy4=y z696(m0$c@&MTxob=|!0-D;bJ3fqKEjFGu~1{M=N1kQ#lL)Z*-t{DR3hm<;$iY;yBc RN^?@}m_ZJcn#{u@3jp@yIPm}g diff --git a/q01_grid_search/build.py b/q01_grid_search/build.py index 20c99a1..a04eb7d 100644 --- a/q01_grid_search/build.py +++ b/q01_grid_search/build.py @@ -1,7 +1,8 @@ +# %load q01_grid_search/build.py # Default imports import warnings -warnings.filterwarnings("ignore") +warnings.filterwarnings('ignore') import pandas as pd from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier @@ -12,11 +13,18 @@ y_bal = loan_data.iloc[:, -1] X_train, X_test, y_train, y_test = train_test_split(X_bal, y_bal, test_size=0.33, random_state=9) -param_grid = {"max_features": ['sqrt', 4, "log2"], - "n_estimators": [10, 50, 120], - "max_depth": [40, 20, 10], - "max_leaf_nodes": [5, 10, 2]} +param_grid = {'max_features': ['sqrt', 4, 'log2'], + 'n_estimators': [10, 50, 120], + 'max_depth': [40, 20, 10], + 'max_leaf_nodes': [5, 10, 2]} # Write your solution here : +def grid_search(X_train, y_train, model, param_grid, cv=3): + grid = GridSearchCV(estimator=model, param_grid=param_grid, cv=cv) + grid.fit(X_train, y_train) + return grid, grid.cv_results_['params'], grid.cv_results_['mean_test_score'] + + + diff --git a/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc b/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc index 5cb0753554300b5c4d0de098c675c24f802d7273..6709d04aa17e9a908fa2c64c6c285c2d1a97abc9 100644 GIT binary patch delta 49 zcmbQsxRR00n3tDp_R5KDmhxfx8Tq-X`bin3#TkitCZ_t~`9;~q1&PV2`pNkzsS|^| E0eMRhUH||9 delta 37 scmZ3LZcT+ delta 64 zcmbOuJ5iR?n3tF9U9o)hrj4BG%)(*%8Tq-X`X#BwCHgL@#n~nK1)KYscQG=$OwM7` UU@a*v$Vr{NkWFH9A1fax0H; Date: Wed, 25 Jul 2018 18:37:00 +0530 Subject: [PATCH 2/3] Update build.py --- q02_fit/build.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/q02_fit/build.py b/q02_fit/build.py index fbafb1a..bf0da8c 100644 --- a/q02_fit/build.py +++ b/q02_fit/build.py @@ -22,6 +22,17 @@ # Write your solution here : +def fit(X_test, y_test): + print(grid.best_params_) + predicted = grid.predict(X_test) + predict = pd.DataFrame(predicted) + expected = y_test + + matrix = confusion_matrix(expected, predict) + clr = classification_report(expected, predict) + accuracy = accuracy_score(expected, predict) + + return matrix, clr, accuracy From 5d2904493856e54737eae9447ed9227c34569637 Mon Sep 17 00:00:00 2001 From: bhushan45 Date: Wed, 25 Jul 2018 18:37:41 +0530 Subject: [PATCH 3/3] Update build.py --- q02_fit/build.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/q02_fit/build.py b/q02_fit/build.py index bf0da8c..e71d66d 100644 --- a/q02_fit/build.py +++ b/q02_fit/build.py @@ -35,4 +35,4 @@ def fit(X_test, y_test): return matrix, clr, accuracy - +fit(X_test, y_test)