首页 > 解决方案 > 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

标签: pythonpandasscikit-learn

解决方案


您只将 2 个功能传递给您的 predict 方法。该模型需要 3 个特征。


推荐阅读