简体   繁体   English

支持向量回归

[英]Support vector regression

After executing this code, y_pred is way too high执行这段代码后,y_pred 太高了

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?为什么y_pred的值这么高? is there some mistake in my code我的代码中是否有错误anaconda 控制台图像

I found the solution:我找到了解决方案:

Instead of line 31 and 32, I need to use而不是第 31 和 32 行,我需要使用

y_pred = sc_y.inverse_transform(regressor.predict(sc_X.transform(np.array([[6.5]))))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM