app.get('/:urlToForward', (req, res, next)=>{ ...
我有一个电影评论的数据框,并使用kmeans.labels_预测了标签栏(1-阳性,0阴性的评论)。如何可视化/绘制以上内容?
所需的输出:1和0的散点图
尝试的代码:
index reviews label
0 0 i admit the great majority of... 1
1 1 take a low budget inexperienced ... 0
2 2 everybody has seen back to th... 1
3 3 doris day was an icon of b... 0
4 4 after a series of silly fun ... 0
输出:在中心有一个红点的图
答案 0 :(得分:0)
此图来自: http://www3.ntu.edu.sg/home/ehchua/programming/webprogramming/Python4_DataAnalysis.html
您没有要在x轴上绘制的值,因此我们可以简单地使用索引。 评论可以作为另一列添加到数据中。
import pandas as pd
from matplotlib import pyplot as plt
data = [1,0,1,0,0]
df = pd.DataFrame(data, index=range(5), columns=['label'])
#
# line plot
#df.reset_index().plot(x='index', y='label') # turn index into column for plotting on x-axis
#
# scatter plot
ax1 = df.reset_index().plot.scatter(x='index', y='label', c='DarkBlue')
#
plt.tight_layout() # helps prevent labels from being cropped
plt.show()