【发布时间】:2020-08-03 17:24:13
【问题描述】:
我正在使用 SVR 来预测 NBA 幻想得分。我的 indep 变量添加到我的 dep 变量中。
import numpy as np
import pandas as pd
X 是一个 58 行 x 9 列的数组。 9列之和=第10列(Y)
DK = pd.read_csv('NV.csv')
X = DK.iloc[:, :-1].values.astype(float)
Y = DK.iloc[:,9].values.astype(float).reshape(-1,1)
#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 data and creating regressors
from sklearn.svm import SVR
regressor1 = SVR(kernel='rbf')
regressor1.fit(X,Y)
当我运行上述程序时,我得到一个数据警告和以下输出
DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
y = column_or_1d(y, warn=True)
SVR(C=1.0, cache_size=200, coef0=0.0, degree=3, epsilon=0.1, gamma='auto',
kernel='rbf', max_iter=-1, shrinking=True, tol=0.001, verbose=False)
预测新结果是我的代码遇到障碍的地方
y_pred = sc_y.inverse_transform((regressor1.predict(sc_X.transform(np.array([[6.5]])))))
这将返回以下错误。问题是我如何拟合/缩放数据还是完全不同的问题?
ValueError Traceback (most recent call last)
<ipython-input-63-9c7f8b557a70> in <module>
----> 1 y_pred = sc_y.inverse_transform((regressor1.predict(sc_X.transform(np.array([[1.9]])))))
~\Anaconda\lib\site-packages\sklearn\preprocessing\data.py in transform(self, X, copy)
767 else:
768 if self.with_mean:
--> 769 X -= self.mean_
770 if self.with_std:
771 X /= self.scale_
ValueError: non-broadcastable output operand with shape (1,1) doesn't match the broadcast shape (1,9)
【问题讨论】:
-
我也有点困惑,为什么您要使用机器学习来预测您创建的计算度量。
标签: python numpy scikit-learn svm