在model_selection.KFold

时间:2019-09-30 22:57:35

标签: python machine-learning scikit-learn

我从here获得了这个不错的实现。一切正常。但是,我一直在尝试向此实现添加更多指标。我需要的度量标准从sklearn.metrics导入category_report中称为“ classification_report”。如果我应该尝试将其添加到我的for循环中或完成所有操作后,我会迷路。有什么想法吗?

# prepare configuration for cross validation test harness
seed = 7

# prepare models
models = []
models.append(('Linear Discriminant Analysis', LinearDiscriminantAnalysis()))
models.append(('Ada Boost Classifier', AdaBoostClassifier()))
models.append(('Decision Tree Classifier', DecisionTreeClassifier()))
models.append(('Extra Trees Classifier', ExtraTreesClassifier()))
models.append(('Random Forest Classifier', RandomForestClassifier()))
#models.append(('Decision Tree Classifier (Cart)', DecisionTreeClassifier()))
#models.append(('Linear Support Vector Classification', LinearSVC()))
#models.append(('Nu-Support Vector Classification', NuSVC()))
#models.append(('Support Vector Classification', SVC()))


# evaluate each model in turn
bestresultvalue = 0
bestresultname = 0
results = []
names = []
scoring = 'accuracy'


for name, model in models:
    # k=10: The value for k is fixed to 10, a value that has been found through experimentation to generally result in a model skill estimate with low bias a modest variance.
    kfold = model_selection.KFold(n_splits=10, random_state=seed) 
    cv_results = model_selection.cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
    results.append(cv_results)
    names.append(name)
    msg = "%s: %f (%f)" % (name, cv_results.mean(), cv_results.std())        
    print(msg)

Sudo代码/想法:

from sklearn.metrics import classification_report
y_true = Y
y_pred = cv_results
target_names = ['class 0', 'class 1', 'class 2']
print(classification_report(y_true, y_pred, target_names=target_names))

0 个答案:

没有答案