Python 训练集中的训练数据

Python 训练集中的训练数据,python,scikit-learn,data-science,Python,Scikit Learn,Data Science,Am,尝试使用scikit学习在我的训练集中训练模型,但出现以下错误: ValueError: Expected 2D array, got 1D array instead: array=[90. 4.]. Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.

Am,尝试使用scikit学习在我的训练集中训练模型,但出现以下错误:

 ValueError: Expected 2D array, got 1D array instead: array=[90.  4.].
 Reshape your data either using array.reshape(-1, 1) if your data has a single feature or array.reshape(1, -1) if it contains a single sample.
步骤1:将x和y拆分为训练和测试集 检查新分割x值的形状(培训和测试) 检查新拆分y值的形状(培训和测试) 步骤2:在训练集上训练我们的模型(使用后勤回归)
运行此代码时出现错误似乎您正在用数据点的形状替换数据点:

X_train = X_train.shape
X_test = X_test.shape
y_train = y_train.shape
y_test = y_test.shape
拆下这些管路并重新运行

你们做了很好的工作,但你们做了一件错误的事情:你们用1D的形状替换了火车和测试数据,这就是为什么你们要面对这个错误

X_train = X_train.shape
X_test = X_test.shape
print(X_train)
print(X_test)
y_train = y_train.shape
y_test = y_test.shape
print(y_train)
print(y_test)
logR = LogisticRegression()
logR = logR.fit(X_train, y_train)
X_train = X_train.shape
X_test = X_test.shape
y_train = y_train.shape
y_test = y_test.shape
 #replace these line

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.4, random_state = 4)

print( X_train.shape)
print( X_test.shape)
print(y_train.shape)
print(y_test.shape)

logR = LogisticRegression()
logR = logR.fit(X_train, y_train)

# Now it work fine