特征归一化后 kNN 分类的准确率下降?
Posted
技术标签:
【中文标题】特征归一化后 kNN 分类的准确率下降?【英文标题】:Accuracy rate for kNN classification dropped after feature normalization? 【发布时间】:2016-02-24 20:12:42 【问题描述】:我正在对一些数据进行kNN 分类。我有数据以 80/20 的比例随机拆分用于训练和测试集。 我的数据如下所示:
[ [1.0, 1.52101, 13.64, 4.49, 1.1, 71.78, 0.06, 8.75, 0.0, 0.0, 1.0],
[2.0, 1.51761, 13.89, 3.6, 1.36, 72.73, 0.48, 7.83, 0.0, 0.0, 2.0],
[3.0, 1.51618, 13.53, 3.55, 1.54, 72.99, 0.39, 7.78, 0.0, 0.0, 3.0],
...
]
矩阵最后一列中的项目是类:1.0、2.0 和 3.0 特征标准化后,我的数据如下所示:
[[-0.5036443480260487, -0.03450760227559746, 0.06723230162846759, 0.23028986544844693, -0.025324623254270005, 0.010553065215338569, 0.0015136367098358505, -0.11291235596166802, -0.05819669234942126, -0.12069793876044387, 1.0],
[-0.4989050339943617, -0.11566537753097901, 0.010637426608816412, 0.2175704556290625, 0.03073267976659575, 0.05764598316498372, -0.012976783512350588, -0.11815839520204152, -0.05819669234942126, -0.12069793876044387, 2.0],
...
]
我用于标准化的公式:
(X - avg(X)) / (max(X) - min(X))
我对 K = 1 到 25 中的每一个(仅奇数)执行 kNN 分类 100 次。我记录了使用的每个 K 的平均准确度。 这是我的结果:
Average accuracy for K=1 after 100 tests with different data split: 98.91313003886198 %
Average accuracy for K=3 after 100 tests with different data split: 98.11976006170633 %
Average accuracy for K=5 after 100 tests with different data split: 97.71226079929019 %
Average accuracy for K=7 after 100 tests with different data split: 97.47493145754373 %
Average accuracy for K=9 after 100 tests with different data split: 97.16596220947888 %
Average accuracy for K=11 after 100 tests with different data split: 96.81465365733266 %
Average accuracy for K=13 after 100 tests with different data split: 95.78772655522567 %
Average accuracy for K=15 after 100 tests with different data split: 95.23116406332706 %
Average accuracy for K=17 after 100 tests with different data split: 94.52371789094929 %
Average accuracy for K=19 after 100 tests with different data split: 93.85285871435981 %
Average accuracy for K=21 after 100 tests with different data split: 93.26620809747965 %
Average accuracy for K=23 after 100 tests with different data split: 92.58047022661833 %
Average accuracy for K=25 after 100 tests with different data split: 90.55746523509124 %
但是当我应用特征归一化时,准确率会显着下降。 我对具有归一化特征的 kNN 的结果:
Average accuracy for K=1 after 100 tests with different data split: 88.56128075154439 %
Average accuracy for K=3 after 100 tests with different data split: 85.01466511662318 %
Average accuracy for K=5 after 100 tests with different data split: 83.32096281613967 %
Average accuracy for K=7 after 100 tests with different data split: 83.09434478900455 %
Average accuracy for K=9 after 100 tests with different data split: 82.05628926919964 %
Average accuracy for K=11 after 100 tests with different data split: 79.89732262550343 %
Average accuracy for K=13 after 100 tests with different data split: 79.60617886853211 %
Average accuracy for K=15 after 100 tests with different data split: 79.26511126374507 %
Average accuracy for K=17 after 100 tests with different data split: 77.51457877706329 %
Average accuracy for K=19 after 100 tests with different data split: 76.97848441605367 %
Average accuracy for K=21 after 100 tests with different data split: 75.70005919265326 %
Average accuracy for K=23 after 100 tests with different data split: 76.45758217099551 %
Average accuracy for K=25 after 100 tests with different data split: 76.16619492431572 %
我在代码中的算法没有逻辑错误,我在简单的数据上进行了检查。
为什么特征归一化后kNN分类的准确率下降这么多?我猜归一化本身不应该降低任何分类的准确率。那么使用特征归一化的目的是什么?
【问题讨论】:
【参考方案1】:KNN 的工作方式是找到与其相似的实例。因为它计算两点之间的Euclidean Distance
。现在通过规范化,您正在改变改变准确性的特征规模。
看看this 研究。转到数字,您会发现不同的缩放技术提供不同的精度。
【讨论】:
【参考方案2】:归一化永远不会降低分类准确度是一个普遍的误解。可以的。
怎么做?
连续的相对值也很重要。事实上,它们确实确定了点在特征空间中的位置。当您执行标准化时,它会严重抵消该相对位置。可以感觉到这一点,尤其是在 k-NN 分类中,因为它直接针对点之间的距离进行操作。与此相比,它在 SVM 中的效果感觉不那么强烈,因为在这种情况下,优化过程仍然能够找到一个相当准确的超平面。
您还应该注意,在这里,您使用 avg(X) 进行归一化。因此,考虑特定行的相邻列中的两个点。如果第一个点远低于平均值,第二个点远高于各自列的平均值,而在非归一化意义上,它们是非常接近的数值,距离计算可能会有很大差异。
永远不要期望规范化能创造奇迹。
【讨论】:
以上是关于特征归一化后 kNN 分类的准确率下降?的主要内容,如果未能解决你的问题,请参考以下文章