小编Ram*_*yal的帖子

SVR 模型 --> 特征缩放 - 预期的 2D 阵列,而是得到 1D 阵列

我试图了解下面的代码有什么问题。我知道Y变量是1D数组,预计是2D数组,需要重塑结构,但该代码以前工作正常,但有警告。

# Importing the libraries
  import numpy as np
  import matplotlib.pyplot as plt
  import pandas as pd

# Importing the dataset
  dataset = pd.read_csv('Position_Salaries.csv')
  X = dataset.iloc[:, 1:2].values
  y = dataset.iloc[:, 2].values



# Feature Scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_y = StandardScaler()
X = sc_X.fit_transform(X)
y = sc_y.fit_transform(y)
Run Code Online (Sandbox Code Playgroud)
ValueError: Expected 2D array, got a 1D array instead:
array=[  45000.   50000.   60000.   80000.  110000.  150000.  200000.  300000.
  500000. 1000000.].
Reshape your data …
Run Code Online (Sandbox Code Playgroud)

python pandas scikit-learn

8
推荐指数
1
解决办法
6697
查看次数

标签 统计

pandas ×1

python ×1

scikit-learn ×1