diff --git a/__pycache__/__init__.cpython-36.pyc b/__pycache__/__init__.cpython-36.pyc index 494c0e4..0802d93 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 eed5319..3959211 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 cac4a0b..6ba330c 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..56ffb8e 100644 --- a/q01_grid_search/build.py +++ b/q01_grid_search/build.py @@ -1,8 +1,10 @@ +# %load q01_grid_search/build.py # Default imports import warnings -warnings.filterwarnings("ignore") +warnings.filterwarnings('ignore') import pandas as pd +import numpy as np from sklearn.model_selection import train_test_split from sklearn.ensemble import RandomForestClassifier from sklearn.model_selection import GridSearchCV @@ -12,11 +14,45 @@ 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]} + +rf = RandomForestClassifier(random_state=9, oob_score=True) +def grid_search(X_train, y_train,rf, param_grid, cv=3): + model = GridSearchCV(estimator=rf, param_grid=param_grid, cv=cv) + model.fit(X_train, y_train) + var1 = list(model.cv_results_['params']) + var2 = np.array(model.cv_results_['mean_test_score']) + return model, var1, var2 + +rf = RandomForestClassifier(random_state=9, oob_score=True) +def grid_search(X_train, y_train,rf, param_grid, cv=3): + model = GridSearchCV(estimator=rf, param_grid=param_grid, cv=cv) + model.fit(X_train, y_train) + var1 = list(model.cv_results_['params']) + var2 = np.array(model.cv_results_['mean_test_score']) + return model, var1, var2 + +grid_search(X_train, y_train,rf, param_grid, cv=3) + + + + + + + + + + + + + + + + + -# Write your solution here : diff --git a/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc b/q01_grid_search/tests/__pycache__/__init__.cpython-36.pyc index 31ac328..209f34e 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 bf1afbe..a0b18a1 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/__pycache__/__init__.cpython-36.pyc b/q02_fit/__pycache__/__init__.cpython-36.pyc index 97c33cb..2eb7f9c 100644 Binary files a/q02_fit/__pycache__/__init__.cpython-36.pyc and b/q02_fit/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_fit/__pycache__/build.cpython-36.pyc b/q02_fit/__pycache__/build.cpython-36.pyc index 3d41a62..b8fb172 100644 Binary files a/q02_fit/__pycache__/build.cpython-36.pyc and b/q02_fit/__pycache__/build.cpython-36.pyc differ diff --git a/q02_fit/build.py b/q02_fit/build.py index fbafb1a..64f8f15 100644 --- a/q02_fit/build.py +++ b/q02_fit/build.py @@ -1,3 +1,4 @@ +# %load q02_fit/build.py # Default imports import pandas as pd @@ -13,15 +14,25 @@ X_train, X_test, y_train, y_test = train_test_split(X_bal, y_bal, test_size=0.33, random_state=9) rfc = RandomForestClassifier(oob_score=True, 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]} grid, grid_param, grid_score = grid_search(X_train, y_train, rfc, param_grid, cv=3) # Write your solution here : +def fit(X_test, y_test): + y_pred = grid.predict(X_test) + variable1 = confusion_matrix(y_test, y_pred) + variable2 = classification_report(y_test, y_pred) + variable3 = accuracy_score(y_test, y_pred) + return variable1, variable2, variable3 +def fit(X_test,y_test): + pass +X_test.shape +type(y_test) diff --git a/q02_fit/tests/__pycache__/__init__.cpython-36.pyc b/q02_fit/tests/__pycache__/__init__.cpython-36.pyc index 4a01850..563c9dd 100644 Binary files a/q02_fit/tests/__pycache__/__init__.cpython-36.pyc and b/q02_fit/tests/__pycache__/__init__.cpython-36.pyc differ diff --git a/q02_fit/tests/__pycache__/test_q02_fit.cpython-36.pyc b/q02_fit/tests/__pycache__/test_q02_fit.cpython-36.pyc index 413b2fc..850116c 100644 Binary files a/q02_fit/tests/__pycache__/test_q02_fit.cpython-36.pyc and b/q02_fit/tests/__pycache__/test_q02_fit.cpython-36.pyc differ