help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Programming error in Octave pattern classification code?


From: babelproofreader
Subject: Programming error in Octave pattern classification code?
Date: Fri, 6 Jul 2012 13:22:09 -0700 (PDT)

I have written the Octave code below to "brute force" classify a pattern into
one of five categories contained in a vector y, but as it stands it is
performing no better than random (accuracy 20%), which is a surprise to me.

First, a line from X (a 324,000 by 54 matrix) is randomly extracted, then a
new matrix is extracted from X where all the lines with the same term in the
first column as the initial random selection are the same. This produces a
9000 by 54 matrix look_up_matrix, and should include the initial random
selection. Then the closest match, in an Euclidean distance sense, is sought
and via index extraction the matching category is looked up in y. Since the
Euclidean distance between the initial random selection and itself in the
look_up_matrix should be zero I would expect an accuracy approaching 100%.
Can anyone point out any errors in the given code?

% first, training data "training_data.mat" should be loaded in command line

clear -exclusive X y % clear everything except y and X, previously loaded
from the command line

% create index to randomly choose from training set X
[junk, random_index] = sort( rand(1,size(X,1)) );

market_type = zeros(size(X,1),1) ;
correct_market_type = market_type ;

for ii = 1:size(market_type,1)

% index into training set based on period measurement
[i_X j_X] = find( X(:,1) == X( random_index(ii) , 1 ) ) ;

% extract the relevant part of X using above index
X_look_up_matrix = X( [i_X] , 4:54 ) ;

% and same for market labels vector y
y_look_up_vector = y( [i_X] , 1 ) ;

% find pattern in X_look_up_matrix that minimises Euclidean distance between
itself and the training example randomly taken from X
[ euc_dist_min i_euc_dist_min ] = min( sum( ( repmat(
X(random_index(ii),4:54), 9000, 1) .- X_look_up_matrix ) .^ 2.0 , 2 ,
'extra' ) ) ;

% take this minimum distance vector index to get predicted market type
market_type(ii) = y_look_up_vector( i_euc_dist_min , 1 ) ;

% keep a record of the actual market_type as taken directly from y
correct_market_type = y( random_index(ii) , 1 ) ;

end % end of loop

% print out accuracy of predicions
fprintf( '\nBrute Force Training Set Accuracy: %f\n' , mean(
double(market_type

--
View this message in context: 
http://octave.1599824.n4.nabble.com/Programming-error-in-Octave-pattern-classification-code-tp4631255.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]