【发布时间】:2018-07-05 18:57:03
【问题描述】:
我正在尝试在数据集上使用我的机器学习模型,其中我只有两列,而标准缩放它们时,我得到了预期的 2D 数组的错误,但得到了 1。
下面是代码:
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
# Splitting the dataset into the Training set and Test set
"""from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)"""
# 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)
# Fitting SVR to the dataset
from sklearn.svm import SVR
regressor = SVR(kernel = 'rbf')
regressor.fit(X, y)
# Predicting a new result
y_pred = regressor.predict(6.5)
y_pred = sc_y.inverse_transform(y_pred)
# Visualising the SVR results
plt.scatter(X, y, color = 'red')
plt.plot(X, regressor.predict(X), color = 'blue')
plt.title('Truth or Bluff (SVR)')
plt.xlabel('Position level')
plt.ylabel('Salary')
plt.show()
当我尝试放
y = sc_y.fit_transform([y])
像这样我没有收到任何错误,但是当我执行接下来的 3 行时,我收到另一个错误。
这是bad input shape (1, 10)
谁能帮我解决这个问题?
【问题讨论】:
-
两列都输入吗?
-
不,X是输入值,y是实际输出...
标签: python arrays machine-learning scikit-learn svm