Issue
Let's consider the data following:
accuracies_in = ([0.5959219858156029, 0.5736842105263158, 0.5670212765957447, 0.3])
accuracies_out = [0.5, 0.6041666666666666, 0.2, 0.4]
auc_out = [0.5182608695652174, 0.6095652173913042, 0.5, 0.7]
algorithm = ["Logistic Regression", "Decision Tree", "Random Forest", "Neural Network"]
frame = pd.DataFrame([accuracies_in, accuracies_out, auc_out])
frame.index = ["accuracies_in", "accuracies_out", "auc_out"]
frame.columns = algorithm
I want to have a barplot which will show results for those three characteristics (accuracies_in
, accuarcies_out
and auc_out
). In other words on the barplot I want to group barplots more or less like this:
The first group (first row - accuracy_in
) will contain four bars - accuracies_in
for Logistic Regression, Decision Tree, Random Forest and Neural Network. Second group of bars will contain again four bars but this time for second row - accuracies_out
. And lastly - the third group of bars will contain four bars with auc_out
in each of them.
Could you please help me how it can be done? I searched a lot of questions but I couldn't find anything which will plot barplots with respect to rows. Could you please give me a hand in this problem?
Solution
You need to convert your dataframe to long form, using pd.melt
.
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
# frame: given dataframe
df = frame.melt(var_name='Algorithm', value_name='Accuracy', ignore_index=False)
sns.set()
sns.barplot(data=df, x=df.index, y='Accuracy', hue='Algorithm')
Answered By - JohanC
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.