Scalling and unscalling of data for SVR prediction
I'm trying to use SVR to predict a certain feature. I create the model with the following code:
from sklearn.svm import SVR
from sklearn.preprocessing import StandardScaler
X = data
# this is the outcome variable
y = data.iloc[:, 10].values
sc_X = StandardScaler()
sc_y = StandardScaler()
X2 = sc_X.fit_transform(X)
y = sc_y.fit_transform(y.reshape(-1, 1))
# my_custom_kernel looks at certain columns of X2 / scaled data
my_regressor = SVR(kernel=my_custom_kernel)
my_regressor = regressor.fit(X2, y)
After creating the model, I want to test it to see if the prediction is good. The first thing the code does is scale the row that I want to test, using the same scaler as above (sc_X
). Then I try to reverse the scaling of the prediction result (using sc_y
). During this process, I get datatype errors. Here is the code:
line1 = X.iloc[0].as_matrix().reshape(1, -1)
line1_scaled = sc_X.fit_transform(line1)
res = regressor.predict (line1_scaled)
pred_line1 = sc_y.inverse_transform (res) # The error appears to be here
Error:
ValueError: non-broadcastable output operand with shape (1,) doesn't match the broadcast shape (24,)
Thanks.
Topic svr reshape jupyter feature-scaling python
Category Data Science