ValueError:模型的特征数量必须与输入匹配。模型n_features为4,输入n_features为1

时间:2019-05-05 07:37:10

标签: machine-learning decision-tree python-3.7

第三季度

文件“ C:\ Users \ COMPAQ \ Anaconda3 \ lib \ site-packages \ sklearn \ tree \ tree.py”,第388行,在_validate_X_predict中     %(self.n_features_,n_features))

ValueError:模型的特征数量必须与输入匹配。模型n_features是4,输入n_features是1

您能帮我解决这个错误吗? tnx

import pandas as pd

d = pd.read_csv('dataset100.csv')

x=d.drop(['Y','SampleNo','x4','x6'], axis=1)
y=d['Y']

from sklearn.model_selection import train_test_split
x_train, x_test,y_train,y_test = train_test_split(x,y,test_size=0.33, random_state=0)

from sklearn.tree import DecisionTreeRegressor
regressor = DecisionTreeRegressor()   # random sate = 0
regressor.fit(x,y)

regressor.predict([[5.5]])

y_pred = regressor.predict(x_test)
print(y_pred)

0 个答案:

没有答案