Sunday 15 November 2015

Minor Update To gtdm-r

I have made a minor update to the gtdm-r repository on github. gtdm-r has Ruby version of programs in "A Programmer's Guide To Data Mining”.


The change is on the keyword upto.
When I wrote the code, I knew only of using upto followed by a number. Like 1.upto 5

If you put the block syntax after the number as in
0.upto @k-1 {|i| totalDistance += nearest[i].second}
you will get the following error --
syntax error, unexpected '}', expecting keyword_end

I was in a rush to complete the programs and to fix this error, I went with the do block.
0.upto @k-1 do |i|
totalDistance += nearest[i].second
end

Later I realized that I could still have upto with the block syntax but that needs the number in parenthesis as in:
0.upto(@k-1) {|i| totalDistance += nearest[i].second}

Hence this update. Total number of places I changed is 25. Break up is:
chapter-2: recommender.rb -- 1 place
chapter-3: recommender3.rb -- 2 places
chapter-4: nearestNeighborClassifier.rb -- 1 place
chapter-5: crossValidation.rb -- 1 place, pimaKNN.rb -- 1 place
chapter-8: hierarchicalClusterer.rb -- 2 places, kmeans.rb -- 8 places, kmeansPlusPlus.rb -- 9 places

Post Script: times seems to be a better keyword than upto, so I will change to it sometime soon.

No comments:

Post a Comment