diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index 14812de..7911605 100644 Binary files a/__pycache__/__init__.cpython-36.pyc and b/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_grid_search/__pycache__/__init__.cpython-36.pyc b/q01_grid_search/__pycache__/__init__.cpython-36.pyc index 9413fbb..e1a3b62 100644 Binary files a/q01_grid_search/__pycache__/__init__.cpython-36.pyc and b/q01_grid_search/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_grid_search/__pycache__/build.cpython-36.pyc b/q01_grid_search/__pycache__/build.cpython-36.pyc index dbd3e7a..46a5309 100644 Binary files a/q01_grid_search/__pycache__/build.cpython-36.pyc and b/q01_grid_search/__pycache__/build.cpython-36.pyc differ 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 5cb0753..6709d04 100644 Binary files a/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc and b/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q01_grid_search/tests/__pycache__/test_q01_grid_search.cpython-36.pyc b/q01_grid_search/tests/__pycache__/test_q01_grid_search.cpython-36.pyc index 6061f23..e606d31 100644 Binary files a/q01_grid_search/tests/__pycache__/test_q01_grid_search.cpython-36.pyc and b/q01_grid_search/tests/__pycache__/test_q01_grid_search.cpython-36.pyc differ diff --git a/q02_fit/build.py b/q02_fit/build.py index fbafb1a..e71d66d 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 + +fit(X_test, y_test)