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] } grid, grid_param, grid_score = grid_search(X_train, y_train, rfc, param_grid, cv=3) class TestFit(TestCase): def test_fit(self): # Input parameters tests args = getargspec(fit) self.assertEqual( len(args[0]), 2, "Expected argument(s) %d, Given %d" % (2, len(args[0]))) def test_fit_default(self): # Input parameter defaults args = getargspec(fit) self.assertEqual( args[3], None,
def fit(X_test,y_test): grid, grid_param, grid_score = grid_search(X_train, y_train, rfc, param_grid, cv=3) grid.fit(X_train,y_train) y_pred = grid.predict(X_test) return confusion_matrix(y_test,y_pred), classification_report(y_test,y_pred), accuracy_score(y_test,y_pred)