Function classify::get_st_dev_classification
source · [−]pub fn get_st_dev_classification<T: ToPrimitive, S: ToPrimitive>(
bin_size: S,
data: &[T]
) -> Classification
Expand description
Returns a Classification object following the Standard Deviation Breaks algorithm given the desired bin size as a proportion of a standard deviation and one-dimensional data Note: This algorithm calculates Standard Deviation with Bessel’s correction
Arguments
bin_size
- A float representing the proportion of a standard deviation each bin should encompassdata
- A reference to a vector of unsorted data points (f64) to generate a Classification 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
Examples
use classify::get_st_dev_classification;
use classify::{Classification, Bin};
let data: Vec<f32> = vec![0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0];
let bin_size = 1.0; // Bins will be the size of one standard deviation
let result: Classification = get_st_dev_classification(bin_size, &data);
let expected: Classification = vec![
Bin{bin_start: 0.0, bin_end: 0.41987655026535653, count: 1},
Bin{bin_start: 0.41987655026535653, bin_end: 1.5, count: 2},
Bin{bin_start: 1.5, bin_end: 2.5801234497346437, count: 3},
Bin{bin_start: 2.5801234497346437, bin_end: 3.0, count: 1}
];
assert!(result == expected);