在练习简单线性回归模型时,我遇到了这个错误,我认为我的数据集有问题。
这是错误体:
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) 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)