缩放LIBSVM的测试数据:MATLAB实现 [英] scaling the testing data for LIBSVM: MATLAB implementation

查看:119
本文介绍了缩放LIBSVM的测试数据:MATLAB实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前使用LIBSVM支持向量机的MATLAB版本对数据进行分类. LIBSVM文档提到在应用SVM之前进行缩放非常重要,我们必须使用相同的方法来对训练和测试数据进行缩放.

I currently use the MATLAB version of the LIBSVM support vector machine to classify my data. The LIBSVM documentation mentions that scaling before applying SVM is very important and we have to use the same method to scale both training and testing data.

相同的缩放方法"解释为: 例如,假设我们将训练数据的第一个属性从[-10, +10]缩放到[-1, +1].如果测试数据的第一个属性在[-11, +8]范围内,则必须将测试数据缩放到[-1.1, +0.8]

The "same method of scaling" is explained as: For example, suppose that we scaled the first attribute of training data from [-10, +10] to [-1, +1]. If the first attribute of testing data lies in the range [-11, +8], we must scale the testing data to [-1.1, +0.8]

可以使用以下MATLAB代码在[0,1]范围内缩放训练数据:

Scaling the training data in the range of [0,1] can be done using the following MATLAB code :

(data - repmat(min(data,[],1),size(data,1),1))*spdiags(1./(max(data,[],1)-min(data,[],1))',0,size(data,2),size(data,2))

但是我不知道如何正确缩放测试数据.

But I don't know how to scale the testing data correctly.

非常感谢您的帮助.

推荐答案

您提供的代码本质上是减去最小值,然后除以范围. 您需要存储训练数据功能的最小值和范围.

The code you give is essentially subtracting the minimum and then dividing by the range. You need to store the minimum and range of the training data features.

minimums = min(data, [], 1);
ranges = max(data, [], 1) - minimums;

data = (data - repmat(minimums, size(data, 1), 1)) ./ repmat(ranges, size(data, 1), 1);

test_data = (test_data - repmat(minimums, size(test_data, 1), 1)) ./ repmat(ranges, size(test_data, 1), 1);

这篇关于缩放LIBSVM的测试数据:MATLAB实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆