- 今天在处理一个多标签分类问题的时候,采用了自适应算法的建模策略。初始化MLkNN模型,
拟合训练集'X_train, Y_train'之后,得到报错信息如下:
'DataFrame' object has no attribute 'getformat'
# 原因是参数数据类型不对,API要求参数类型为array,而我原始代码fit()的参数为DataFrame类型;
X : array-like of shape (n_samples, n_features)
Training vector, where n_samples is the number of samples and
n_features is the number of features.
y : array-like of shape (n_samples, n_output) or (n_samples,), default=None
Target relative to X for classification or regression;
None for unsupervised learning.
- 修改后的代码,运行无误;这里将参数通过np.array转为array格式。


本文讲述了在处理多标签分类问题时遇到的数据类型错误,即在使用MLkNN模型时输入参数应为array而非DataFrame。作者详细描述了错误信息,并解释了API对输入参数的要求。为解决此问题,作者将DataFrame转换为array类型,成功避免了错误并确保了模型的正常运行。这个案例展示了在机器学习实践中正确处理数据类型的重要性。
1242





