目标的缩放导致Scikit-learn SVM回归分解

 哥这么好的人你去哪找 发布于 2022-12-24 21:22

在训练SVM回归时,通常建议在训练之前缩放输入要素.

但是如何扩展目标呢?通常这不是必要的,我认为没有必要为什么这么做.

但是,在scikit-learn示例中,SVM回归来自:http: //scikit-learn.org/stable/auto_examples/svm/plot_svm_regression.html

通过在训练之前引入线y = y/1000,预测将分解为恒定值.在训练之前缩放目标变量可以解决问题,但我不明白为什么有必要.

是什么导致这个问题?

import numpy as np
from sklearn.svm import SVR
import matplotlib.pyplot as plt

# Generate sample data
X = np.sort(5 * np.random.rand(40, 1), axis=0)
y = np.sin(X).ravel()

# Add noise to targets
y[::5] += 3 * (0.5 - np.random.rand(8))

# Added line: this will make the prediction break down
y=y/1000

# Fit regression model
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin = SVR(kernel='linear', C=1e3)
svr_poly = SVR(kernel='poly', C=1e3, degree=2)
y_rbf = svr_rbf.fit(X, y).predict(X)
y_lin = svr_lin.fit(X, y).predict(X)
y_poly = svr_poly.fit(X, y).predict(X)

# look at the results
plt.scatter(X, y, c='k', label='data')
plt.hold('on')
plt.plot(X, y_rbf, c='g', label='RBF model')
plt.plot(X, y_lin, c='r', label='Linear model')
plt.plot(X, y_poly, c='b', label='Polynomial model')
plt.xlabel('data')
plt.ylabel('target')
plt.title('Support Vector Regression')
plt.legend()
plt.show()

Fred Foo.. 10

支持向量回归使用损失函数,如果预测值与目标之间的差异超过某个阈值,则该函数仅为正值.低于阈值,预测被认为是"足够好"并且损失为零.缩小目标时,SVM学习者可以放弃返回平面模型,因为它不会再造成任何损失.

该阈值参数被称为epsilonsklearn.svm.SVR; 为较小的目标设置较低的值.这里解释了这背后的数学.

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有