scikit learn target variable reversed (DecisionTreeClassifier) I created a Decision Tree Classifier using sklearn, defined the target variable:
#extract features and target variables
x = df.drop(columns=&quot;target_column&quot;,)
y = df[&quot;target_column&quot;]
#save the feature name and target variables
feature_names = x.columns
labels = y.unique()
#split the dataset
from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x,y, test_size = 0.3, random_state = 42)

Additionally I checked the count of each of the two classes (Success, Failure) within y which confirmed to me that each has the correct count.
Then I fitted my DTClassifier:
clf = DecisionTreeClassifier(
    criterion='gini',
    splitter='best',
    max_depth=None,
    min_samples_split=2,
    min_samples_leaf=1,
    min_weight_fraction_leaf=0.0,
    max_features=None,
    random_state=42,
    max_leaf_nodes=None,
    min_impurity_decrease=0.0,
    min_impurity_split=None,
    #class_weight=&quot;balanced&quot;,
    presort='deprecated',
    ccp_alpha=0.0,
)
clf.fit(x_train, y_train)

The problem becomes apparent at the visualization step when I plotted the tree, each node shows me class = Failure when Failure is the minority and vice versa. Further down the line plotting the confusion matrix and calculating all the performance metrics it also becomes apparent, that the labels were reversed and I cannot figure out as to why.
Any ideas where I might need to look for the answer? If more code is necessary to give a feedback I can provide.
Much appreciated.
It might be because of the conflict of order between model.classes_ and series.unique()
For a binary labels,
model.classes_ = array([0, 1])
series.unique() = array([1, 0])
Try creating a constant value i.e. np.array[0,1] for labels and see.