【发布时间】:2018-10-29 19:29:39
【问题描述】:
我试图了解下面的代码有什么问题。我知道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)
ValueError: Expected 2D array, got a 1D array instead:
array=[ 45000. 50000. 60000. 80000. 110000. 150000. 200000. 300000.
500000. 1000000.].
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.
【问题讨论】:
标签: python pandas scikit-learn