1

我曾尝试在 jupyter notebook 和 colab 中运行,但仍然收到 fcmeans 的此错误。但它在不同的笔记本电脑上运行良好。 这是用于拆分数据集的代码

# Stratified Sampling using Scikit-learn's Stratified Shuffle Split Class
from sklearn.model_selection import StratifiedShuffleSplit

split = StratifiedShuffleSplit(n_splits=1, test_size=0.25, random_state=42)

for train_index, test_index in split.split(data1, data1["class"]):
    strat_train_set = data1.loc[train_index]

    strat_test_set = data1.loc[test_index]
    train_set = strat_train_set.drop("class", axis=1) # drop labels for training set

train_labels = strat_train_set["class"].copy()
test_set = strat_test_set.drop("class", axis=1) # drop labels for testing set
test_labels = strat_test_set["class"].copy()

那我在这里想念什么?

在此处输入图像描述

4

1 回答 1

1

这里的问题是,tr_set不是numpy.ndarray. 因此,您需要做的就是将数据帧作为 numpy 数组传递。

在您的情况下,如果to_numpy在将数据传递给fit(像这样fcm.fit(tr_set.to_numpy()))之前使用函数,它将起作用。

从 fcm 文档中可以清楚地看到这一点。

于 2021-09-10T09:50:05.217 回答