小编dan*_*han的帖子

ValueError:预期的2D数组,而是1D数组:

在练习简单线性回归模型时,我遇到了这个错误,我认为我的数据集有问题。

这是我的数据集:

这是自变量X:

这是因变量Y:

这是X_train

这是Y_train

这是错误体:

ValueError: Expected 2D array, got 1D array instead:
array=[ 7.   8.4 10.1  6.5  6.9  7.9  5.8  7.4  9.3 10.3  7.3  8.1].
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.
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

import pandas as pd
import matplotlib as pt

#import data set

dataset = pd.read_csv('Sample-data-sets-for-linear-regression1.csv')
x = dataset.iloc[:, 1].values
y = dataset.iloc[:, 2].values

#Spliting the dataset into Training set …
Run Code Online (Sandbox Code Playgroud)

linear-regression python-3.x scikit-learn

6
推荐指数
4
解决办法
1万
查看次数

TypeError: fit_transform() missing 1 required positional argument: 'X'

I am trying to do Feature Scaling in a dataset, but I get an error and have no idea how to proceed:

    > Traceback (most recent call last):
    > 
    >   File "<ipython-input-10-71bea414b4d0>", line 22, in <module>
    >     x_train = sc_X.fit_transform(x_train)
    > 
    > TypeError: fit_transform() missing 1 required positional argument: 'X'
Run Code Online (Sandbox Code Playgroud)

and here is my code:

import pandas as pd

# Importing the dataset
dataset = pd.read_csv('Data.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 3].values
# Taking care of missing data …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

3
推荐指数
1
解决办法
9803
查看次数