When the sklearn model is referenced and the model is evaluated after fit, the error occurs. The code is as follows:
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import f1_score
regressor = DecisionTreeClassifier(random_state=42)
regressor.fit(X_train,y_train)
y_pred = regressor.predict(X_test)
print(f1_score(y_pred,y_test))
After running, it appears:
target is multiclass but average='binary'. please choose another average setting.
In fact, there is no problem with the code. The problem lies in the data type, y here_ The values in test are not binary of 0 and 1, but [123, 23142243 ]Therefore, in essence, it is impossible to carry out hair care_ Score calculation, you will find that if F1_ Change score to accuracy_ Score, the return result is 0
so to predict y of this kind of value type, other evaluation indicators, such as R 2, are needed. The code is as follows:
from sklearn.tree import DecisionTreeClassifier
from sklearn.metrics import r2_score
regressor = DecisionTreeClassifier(random_state=42)
regressor.fit(X_train,y_train)
# TODO: output predicted scores on the test set
y_pred = regressor.predict(X_test)
print(r2_score(y_pred,y_test))
result:
0.12800402751210926