yellowbrick tSNE fit提高价值

2024-05-16 02:40:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图用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()

错误(由拟合方法引发):

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

Tags: 数据fromimportdatamake可视化错误with
1条回答
网友
1楼 · 发布于 2024-05-16 02:40:55

在对这些论点进行了一些实验之后:

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()

这个库是用来分析文本数据集的,也许这就是为什么y不需要是字符串的原因。此外,错误消息也没有帮助。你知道吗

相关问题 更多 >