经过几次预测后如何计算错类率列?

时间:2018-08-15 06:10:37

标签: python

我正在尝试通过以下几种预测迭代来计算错误分类率的方法。我试图编写其余的代码,但仍然无法正常工作。我在做什么错了?

predictions = df.copy()
y = df['gt']
noiter = 10
hits = 0
tpred = 0

for i in range(noiter):
    Xtrain, Xtest, ytrain, ytest = train_test_split(df,test_size=0.3,random_state=noiter)


    model = xgb.XGBClassifier()
    model.fit(X_train,y_train)
    pred_i = model.predict(X_test)
    newcol = 'npred_' + str(noiter)
    pred.loc[test.index,newcol] = pred_i

#now to calculate the misclassification rate
    if pred_i != 'NaN':
        tpred = tpred + 1


    if pred_i == test['gt']:
        hits = hits + 1

pred['missclassrate'] = hits/tpred

1 个答案:

答案 0 :(得分:0)

您可以获取混淆矩阵以确定假阳性和阴性:

from sklearn.metrics import confusion_matrix
print confusion_matrix(ytest, pred_i)