我正在尝试修复我的代码。这是我的错误:
文件 “ C:\ Users \ COMPAQ \ Anaconda3 \ lib \ site-packages \ sklearn \ utils \ validation.py”, 第235行,在check_consistent_length中 “样本:%r”%[长度为l的int(l)])
ValueError:找到数量不一致的输入变量 样本:[120,1]
这是我的代码:
import pandas as pd
d = pd.read_csv('dataset.csv')
x=d.drop(['Y','SampleNo','x4','x6'], axis=1)
y=d['Y'].values.reshape(1, -1)
from sklearn.preprocessing import Imputer
imputer= Imputer(missing_values='NaN', strategy = 'mean', axis=0 )
imputer = imputer.fit(y)
y = imputer.transform(y)
print(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.values.reshape(-1, 1),y.values.reshape(-1, 1))
regressor.predict([[5.5]])
y_pred = regressor.predict(x_test)
print(y_pred)
有人可以帮我找出这段代码有什么问题吗?