Я строю данные, используя matplotlib.Я следую этому примеру в качестве основы для построения четырех меток.Ниже вы можете найти код.Тем не менее, я получаю эту ошибку
Traceback (most recent call last):
File "visualization_SH_Male_female.py", line 86, in <module>
main()
File "visualization_SH_Male_female.py", line 58, in main
plt.scatter(x_list[indices], y_list[indices], marker=markers[i], color=colors[j])
TypeError: list indices must be integers or slices, not list
на этом графике рассеяния.Может кто-нибудь указать, как я могу преобразовать indices
в целые числа?
import matplotlib
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
import csv
import numpy as np
from sklearn import preprocessing
def parse_features_from_csv(csv_file):
feat_lst = []
id_lst = []
count = 0
with open(csv_file) as fr:
reader = csv.reader(fr, delimiter=',')
for row in reader:
s_feat = row[:-1]
identifier = row[-1]
if count < 50:
if (
identifier == 'Alan_Cumming' or identifier == 'Chiwetel_Ejiofor' or identifier == 'James_Purefoy' or identifier == 'Johnathon_Schaech' or identifier == 'Will_Poulter'):
identifier = 0
else:
identifier = 2
else: # >= 50
if (
identifier == 'Alan_Cumming' or identifier == 'Chiwetel_Ejiofor' or identifier == 'James_Purefoy' or identifier == 'Johnathon_Schaech' or identifier == 'Will_Poulter'):
identifier = 1
else:
identifier = 3
s_feat = [float(i) for i in s_feat]
feat_lst.append(s_feat)
id_lst.append(identifier)
count += 1
return feat_lst, id_lst
def main():
face_file = 'comb.csv'
feat_lst, labels = parse_features_from_csv(face_file)
labels = np.array(labels)
X_embedded = TSNE(n_components=2).fit_transform(feat_lst)
x_list = [x for [x, y] in X_embedded]
y_list = [y for [x, y] in X_embedded]
# generate a list of markers and another of colors
markers = ["o", "<"]
colors = ['r', 'g']
for i in range(2):
for j in range(2):
lab = i + j
indices = list(map(int, labels == lab))
print(indices)
plt.scatter(x_list[indices], y_list[indices], marker=markers[i], color=colors[j])
plt.legend(['0', '1', '2', '3'])
plt.grid()
plt.show()