资 源 简 介
load "iris.csv";tictraining_set = [iris(1:ceil(50*2/3),:); iris(51:50 + ceil(50*2/3),:); iris(101:100 + ceil(50*2/3),:)];%取每类的前2/3作为训练集 ceil用于提高效率test_set = [iris(ceil(50*2/3) + 1:50,:); iris(51 + ceil(50*2/3):100,:); iris(101 + ceil(50*2/3):150,:)];%取每类的后1/3作为测试集class1 = test_set(:,5);%记录类标,class1是一个行矩阵class1test_set(:,5) = 0;%便于计算准确度rows1 = find(training_set(:,5) == 1);%找出training_set(:,5) == 1的位置meanValue1 = mean(training_set(rows1,1:4));%计算一到四列的均值stdValue1 = std(training_set(rows1,1:4));%std(x) 算出一到四列的标准偏差。 x可以是一行的matrix或者一个多行matrix矩阵。如果只有一行,那么就是算一行的标准偏差,如果有多行,就是算每一列的标准偏差。rows2 = find(training_set(:,5) == 2);meanValue2 = mean(training_set(rows2,1:4));stdValue2 = std(training_set(rows2,1:4));rows3 = find(training_set(:,5) == 3);meanValue3 = mean(training_set(rows3,1:4));stdValue3 = std(training_set(rows3,1:4));pClass1 = size(rows