Function classify::get_equal_interval_breaks
source · [−]pub fn get_equal_interval_breaks<T: ToPrimitive>(
num_bins: usize,
data: &[T]
) -> Vec<f64>
Expand description
Returns a vector of breaks generated through the Equal Interval Breaks algorithm given the desired number of bins and a dataset
Arguments
num_bins
- The desired number of binsdata
- A reference to a collection of unsorted data points to generate breaks for
Edge cases
- Inputting large u64/i64 data (near their max values) will result in loss of precision because data is being cast to f64
- If there is a wide enoguh gap in the data, this algorithm may produce one or more empty bins
Examples
use classify::get_equal_interval_breaks;
let data: Vec<f32> = vec![0.0, 0.5, 1.0, 1.5, 2.5, 3.0];
let num_bins = 3;
let result: Vec<f64> = get_equal_interval_breaks(num_bins, &data);
assert_eq!(result, vec![1.0, 2.0]);