Computing frequency distribution
The Frequency
class has methods to count the number of data instances in a bucket, to count unique number of data instances, and so on. The interface to Frequency
is very simple, and in most cases, it requires very few lines of code to get the desired calculations done.
As value types, Strings, integers, longs, and chars are all supported.
Note
Natural ordering is the default ordering for cumulative frequencies, but this can be overridden by supplying a Comparator
to the constructor
.
How to do it...
Create a method that takes a
double
array as argument. We will be computing the frequency distributions of the values of this array:public void getFreqStats(double[] values){
Create an object of theÂ
Frequency
class:Frequency freq = new Frequency();
Add the values of the
double
array to this object:for( int i = 0; i < values.length; i++) { freq.addValue(values[i]); }
Generate the frequency...