我正在尝试用Seaborn绘制T-SNE约简矢量。我有以下代码:
import pandas as pd
import numpy as np
import seaborn as sns
from sklearn.manifold import TSNE
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
tsne = TSNE(n_components=2, verbose=1, perplexity=40, n_iter=300)
tsne_results = tsne.fit_transform(final_data)
df_subset = pd.DataFrame(columns = ['tsne-2d-one', 'tsne-2d-two'])
df_subset['tsne-2d-one'] = tsne_results[:,0]
df_subset['tsne-2d-two'] = tsne_results[:,1]
plt.figure(figsize=(16,10))
sns.scatterplot(
x="tsne-2d-one", y="tsne-2d-two",
hue="y",
palette=sns.color_palette("hls", 10),
data=df_subset,
legend="full")
从上面的代码中可以看到,似乎来自seaborn lib的散点图需要Panda.DataFrame输入,所以基本上我以这种方式将其初始化为空
df_subset = pd.DataFrame(columns = ['tsne-2d-one', 'tsne-2d-two'])
然后,我基本上将此数据帧的列分配给每个TSNE维度
df_subset['tsne-2d-one'] = tsne_results[:,0]
df_subset['tsne-2d-two'] = tsne_results[:,1]
我可以毫无问题地打印这些值。
但是,当我运行代码时,这是我得到的:
File "balance-training.py", line 59, in <module>
legend="full")
File "/home/server/.local/lib/python3.6/site-packages/seaborn/relational.py", line 1335, in scatterplot
alpha=alpha, x_jitter=x_jitter, y_jitter=y_jitter, legend=legend,
File "/home/server/.local/lib/python3.6/site-packages/seaborn/relational.py", line 852, in __init__
x, y, hue, size, style, units, data
File "/home/server/.local/lib/python3.6/site-packages/seaborn/relational.py", line 142, in establish_variables
raise ValueError(err)
ValueError: Could not interpret input 'y'
我在这里想念什么?