Как построить график данных только с 2 столбцами (text и int)? - PullRequest
0 голосов
/ 26 января 2019
   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

У меня есть дата кадра обзоров фильмов, и я предсказал столбец метки (1-положительный, 0-отрицательный отзыв), используя kmeans.labels_.Как визуализировать / изобразить вышесказанное?

Желаемый результат: точечный график 1 и 0

Пробный код:

colors = ['red', 'blue']
pred_colors = [colors[label] for label in km.labels_]
import matplotlib.pyplot as plt
%matplotlib inline
plt.scatter(x='index',y='label',c=pred_colors)

Вывод: график с красной точкой нацентр

1 Ответ

0 голосов
/ 27 января 2019

enter image description here

Этот график получен из: 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()
...