我目前正在阅读Ethem Alpaydin的"机器学习简介",我和我遇到了最近的质心分类器,并试图实施它。我想我已经正确地实现了分类器,但是我的准确性只有68%。因此,最近的质心分类器本身是否效率低下,或者我的实现中是否存在某些错误?
?数据集包含1372个数据点,每个数据点具有4个功能,并且有2个输出类我的MATLAB实现:
DATA = load("-ascii", "data.txt");
#DATA is 1372x5 matrix with 762 data points of class 0 and 610 data points of class 1
#there are 4 features of each data point
X = DATA(:,1:4); #matrix to store all features
X0 = DATA(1:762,1:4); #matrix to store the features of class 0
X1 = DATA(763:1372,1:4); #matrix to store the features of class 1
X0 = X0(1:610,:); #to make sure both datasets have same size for prior probability to be equal
Y = DATA(:,5); # to store outputs
mean0 = sum(X0)/610; #mean of features of class 0
mean1 = sum(X1)/610; #mean of featurs of class 1
count = 0;
for i = 1:1372
pre = 0;
cost1 = X(i,:)*(mean0'); #calculates the dot product of dataset with mean of features of both classes
cost2 = X(i,:)*(mean1');
if (cost1<cost2)
pre = 1;
end
if pre == Y(i)
count = count+1; #counts the number of correctly predicted values
end
end
disp("accuracy"); #calculates the accuracy
disp((count/1372)*100);
这里至少有几件事:
-
您正在使用DOT产品在输入空间中分配相似性,这几乎是从不有效。使用DOT产品的唯一原因是假设您的所有数据点都具有相同的规范,或者规范无关紧要(几乎永远不会正确(。尝试使用欧几里得距离,即使它非常天真 - 它应该更好
-
是效率低下分类器吗?取决于效率的定义。这是一个非常简单且快速的,但是就预测能力而言,它是极糟糕的。实际上,它比天真的贝叶斯更糟糕,后者已经被认为是"玩具模型"。
-
代码也有问题
X0 = DATA(1:762,1:4); #matrix to store the features of class 0 X1 = DATA(763:1372,1:4); #matrix to store the features of class 1 X0 = X0(1:610,:); #to make sure both datasets have same size for prior probability to be equal
X0子样本后,您将有1220个培训样本,然后在"测试"训练和" X0的缺失元素"测试期间,从概率的角度来看,这确实没有任何意义。首先,您绝对不应该在训练集上测试准确性(因为它高估了真正的准确性(,其次是通过对培训数据进行二次采样,而不是不是均衡的先生。不在这样的方法中,您只是在降低质量估计的质量,仅此而已。这类技术(子/超级采样(均衡了模型priors 的模型的先验。您的方法不是(因为它基本上是1/2之前假定的生成模型(,因此没有任何好处发生。