What’s the problem? The model is trained on the same data, but predicts nothing. An error appears
ValueError: The truth value of an array with more than one element is ambiguous.Use a.any () or a.all ()
Was saving data to DataFrame, but still error.
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool (), a.item (), a.any () or a.all ().
Answer 1, authority 100%
The dt.predict(X, check_input=True)
method expects two arguments – a matrix of values from which predictions will be made and a check_input
boolean flag. You passed an array of valid values as the second parameter instead of a scalar value. In the code dt.predict
there is a check if check_input:
– an exception will be thrown on this line of code, because the construction if np.array([1, 0, 0, 2])
– cannot be unambiguously checked.
It makes no sense to pass the well-known answer to dt.predict()
– y_test
.
The correct way to do this:
predicted = dt.predict(X_test)
If you want to check the accuracy of predictions, you can use the .score()
:
In [5]: dt.score(X_test, y_test)
Out[5]: 0.9473684210526315