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
Read More:
- [Solved] pytorch CrossEntropyLoss Error: RuntimeError: 1D target tensor expected, multi-target not supported
- AUC Error – ValueError: Data is not binary and pos_label is not specified
- [Solved] Android Studio Error: The binary version of its metadata is 1.5.1, expected version is 1.1.15.
- [Solved] Message from debugger: debug-server is x86_64 binary running in translation, attached failed.
- [Solved] CMake Error Cannot specify link libraries for target “variational“ which is not built by this projec
- [Solved] (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk.
- It can be opened with localhost, but not with IP address. The request host name is invalid
- How to Solve Element Error: target is not existed: .page-component__scroll .el-scrollbar__wrap
- Vscode pylint reported an error of “no member”, but it is running normally
- Json: struct field readyReplicas has json tag but is not exported [How to Solve]
- VUE: Property or method “deleteFun“ is not defined on the instance but referenced during render. [How to Fix]
- [Error] invalid operands to binary ^ (have ‘double‘ and ‘float‘)
- When installing zookeeper, you can view the process start, but the status display error: Error contacting service. It is probably not running
- [Solved] RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of s
- There is no error when compiling and packaging the IDEA code, but the code displays an error
- [Solved] Cmake compile opencv open-source project Error: but it set OpenCV_FOUND to FALSE so package “OpenCV” is considered to be…
- [Solved] TFrecords Create Datas Error: Number of int64 values != expected. Values size: 1 but output shape: [3]
- [Solved] ERROR: Attempting to operate on hdfs journalnode as rootERROR: but there is no HDFS_JOURNALNODE_USE
- [Solved] MySQL workbench Error: SSL connection error: SSL is required but the server doesn‘t support it.
- [Solved] Matlab Code generate error: failed to generate all binary outputs