python - Yellowbrick t-SNE 拟合引发 ValueError

标签 python visualization yellowbrick

我正在尝试使用 Yellowbrick 包中的 t-SNE 来可视化数据。我收到一个错误。

import pandas as pd
from yellowbrick.text import TSNEVisualizer
from sklearn.datasets import make_classification

## produce random data
X, y = make_classification(n_samples=200, n_features=100,
                       n_informative=20, n_redundant=10,
                       n_classes=3, random_state=42)

## visualize data with t-SNE
tsne = TSNEVisualizer()
tsne.fit(X, y)
tsne.poof()

错误(由 fit 方法引发):

ValueError: The truth value of an array with more than one element
             is ambiguous. Use a.any() or a.all()

最佳答案

在对这些参数进行一些实验之后:

tsne.fit(X, y.tolist())

这不会引发错误,但不会产生输出。

最后,用字符串列表替换是可行的:

y_series = pd.Series(y, dtype="category")
y_series.cat.categories = ["a", "b", "c"]
y_list = y_series.values.tolist()

tsne.fit(X, y_list)
tsne.poof()

该库旨在分析文本数据集,也许这就是它不是 documented 的原因。 y 必须是字符串。此外,错误消息没有帮助。

关于python - Yellowbrick t-SNE 拟合引发 ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48950135/

相关文章:

r - 为什么 geom_abline 不尊重 scales_x_reverse?

python - 如何调整matplotlib图表图形

python - 如何在黄砖图中设置图形大小?

python - YellowBrick 导入错误 : cannot import name 'safe_indexing' from 'sklearn.utils'

python - Django 项目结构,跨应用程序共享扩展 auth "User"模型的推荐结构?

python - 从 postman : CSRF verification failed 运行 django api

python - 运行 .detector (openCV) 时内核死机

wolfram-mathematica - Mathematica 北美 map

python - 如何使打开的 STL 文件防水

Java可视化库称为 "C-BOMB"之类的?我想我听错了