fn predict_no_ties(&self, k: usize) -> Result<Label, ()> {
        if k > self.neighbors.len() {
            return Err(());
        }

        let mut label_count = HashMap::new();

        let mut y_pred = 0;
        let mut y_count = 0;

        for neigh in self.neighbors.iter().take(k) {
            let count = label_count.entry(neigh.label).or_insert(0);
            *count += 1;
            if *count > y_count {
                y_pred = neigh.label;
                y_count = *count;
            }
        }
        Ok(y_pred)
    }
/// Predict label according to k-NN rule, for specified k, without
/// accounting for ties.
Predict label according to k-NN rule, for specified k, without
accounting for ties.
Predict label according to k - NN rule for specified k without accounting for ties .
fn predict_no_ties(&self, k: usize) -> Result<Label, ()> {
        if k > self.neighbors.len() {
            return Err(());
        }
        let mut label_count = HashMap::new();
        let mut y_pred = 0;
        let mut y_count = 0;
        for neigh in self.neighbors.iter().take(k) {
            let count = label_count.entry(neigh.label).or_insert(0);
            *count += 1;
            if *count > y_count {
                y_pred = neigh.label;
                y_count = *count;
            }
        }
        Ok(y_pred)
    }
fn predict_no_ties ( & self , k : usize ) -> Result < Label , ( ) > { if k > self . neighbors . len ( ) { return Err ( ( ) ) ; } let mut label_count = HashMap :: new ( ) ; let mut y_pred = 0 ; let mut y_count = 0 ; for neigh in self . neighbors . iter ( ) . take ( k ) { let count = label_count . entry ( neigh . label ) . or_insert ( 0 ) ; * count += 1 ; if * count > y_count { y_pred = neigh . label ; y_count = * count ; } } Ok ( y_pred ) }
Predict label according to k-NN rule, for specified k, without
accounting for ties.
Predict label according to k - NN rule for specified k without accounting for ties .
&self
k
usize
&self
k
usize