在fuzzy-c-means中遇到验证错误

我在jupyter notebook和colab上都尝试运行过,但仍然在fcmeans上遇到这个错误。然而,在另一台笔记本电脑上运行正常。这是用于分割数据集的代码

# 使用Scikit-learn的分层shuffle拆分类进行分层抽样
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) # 丢弃训练集的标签
    train_labels = strat_train_set["class"].copy()
    test_set = strat_test_set.drop("class", axis=1) # 丢弃测试集的标签
    test_labels = strat_test_set["class"].copy()

那么我在这里遗漏了什么呢?

enter image description here


回答:

问题在于,tr_set不是numpy.ndarray。所以你需要做的就是将数据框作为numpy数组传递。

在你的情况下,如果在传递数据到fit之前使用to_numpy函数(就像这样fcm.fit(tr_set.to_numpy())),它就会工作。

这在fcm文档中已经非常清楚了。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注