简体   繁体   English

在SVM中使用特征之前如何在特征上使用L2规范化

[英]How to use L2 normalization on features before using them in SVM

I'm training SVM with features extracted from Convolutional Neural Network. 我正在使用从卷积神经网络中提取的功能来训练SVM。 As written in this paper ( http://arxiv.org/pdf/1405.3531v4.pdf ) it is good to L2-normalize your features before applying SVM on them. 如本文所述( http://arxiv.org/pdf/1405.3531v4.pdf ),在对它们应用SVM之前对它们进行L2归一化是很好的。

I use this function to normalize vectors: 我使用此函数对向量进行归一化:

def l2normalize(features):
    l2norm = np.sum(np.abs(features)**2,axis=-1)**(1./2)
    return features/l2norm

After this normalization my accuracy drops from around 60% to 20% so something is clearly wrong. 归一化后,我的准确度从大约60%下降到20%,因此显然有些错误。 How should I properly prepare my vectors for SVM with L2 norm? 我应该如何正确地为L2规范的SVM准备向量?

  1. Check if you are actually normalizing both the features extracted from training data and the test data. 检查是否你实际上是归无论从训练数据和测试数据中提取的特征。

  2. Try using normalize from sklearn.preprocessing . 尝试从sklearn.preprocessing使用normalize I checked and your function returns slightly different values. 我检查了一下,您的函数返回的值略有不同。

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

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