def cv_evaluate_model(model, dframe): X = get_featues(dframe) y = get_label(dframe) kfold = StratifiedKFold(n_splits=10, shuffle=True) accuracy = np.empty(10) precision = np.empty(10) recall = np.empty(10) for i, (train_idx, test_idx) in tqdm(enumerate(kfold.split(X, y))): model.train(dframe.iloc[train_idx]) predictions = model.predict(X.iloc[test_idx]) accuracy[i] = accuracy_score(y[test_idx], predictions) precision[i] = precision_score(y[test_idx], predictions, average='macro') recall[i] = recall_score(y[test_idx], predictions, average='macro') results = { 'params': model.get_params(), 'model': model.name, 'accuracy_std': np.std(accuracy), 'accuracy_mean': np.mean(accuracy), 'precision_std': np.std(precision), 'precision_mean': np.mean(precision), 'recall_std': np.std(recall), 'recall_mean': np.mean(recall) } return results
def train(self, dframe): # from preprocess.py X = get_featues(dframe) y = get_label(dframe) self.clf.fit(X, y)
def train(self, dframe): X = get_featues(dframe) y = get_label(dframe) self.clf.fit(X, y)
def plot_learning_curve(self, dframe): X = get_featues(dframe) y = get_label(dframe) return skplt.plot_learning_curve(self.clf, X, y)