Home > OS >  transfering list of result to a barplot
transfering list of result to a barplot

Time:10-29

I generated a list of result in machine learning, and I want to put these result to a bar chart like this Barplot

I am struggling with how should I set up the data frame or transfer the result to the barplot directly?

euclidean ward
silhouette 0.05
completeness 0.1
homogeneity 0.3
euclidean complete
silhouette 0.09
completeness 0.1
homogeneity 0.1
euclidean average
silhouette 0.1
completeness 0.1
homogeneity 0.01
manhattan complete
silhouette 0.05
completeness 0.1
homogeneity 0.2
manhattan average
silhouette 0.1
completeness 0.1
homogeneity 0.1
cosine complete
silhouette -0.01
completeness 0.1
homogeneity 0.2
cosine average
silhouette -0.09
completeness 0.2
homogeneity 0.2

CodePudding user response:

If you set up the dataframe such that the index is the metric name (i.e. "cosine average", "euclidean ward"), and you have the 3 columns - "silhouette", "completeness" and "homogeneity", then you could simply do df.plot.bar() to get the desired result.

> df

                    silhouette  completeness
euclidean ward            0.05           0.1
euclidean complete        0.09           0.1
euclidean average         0.10           0.1
manhattan complete        0.05           0.1
manhattan average         0.10           0.1
cosine complete          -0.01           0.1
cosine average           -0.09           0.2
df.plot.bar(rot=45)
plt.tight_layout()
plt.show()
  • Related