I would like to print the f1-score. I got confused about the wording f1-accuracy score and accuracy score. What is the difference of these 2 scikit-learn metrics and how can I print the f1-score out of this code?

from xgboost import XGBClassifier
from sklearn.metrics import accuracy_score, classification_report
from sklearn.model_selection import train_test_split
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split

df = pd.read...path
X = df.drop('pricing_class', axis=1)
y = df.pricing_class

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)

xgb_classification = XGBClassifier(random_state=42)

print('accuracy_score',accuracy_score(xgb_results, y_test))

this is a test sample:

enter image description here

Question 1: There is under the column f1-score the row of accuracy. Is this the f1-score of the scikit-learn classification report? or is this the accuracy score?

I have the feeling, that this value is the rounded value of the accuracy_score the line below (when I use full dataset).

Question 2: How can I print the f1-score?


1 Answer 1


Use f1_score instead of the classification report:

from sklearn.metrics import f1_score


print('f1_score', f1_score(xgb_results, y_test))
  • $\begingroup$ thanks this leads to my next question. I will make a new post. if it is possible to compare f1 'micro' out of models which are imbalanced, and not imbalanced because of smote. $\endgroup$
    – martin
    Oct 19, 2020 at 13:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.