I have a Dataframe which consists of some ML models with 2 columns for train & test accuracies respectively
JavaScript
x
12
12
1
evaluations_df
2
Out[13]:
3
Model train_accuracy test_accuracy
4
0 Logistic Regression 100.000000 86.956522
5
1 Decision Tree 99.065421 84.782609
6
2 Random Forest 92.523364 82.608696
7
3 Ada Boosting 100.000000 89.130435
8
4 Gradient Boosting 100.000000 84.782609
9
5 Nearest Neighbors 88.785047 82.608696
10
6 Support Vector Machine 93.457944 82.608696
11
7 Naive Bayes 99.065421 89.130435
12
And I want to plot in similar to to this:
Where the x
value is the number of models where it’s ticks will be replaced by the model names, and the y
value will be a pair of each accuracy metric.
I tried something like:
JavaScript
1
5
1
sns.histplot(data=evaluations_df, x=range(len(evaluations_df)), y=['train_accuracy', 'test_accuracy'],
2
color=['r', 'b'],
3
shrink=0.8,
4
multiple='dodge')
5
But it raises the following error:
JavaScript
1
2
1
ValueError: Length of list vectors must match length of `data` when both are used, but `data` has length 8 and the vector passed to `y` has length 2.
2
I don’t seem to be able to unpack the y
values as a pair of bins with that list.
Advertisement
Answer
Without using seaborn and using just pandas you can do this:
JavaScript
1
2
1
evaluations_df.plot.bar(x='Model', y=['train_accuracy', 'test_accuracy'])
2