Geoscience Reference
In-Depth Information
Next, we generate a data set from the chemical compositions of the three
types of granite. Sixty granite samples were collected from each rock type
and chemically analyzed. h e percentages of two chemical elements, x1 and
x2 , we store in three variables data1 , data2 and data3 .
data1 = randn(60,2);
data1(:,1) = 3.4 + 1.2*data1(:,1);
data1(:,2) = 1.7 + 0.4*data1(:,2);
data2 = randn(60,2);
data2(:,1) = 5.5 + 1.8*data2(:,1);
data2(:,2) = 2.9 + 0.6*data2(:,2);
data3 = randn(60,2);
data3(:,1) = 3+ 1.8*data2(:,1);
data3(:,2) = 0.3 + 1.2*data2(:,2);
In order to dei ne the established categories (or classes) we create a character
array containing the labels for each pair of measurements using remap , which
creates 60 copies of each string Granite_1 , Granite_2 , and Granite_3 and stores
them in classes .
classes(1:60,1:9) = repmat('Granite_1',60,1);
classes(61:120,1:9) = repmat('Granite_2',60,1);
classes(121:180,1:9) = repmat('Granite_3',60,1);
We then vertically concatenate the three variables data1 , data2 and data3 to
a single variable data .
data = [data1(:,1:2);data2(:,1:2);data3(:,1:2)];
We save the resulting synthetic data set in the binary i le granite.mat .
save granite.mat
We have thus generated a synthetic data set from three groups of normally
distributed data. We can load the data set (as we would with any other real
data set) from the i le granite.mat by typing
clear
load granite.mat
We then create a linear discriminant analysis classii er using Classification
Discriminant.fit .
cls = ClassificationDiscriminant.fit(data,classes);
h e function returns a discriminant analysis model for predictors data and
Search WWH ::




Custom Search