Значение истинности массива с более чем одним элементом неоднозначно. Используйте a.any () или a.all () в пределах мл обучения - PullRequest
0 голосов
/ 03 мая 2020

я пытаюсь обучить данные, как показано ниже, но я получаю эту ошибку при выполнении

cv_results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)

ошибка:

The truth value of an array with more than one element is ambiguous. Use a.any() or a.all().

# Predicting the Test set results
y_pred = classifier.predict(X_test)
y_pred = (y_pred > 0.5)


# Making the Confusion Matrix
from sklearn.metrics import multilabel_confusion_matrix
cm = multilabel_confusion_matrix(y_test, y_pred)


scoring = 'accuracy'
# Define models to train
models = []
models.append(('K-Nearest Neighbours', KNeighborsClassifier(n_neighbors = 5)))
models.append(('Support Vector Machine', SVC()))
models.append(('Naive Bayes', GaussianNB()))
models.append(('Decision Tree', DecisionTreeClassifier()))
models.append(('Randoom Forest', RandomForestClassifier(n_estimators=100)))
models.append(('Logistic Regression', LogisticRegression()))


# evaluate each model in turn
results = []
names = []

for name, model in models:
    kfold = model_selection.KFold(n_splits=10, random_state = 8)
    cv_results = model_selection.cross_val_score(model, X_train, y_train, cv=kfold, scoring=scoring)

здесь обратная связь за ошибку:

/usr/local/lib/python3.6/dist-packages/scipy/sparse/base.py in __bool__(self)
    285             return self.nnz != 0
    286         else:
--> 287             raise ValueError("The truth value of an array with more than one "
    288                              "element is ambiguous. Use a.any() or a.all().")
    289     __nonzero__ = __bool__
...