python - ValueError:模型的特征数量必须与输入匹配。模型 n_features 为 3,输入 n_features 为 2
问题描述
我一直在尝试修复它,但无法理解事实。我该如何解决?
ValueError: Number of features of the model must match the input. Model n_features is 3 and input n_features is 2
我的代码:
import pandas as pd
from sklearn.tree import DecisionTreeClassifier
from sklearn.externals import joblib
# music_data = pd.read_csv('music.csv')
# X = music_data.drop(columns = ['genre'])
# y = music_data['genre']
# concat_music_data = pd.concat([y])
# model = DecisionTreeClassifier()
# model.fit(X, y)
model = joblib.load('music-recommender.joblib')
predictions = model.predict([[21, 1]])
predictions
解决方案
您只将 2 个功能传递给您的 predict 方法。该模型需要 3 个特征。
推荐阅读
- python - 是否可以使用 Flask 在服务器请求之间共享复杂对象?
- batch-file - 检查字符串中的文本
- python - 我如何刮多个
s 下多个
- azureservicebus - 是否可以将 Azure 服务总线与 Azure AD(不是 ADFS)一起使用来公开 AX 2012 服务?
- pandas - 使用该方法后,我在 Dataframe 中的列已更改位置
- arrays - 如何改进或索引 postgresql 的 jsonb 数组字段?
- javascript - 音频在没有可视化的情况下播放
- swift - SwiftUi 表在第一次点击时是空白的,但之后可以正常工作
- excel - 强制宏在特定时间 VBA 后停止
- ios - 即使使用正确的标识符,视图控制器也不会通过 instanceViewController 函数加载