public static void main(String[] args) throws java.io.IOException{
Dataset data = FileHandler.loadDataset(new File("iris.txt"), 50, ",");
Dataset evalData = FileHandler.loadDataset(new File("irisfull.txt"), 50, ",");
Classifier knn = new KNearestNeighbors(5);
knn.buildClassifier(data);
Map<Object, PerformanceMeasure> pm = EvaluateDataset.testDataset(knn, evalData);
for(Object o:pm.keySet())
System.out.println(o+": "+pm.get(o).getAccuracy());
}
问候!我正在写机器学习的学校作业(我绝不是该领域的专业人员)。我使用javaml库。这段代码适用于经典的iris.txt就好了(精度约为0.97)。但是,每当我将数据插入iris.txt(并且还更改classindex 4-> 50)时,PerformanceMeasure似乎出现故障并打印出&#34; one&#34;作为一个&#34;一个&#34;和&#34;两个&#34; (反之亦然)。
我的数据示例(总共30个样本)
130.27, -80.63, 112.97, 0.0, 89.73, 134.14, -79.52, 114.29, 0.0, 87.65, 130.69, -79.58, 112.17, 0.0, 84.22, 126.9, -80.08, 106.0, 0.0, 86.2, 133.16, -79.82, 113.72, 0.0, 92.88, 132.13, -81.05, 113.49, 0.0, 97.74, 124.16, -80.69, 109.18, 0.0, 91.62, 133.31, -80.36, 116.82, 0.0, 91.66, 139.03, -78.47, 117.62, 0.0, 88.47, 143.13, -79.44, 125.02, 0.0, 96.97,one
-67.15, -83.81, 147.47, 0.0, 87.53, -72.51, -84.21, 146.45, 0.0, 96.33, -67.69, -84.44, 147.6, 0.0, 84.96, -67.05, -84.87, 144.97, 0.0, 83.52, -69.23, -84.06, 146.3, 0.0, 77.51, -68.91, -84.5, 144.07, 0.0, 87.87, -71.96, -84.45, 143.12, 0.0, 73.64, -70.94, -84.73, 143.75, 0.0, 74.4, -73.52, -84.52, 144.33, 0.0, 83.48, -62.95, -84.37, 144.5, 0.0, 102.88,one
-110.14, -80.15, 117.75, 0.0, 75.46, -111.92, -80.34, 119.03, 1.0, 77.11, -111.43, -80.2, 117.21, 0.0, 83.65, -110.17, -80.78, 117.98, 0.0, 80.38, -113.83, -79.49, 117.43, 1.0, 88.4, -113.36, -80.15, 117.56, 1.0, 85.62, -106.62, -81.3, 122.5, 0.0, 81.89, -103.48, -81.09, 124.99, 1.0, 87.83, -125.0, -78.76, 107.75, 1.0, 86.06, -109.81, -80.96, 114.7, 1.0, 79.33,one
-178.84, 72.82, 83.53, 0.0, 109.74, -80.39, 79.98, -13.35, 0.0, 108.66, 77.19, 76.98, 124.21, 0.0, 109.65, 74.66, 80.59, 166.15, 0.0, 103.41, -100.05, 80.53, 22.57, 0.0, 105.92, -12.87, 71.55, -98.41, 0.0, 105.81, 65.87, 73.04, 108.27, 0.0, 109.67, 61.01, 82.37, 178.77, 0.0, 104.66, 46.63, 67.01, -165.75, 0.0, 105.96, -150.4, 84.58, 44.67, 0.0, 107.9,two
25.83, 47.49, -21.31, 0.0, 98.99, 75.19, 67.47, -76.54, 0.0, 99.37, 19.34, -25.5, -63.96, 0.0, 95.48, 74.99, 83.5, -46.41, 0.0, 91.97, -7.61, 55.46, -144.28, 0.0, 100.24, -8.78, 24.74, -119.22, 0.0, 109.09, -26.2, 72.37, -176.77, 0.0, 109.73, -10.25, -8.74, -132.55, 0.0, 105.29, -95.8, 84.23, 27.79, 0.0, 104.68, 24.33, 65.22, -168.3, 0.0, 105.44,two
主要的问题是我可以删除除#34; 2&#34;之外的所有实例,并且它将同时显示&#34; 2&#34;和&#34;一个&#34;精度相同(约0.87)。此外,它很少能够分离数据&#34;一个&#34;来自数据&#34;两个&#34;如果我没有从提供的数据库中提取样本。
请帮助,非常重要的任务。 提前谢谢。