After executing this code, y_pred is way too high
I have tried my code
import numpy as py
import matplotlib.pyplot as plt
import pandas as pd
dataset = pd.read_csv('Position_Salaries.csv')
X = dataset.iloc[:,1:2].values
y= dataset.iloc[:, 2].values
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
sc_y = StandardScaler()
X = sc_X.fit_transform(X)
y= sc_y.fit_transform(y.reshape(-1,1))
# 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)
Why is the value of y_pred so high? is there some mistake in my code
I found the solution:
Instead of line 31 and 32, I need to use
y_pred = sc_y.inverse_transform(regressor.predict(sc_X.transform(np.array([[6.5]))))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.