I created a Decision Tree Classifier using sklearn, defined the target variable:
#extract features and target variables x = df.drop(columns="target_column",) y = df["target_column"] #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="balanced", 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.