Today, when compiling Python code, we encountered the following error:
target is multiclass but average =’binary ‘. Please choose another average setting, one of [none,’ micro ‘,’ macro ‘,’ weighted ‘]
The original code is as follows, is to require a data set of F1 (precision and recall combined into a single index).
from sklearn.metrics import precision_score, recall_score
precision_score(y_train, y_train_pred)
terms of settlement
Average =’micro’is added to the original code.
from sklearn.metrics import precision_score, recall_score
precision_score(y_train, y_train_pred, average='micro')
The average parameter defines the calculation method of the index. In binary classification, the average parameter is binary by default; in multi classification, the optional parameters are micro, macro, weighted and samples.
None: returns the score of each class. Otherwise, this determines the average type of execution on the data.
Binary: only report the result POS of the specified class_ label。 Only if targets (Y_ Only when {true, PRED}) is binary.
Micro: global indicators are calculated by calculating total true positives, false negatives and false positives. That is to say, all classes are calculated together (to be specific to precision), and then the TP sum of all classes is divided by the sum of TP and FN of all classes. Therefore, precision and recall in micro method are equal to accuracy.
Macro: calculate the indicators of each tag to find their unweighted average. This does not take into account label imbalance. In other words, the precision of each class is calculated first, and then the arithmetic average is calculated.
Weighted: calculate the indicators of each tag, find their average value, and weight by support (the number of real instances of each tag). This would change the “macro” to address the label imbalance; it could result in an F-score that is not between precision and recall.
Samples: calculate the indicators of each instance and find their average value (only meaningful for different multi label classification)_ score)。
reference resources: https://blog.csdn.net/datongmu_ yile/article/details/81750737
Read More:
- Wrong classification of Python — assertion cur_ Target is greater than or equal to 0 and cur_ Target is less than n_ classes failed
- Python learning notes (5) — cross entropy error runtimeerror: 1D target tensor expected, multi target not supported
- PySpark ERROR Shell: Failed to locate the winutils binary in the hadoop binary path
- An import error is reported in the python. The solution to setting. Pylintrc is invalid
- The binary version of its metadata is 1.5.1, expected version is 1.1.16
- Android studio simulator architecture choose arm or x86 to solve the problem of missing libraryexception
- Error: Target container is not a DOM element.
- “XXXXXX is a” namespace “, but here it is used as a” type “
- Uncaught Error: _registerComponent(…): Target container is not a DOM element
- The key “target densitydpi” is not supported
- IntelliJ idea class is normal, but error is marked in red and cannot be found
- Solve the problem of jdk8 after win7 is installed. Has value ‘1.8’, but ‘1.7’ is required
- Apache [error] server reached MaxClients setting, consider raising the MaxClients setting
- Android studio NDK setting is gray and cannot be solved
- In idea, @ slf4j is used to report an error, but log is not found
- Modification scheme of binary files in dot matrix font library
- (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to
- The file is generated, but an error is still reported. Error: CreateProcess failed
- Property xxx was accessed during render but is not defined on instance
- About java “Error: bad binary operator types”