计算np.mean使用百分比过滤器进行预测

时间:2018-04-21 06:36:00

标签: pandas machine-learning scikit-learn

我需要找到clf.predict的np.mean仅适用于其中一个预测值超过80%的行

我目前的代码:

clf = DecisionTreeClassifier(random_state=1)
clf.fit(X, Y)

dropIndexes = []

for i in range(len(X)):
    proba = clf.predict_proba ([X.values[i]])
    if (proba[0][0] < 80 and proba[0][1] < 80):
        dropIndexes.append(i)

#delete all rows where predicted values less then 80

X.drop(dropIndexes, inplace=True)
Y.drop(dropIndexes, inplace=True)

#Returns the average of the array elements
print ("ERR:",  np.mean(Y != clf.predict(X)))

是否可以更快地制作此代码?

1 个答案:

答案 0 :(得分:0)

您的循环是不必要的,因为predict_proba适用于矩阵。您可以用

替换它
 prd = clf.predict_proba(X)
 dropIndexes = (prd[:, 0] < 0.8) & (prd[:, 1] < 0.8)
相关问题