pub fn get_hinge_breaks<T: ToPrimitive, S: ToPrimitive>(
    hinge_coefficient: S,
    data: &[T]
) -> Vec<f64>
Expand description

Returns a vector of breaks generated through the Hinge Breaks algorithm given the desired number of bins and a dataset

Arguments

  • hinge_coefficient - A coefficient representing the size of the hinge as a multiple of the data’s IQR (usually 1.5 or 3)
  • data - 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 the data doesn’t have outliers below/above the hinges, the algorithm may not produce all six bins

Examples

use classify::get_hinge_breaks;

let data: Vec<usize> = vec![0, 1, 10, 11, 12, 13, 14, 15, 16, 20, 25];
let hinge_coefficient = 1.5;

let result: Vec<f64> = get_hinge_breaks(hinge_coefficient, &data);

assert_eq!(result, vec![3.0, 10.5, 13.0, 15.5, 23.0]);