ModuleNotFoundError:没有名为“ pandas_confusion”的模块

时间:2019-03-17 19:45:04

标签: python python-3.x

我正在尝试从教程中运行代码,以更好地理解它。我已经完成一半,但是在粘贴此行代码后,我收到一条错误消息:

ModuleNotFoundError: No module named 'pandas_confusion

代码如下:

from pandas_confusion import ConfusionMatrix


def iterate_fit_predict_score(number_runs):
    f1_scores = []

    y = reformat(student_data['passed'])

    for num in range(0,number_runs):
        X_train, X_test, y_train, y_test = Stratified_Shuffle_Split(X_all, y, num_test)
        clf_SVC = SVC()
        parameters = [{'C':[1,10,50,100,200,300,400,500,1000],
                     'gamma':[1e-4, 1e-3, 1e-2, 1e-1, 1e0, 1e1],
                     'kernel': ['rbf']}]

        clf = GridSearchCV(clf_SVC, parameters, scoring = 'f1')
        clf.fit(X_train, y_train)
        y_true, y_pred = y_test, clf.predict(X_test)
        target_names = ["failed","passed"]
        print(classification_report(y_true, y_pred,target_names=target_names))    

        # Print Conf_Matrix
        conf_matrix = pd.crosstab(y_true, y_pred, rownames=['Actual'], colnames=['Predicted'], margins=True)
        print("\nConf_Matrix:", conf_matrix)

        #Normalize Conf_Matrix:
        conf_matrix_norm = conf_matrix / conf_matrix.sum(axis=1)
        print("\nNormalize Conf_Matrix:", conf_matrix_norm)

        #Generate Confusion Matrix Plot
        conf_matrix = metrics.confusion_matrix(y_true, y_pred)
        labels = ['fail','pass']
        pl.title('SVC: Confusion Matrix')
        ax = pl.axes
        sns.heatmap(conf_matrix, 
                xticklabels=labels, 
                yticklabels=labels,
                annot=True, fmt='')
        pl.xlabel("Predicted")
        pl.ylabel("True")

enter image description here

是什么意思?无论如何,这是我要关注的project,以防万一您想查看完整的代码

1 个答案:

答案 0 :(得分:0)

您缺少pandas_confusion软件包。在命令提示符下,运行pip install pandas_confusion