Python 尝试分离训练集和测试集时出现ValueError

Python 尝试分离训练集和测试集时出现ValueError,python,statistics,Python,Statistics,我在python中尝试了以下代码: X=df[["age","bmi","children"]].values.reshape(-1,1) Y=df["charges"].values.reshape(-1,1) from sklearn.preprocessing import MinMaxScaler X_scaler = MinMaxScaler() Y_scaler = MinMaxScaler() X =

我在python中尝试了以下代码:

X=df[["age","bmi","children"]].values.reshape(-1,1)
Y=df["charges"].values.reshape(-1,1)
from sklearn.preprocessing import MinMaxScaler
X_scaler = MinMaxScaler()
Y_scaler = MinMaxScaler()
X = X_scaler.fit_transform(X)
Y = Y_scaler.fit_transform(Y)
X_train, X_test, y_train, y_test = train_test_split(
    X, Y, test_size=0.2, random_state=1)
但它给了我以下错误:

ValueError: Found input variables with inconsistent numbers of samples: [2136, 712]
如果我不进行重塑,它会给我:

ValueError: Expected 2D array, got 1D array instead
所以我不知道该怎么办
如果有人能帮助我,我将不胜感激。

好吧,我找到了一个解决方案,我改变了Y:

Y = Y_scaler.fit_transform(Y.values.reshape(-1,1))

它成功了

在您的问题中添加数据集