anofox-ml-linear 0.1.0

Stochastic Gradient Descent linear models (SGDClassifier, SGDRegressor, PassiveAggressive) for anofox-ml
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
//! SGD-based linear classifier.
//!
//! Supports hinge (linear SVM), log_loss (logistic regression), and
//! modified_huber loss functions, trained with stochastic gradient descent.
//! Multi-class uses a one-vs-rest strategy.

use crate::sgd_common::{compute_lr, penalty_gradient, LearningRate, Penalty};
use anofox_ml_core::{Fit, Float, PartialFit, Predict, Result, RustMlError};
use ndarray::{Array1, Array2};
use rand::rngs::StdRng;
use rand::seq::SliceRandom;
use rand::SeedableRng;

/// Loss function for SGD classifier.
#[derive(Debug, Clone, Copy, PartialEq, serde::Serialize, serde::Deserialize)]
pub enum ClassifierLoss {
    /// Hinge loss (linear SVM). Not differentiable at 1, but subgradient works.
    Hinge,
    /// Log loss (logistic regression).
    Log,
    /// Modified Huber: smooth hinge that gives probability estimates.
    ModifiedHuber,
    /// Perceptron loss: hinge with zero threshold.
    Perceptron,
}

impl Default for ClassifierLoss {
    fn default() -> Self {
        ClassifierLoss::Hinge
    }
}

/// Stochastic Gradient Descent classifier.
///
/// Linear classifier trained via SGD, supporting multiple loss functions.
/// For multi-class problems, uses one-vs-rest decomposition.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct SgdClassifier {
    pub loss: ClassifierLoss,
    pub penalty: Penalty,
    pub alpha: f64,
    pub l1_ratio: f64,
    pub max_iter: usize,
    pub tol: f64,
    pub eta0: f64,
    pub power_t: f64,
    pub learning_rate: LearningRate,
    pub shuffle: bool,
    pub seed: u64,
}

impl SgdClassifier {
    pub fn new() -> Self {
        Self {
            loss: ClassifierLoss::Hinge,
            penalty: Penalty::L2,
            alpha: 0.0001,
            l1_ratio: 0.15,
            max_iter: 1000,
            tol: 1e-3,
            eta0: 0.01,
            power_t: 0.5,
            learning_rate: LearningRate::Optimal,
            shuffle: true,
            seed: 0,
        }
    }

    pub fn with_loss(mut self, loss: ClassifierLoss) -> Self {
        self.loss = loss;
        self
    }
    pub fn with_penalty(mut self, penalty: Penalty) -> Self {
        self.penalty = penalty;
        self
    }
    pub fn with_alpha(mut self, alpha: f64) -> Self {
        self.alpha = alpha;
        self
    }
    pub fn with_l1_ratio(mut self, l1_ratio: f64) -> Self {
        self.l1_ratio = l1_ratio;
        self
    }
    pub fn with_max_iter(mut self, max_iter: usize) -> Self {
        self.max_iter = max_iter;
        self
    }
    pub fn with_tol(mut self, tol: f64) -> Self {
        self.tol = tol;
        self
    }
    pub fn with_eta0(mut self, eta0: f64) -> Self {
        self.eta0 = eta0;
        self
    }
    pub fn with_power_t(mut self, power_t: f64) -> Self {
        self.power_t = power_t;
        self
    }
    pub fn with_learning_rate(mut self, lr: LearningRate) -> Self {
        self.learning_rate = lr;
        self
    }
    pub fn with_shuffle(mut self, shuffle: bool) -> Self {
        self.shuffle = shuffle;
        self
    }
    pub fn with_seed(mut self, seed: u64) -> Self {
        self.seed = seed;
        self
    }
}

impl Default for SgdClassifier {
    fn default() -> Self {
        Self::new()
    }
}

/// A fitted SGD linear classifier.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(bound(deserialize = "F: serde::de::DeserializeOwned"))]
pub struct FittedSgdClassifier<F: Float> {
    /// One weight vector per class (OvR). Shape: (n_classes, n_features).
    weights: Vec<Array1<F>>,
    /// One bias per class.
    biases: Vec<F>,
    /// Sorted unique class labels.
    classes: Vec<F>,
    n_features: usize,
}

impl<F: Float> FittedSgdClassifier<F> {
    /// Return the unique class labels.
    pub fn classes(&self) -> &[F] {
        &self.classes
    }

    /// Return weight vectors (one per class in OvR).
    pub fn weights(&self) -> &[Array1<F>] {
        &self.weights
    }

    /// Return biases (one per class in OvR).
    pub fn biases(&self) -> &[F] {
        &self.biases
    }

    /// Compute raw decision function values for each class.
    pub fn decision_function(&self, x: &Array2<F>) -> Result<Array2<F>> {
        if x.ncols() != self.n_features {
            return Err(RustMlError::ShapeMismatch(format!(
                "expected {} features, got {}",
                self.n_features,
                x.ncols()
            )));
        }
        let n = x.nrows();
        let k = self.classes.len();
        let mut scores = Array2::zeros((n, k));
        for (c, (w, &b)) in self.weights.iter().zip(self.biases.iter()).enumerate() {
            for i in 0..n {
                let mut s = b;
                for j in 0..self.n_features {
                    s = s + x[[i, j]] * w[j];
                }
                scores[[i, c]] = s;
            }
        }
        Ok(scores)
    }
}

/// Train a single binary OvR classifier via SGD.
/// Returns (weights, bias).
fn train_binary_sgd(
    x: &Array2<f64>,
    y_binary: &[f64], // +1 or -1
    loss: ClassifierLoss,
    penalty: Penalty,
    alpha: f64,
    l1_ratio: f64,
    max_iter: usize,
    tol: f64,
    eta0: f64,
    power_t: f64,
    learning_rate: LearningRate,
    shuffle: bool,
    seed: u64,
) -> (Array1<f64>, f64) {
    train_binary_sgd_resume(
        x,
        y_binary,
        None,
        loss,
        penalty,
        alpha,
        l1_ratio,
        max_iter,
        tol,
        eta0,
        power_t,
        learning_rate,
        shuffle,
        seed,
    )
}

/// Same as `train_binary_sgd` but starts from the given (weights, bias) if
/// provided. Powers `partial_fit`: each call resumes from the previous
/// state instead of zero-initialising.
fn train_binary_sgd_resume(
    x: &Array2<f64>,
    y_binary: &[f64],
    initial: Option<(Array1<f64>, f64)>,
    loss: ClassifierLoss,
    penalty: Penalty,
    alpha: f64,
    l1_ratio: f64,
    max_iter: usize,
    tol: f64,
    eta0: f64,
    power_t: f64,
    learning_rate: LearningRate,
    shuffle: bool,
    seed: u64,
) -> (Array1<f64>, f64) {
    let n = x.nrows();
    let p = x.ncols();
    let (mut w, mut b) = initial.unwrap_or_else(|| (Array1::zeros(p), 0.0));
    let mut rng = StdRng::seed_from_u64(seed);
    let mut indices: Vec<usize> = (0..n).collect();
    let mut t: usize = 1;

    for _epoch in 0..max_iter {
        if shuffle {
            indices.shuffle(&mut rng);
        }

        let mut total_loss = 0.0;

        for &i in &indices {
            let eta = compute_lr(learning_rate, eta0, alpha, t, power_t);
            t += 1;

            // Compute decision: z = w · x_i + b
            let mut z = b;
            for j in 0..p {
                z += w[j] * x[[i, j]];
            }
            let yi = y_binary[i];
            let margin = yi * z;

            // Compute loss gradient w.r.t. z
            let dloss = match loss {
                ClassifierLoss::Hinge => {
                    if margin < 1.0 {
                        total_loss += (1.0 - margin).max(0.0);
                        -yi
                    } else {
                        0.0
                    }
                }
                ClassifierLoss::Log => {
                    let sig = 1.0 / (1.0 + (-z).exp());
                    let label01 = (yi + 1.0) / 2.0; // convert {-1,1} to {0,1}
                    total_loss += -(label01 * sig.ln() + (1.0 - label01) * (1.0 - sig).ln());
                    sig - label01
                }
                ClassifierLoss::ModifiedHuber => {
                    if margin >= 1.0 {
                        0.0
                    } else if margin >= -1.0 {
                        total_loss += (1.0 - margin).powi(2);
                        -2.0 * yi * (1.0 - margin)
                    } else {
                        total_loss += -4.0 * margin;
                        -4.0 * yi
                    }
                }
                ClassifierLoss::Perceptron => {
                    if margin <= 0.0 {
                        total_loss += -margin;
                        -yi
                    } else {
                        0.0
                    }
                }
            };

            // Update weights: w -= eta * (dloss * x_i + penalty_grad)
            if dloss != 0.0 {
                for j in 0..p {
                    w[j] -= eta
                        * (dloss * x[[i, j]] + penalty_gradient(w[j], alpha, penalty, l1_ratio));
                }
                b -= eta * dloss;
            } else {
                // Still apply regularization
                for j in 0..p {
                    w[j] -= eta * penalty_gradient(w[j], alpha, penalty, l1_ratio);
                }
            }
        }

        // Check convergence
        let avg_loss = total_loss / n as f64;
        if avg_loss < tol {
            break;
        }
    }

    (w, b)
}

impl Fit<f64> for SgdClassifier {
    type Fitted = FittedSgdClassifier<f64>;

    fn fit(&self, x: &Array2<f64>, y: &Array1<f64>) -> Result<Self::Fitted> {
        if x.nrows() != y.len() {
            return Err(RustMlError::ShapeMismatch(format!(
                "X has {} rows but y has {} elements",
                x.nrows(),
                y.len()
            )));
        }
        if x.is_empty() {
            return Err(RustMlError::EmptyInput("training data is empty".into()));
        }
        if self.alpha < 0.0 {
            return Err(RustMlError::InvalidParameter(
                "alpha must be non-negative".into(),
            ));
        }

        // Collect unique classes
        let mut classes: Vec<f64> = y.iter().copied().collect();
        classes.sort_by(|a, b| a.partial_cmp(b).unwrap());
        classes.dedup();

        if classes.len() < 2 {
            return Err(RustMlError::InvalidParameter(
                "need at least 2 classes".into(),
            ));
        }

        let n_features = x.ncols();

        // One-vs-rest: train one binary classifier per class
        let mut weights = Vec::with_capacity(classes.len());
        let mut biases = Vec::with_capacity(classes.len());

        for (c_idx, &cls) in classes.iter().enumerate() {
            let y_binary: Vec<f64> = y
                .iter()
                .map(|&v| if v == cls { 1.0 } else { -1.0 })
                .collect();

            let (w, b) = train_binary_sgd(
                x,
                &y_binary,
                self.loss,
                self.penalty,
                self.alpha,
                self.l1_ratio,
                self.max_iter,
                self.tol,
                self.eta0,
                self.power_t,
                self.learning_rate,
                self.shuffle,
                self.seed.wrapping_add(c_idx as u64),
            );
            weights.push(w);
            biases.push(b);
        }

        Ok(FittedSgdClassifier {
            weights,
            biases,
            classes,
            n_features,
        })
    }
}

impl PartialFit<f64> for SgdClassifier {
    type Fitted = FittedSgdClassifier<f64>;

    fn partial_fit(
        &self,
        state: Option<Self::Fitted>,
        x: &Array2<f64>,
        y: &Array1<f64>,
        classes: Option<&[f64]>,
    ) -> Result<Self::Fitted> {
        if x.nrows() != y.len() {
            return Err(RustMlError::ShapeMismatch(format!(
                "X has {} rows but y has {} elements",
                x.nrows(),
                y.len()
            )));
        }
        if x.is_empty() {
            return Err(RustMlError::EmptyInput("training data is empty".into()));
        }

        // Establish the class set: from state, or from `classes` on first call,
        // or by deriving from the batch (must have ≥ 2 unique labels then).
        let class_list: Vec<f64> = if let Some(s) = &state {
            s.classes.clone()
        } else if let Some(c) = classes {
            c.to_vec()
        } else {
            let mut v: Vec<f64> = y.iter().copied().collect();
            v.sort_by(|a, b| a.partial_cmp(b).unwrap());
            v.dedup();
            if v.len() < 2 {
                return Err(RustMlError::InvalidParameter(
                    "first partial_fit needs classes= or batch with ≥ 2 unique labels".into(),
                ));
            }
            v
        };

        let n_features = x.ncols();

        // Initial weights/biases per class — from existing state or zeros.
        let (existing_weights, existing_biases): (Vec<Array1<f64>>, Vec<f64>) =
            if let Some(s) = state {
                if s.n_features != n_features {
                    return Err(RustMlError::ShapeMismatch(format!(
                        "previous fit had {} features, batch has {}",
                        s.n_features, n_features
                    )));
                }
                (s.weights, s.biases)
            } else {
                (
                    vec![Array1::<f64>::zeros(n_features); class_list.len()],
                    vec![0.0; class_list.len()],
                )
            };

        // Run one resume-pass per class.
        let mut weights = Vec::with_capacity(class_list.len());
        let mut biases = Vec::with_capacity(class_list.len());
        for (c_idx, &cls) in class_list.iter().enumerate() {
            let y_binary: Vec<f64> = y
                .iter()
                .map(|&v| if v == cls { 1.0 } else { -1.0 })
                .collect();
            let (w, b) = train_binary_sgd_resume(
                x,
                &y_binary,
                Some((existing_weights[c_idx].clone(), existing_biases[c_idx])),
                self.loss,
                self.penalty,
                self.alpha,
                self.l1_ratio,
                self.max_iter,
                self.tol,
                self.eta0,
                self.power_t,
                self.learning_rate,
                self.shuffle,
                self.seed.wrapping_add(c_idx as u64),
            );
            weights.push(w);
            biases.push(b);
        }

        Ok(FittedSgdClassifier {
            weights,
            biases,
            classes: class_list,
            n_features,
        })
    }
}

impl Predict<f64> for FittedSgdClassifier<f64> {
    fn predict(&self, x: &Array2<f64>) -> Result<Array1<f64>> {
        let scores = self.decision_function(x)?;
        let n = x.nrows();
        let mut preds = Array1::zeros(n);

        for i in 0..n {
            let mut best_c = 0;
            let mut best_s = scores[[i, 0]];
            for c in 1..self.classes.len() {
                if scores[[i, c]] > best_s {
                    best_s = scores[[i, c]];
                    best_c = c;
                }
            }
            preds[i] = self.classes[best_c];
        }
        Ok(preds)
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use ndarray::array;

    fn make_binary_data() -> (Array2<f64>, Array1<f64>) {
        let x = Array2::from_shape_vec(
            (12, 2),
            vec![
                0.0, 0.0, 0.5, 0.5, 1.0, 0.0, 0.0, 1.0, 3.0, 3.0, 3.5, 3.5, 4.0, 3.0, 3.0, 4.0,
                0.5, 0.0, 0.0, 0.5, 3.5, 3.0, 3.0, 3.5,
            ],
        )
        .unwrap();
        let y = array![0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0];
        (x, y)
    }

    #[test]
    fn test_sgd_partial_fit_resumes_from_state() {
        // partial_fit on two halves should fit a classifier that achieves
        // training accuracy ≥ that of one-shot fit on a single half.
        let (x, y) = make_binary_data();
        let n = x.nrows();
        let half = n / 2;
        let x1 = x.slice(ndarray::s![..half, ..]).to_owned();
        let y1 = y.slice(ndarray::s![..half]).to_owned();
        let x2 = x.slice(ndarray::s![half.., ..]).to_owned();
        let y2 = y.slice(ndarray::s![half..]).to_owned();

        let clf = SgdClassifier::new()
            .with_loss(ClassifierLoss::Log)
            .with_max_iter(200)
            .with_alpha(0.001);
        let classes = [0.0_f64, 1.0];

        let s1 = PartialFit::partial_fit(&clf, None, &x1, &y1, Some(&classes)).unwrap();
        let s2 = PartialFit::partial_fit(&clf, Some(s1), &x2, &y2, None).unwrap();

        let preds = s2.predict(&x).unwrap();
        let correct: usize = preds.iter().zip(y.iter()).filter(|(&p, &t)| p == t).count();
        // Should classify the majority correctly after seeing both halves.
        assert!(correct >= 10, "partial_fit too inaccurate: {correct}/12");
        assert_eq!(s2.classes(), &[0.0_f64, 1.0]);
    }

    #[test]
    fn test_sgd_classifier_hinge() {
        let (x, y) = make_binary_data();
        let clf = SgdClassifier::new()
            .with_loss(ClassifierLoss::Hinge)
            .with_max_iter(500)
            .with_alpha(0.001);
        let fitted = clf.fit(&x, &y).unwrap();

        let preds = fitted.predict(&x).unwrap();
        let correct: usize = preds.iter().zip(y.iter()).filter(|(&p, &t)| p == t).count();
        assert!(
            correct >= 8,
            "should classify most points correctly, got {}/12",
            correct
        );
    }

    #[test]
    fn test_sgd_classifier_log_loss() {
        let (x, y) = make_binary_data();
        let clf = SgdClassifier::new()
            .with_loss(ClassifierLoss::Log)
            .with_max_iter(500)
            .with_alpha(0.001);
        let fitted = clf.fit(&x, &y).unwrap();

        let preds = fitted.predict(&x).unwrap();
        let correct: usize = preds.iter().zip(y.iter()).filter(|(&p, &t)| p == t).count();
        assert!(
            correct >= 8,
            "should classify most points correctly, got {}/12",
            correct
        );
    }

    #[test]
    fn test_sgd_classifier_modified_huber() {
        let (x, y) = make_binary_data();
        let clf = SgdClassifier::new()
            .with_loss(ClassifierLoss::ModifiedHuber)
            .with_max_iter(500);
        let fitted = clf.fit(&x, &y).unwrap();

        let preds = fitted.predict(&x).unwrap();
        for &p in preds.iter() {
            assert!(p == 0.0 || p == 1.0);
        }
    }

    #[test]
    fn test_sgd_classifier_perceptron() {
        let (x, y) = make_binary_data();
        let clf = SgdClassifier::new()
            .with_loss(ClassifierLoss::Perceptron)
            .with_penalty(Penalty::None)
            .with_max_iter(500);
        let fitted = clf.fit(&x, &y).unwrap();

        assert_eq!(fitted.classes().len(), 2);
    }

    #[test]
    fn test_sgd_classifier_multiclass() {
        let x = Array2::from_shape_vec(
            (9, 2),
            vec![
                0.0, 0.0, 0.5, 0.5, 0.0, 0.5, 3.0, 0.0, 3.5, 0.5, 3.0, 0.5, 1.5, 3.0, 1.0, 3.5,
                2.0, 3.0,
            ],
        )
        .unwrap();
        let y = array![0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0];

        let clf = SgdClassifier::new()
            .with_loss(ClassifierLoss::Hinge)
            .with_max_iter(1000)
            .with_alpha(0.001);
        let fitted = clf.fit(&x, &y).unwrap();

        assert_eq!(fitted.classes().len(), 3);
        let preds = fitted.predict(&x).unwrap();
        for &p in preds.iter() {
            assert!(p == 0.0 || p == 1.0 || p == 2.0);
        }
    }

    #[test]
    fn test_sgd_classifier_decision_function() {
        let (x, y) = make_binary_data();
        let clf = SgdClassifier::new().with_max_iter(100);
        let fitted = clf.fit(&x, &y).unwrap();

        let scores = fitted.decision_function(&x).unwrap();
        assert_eq!(scores.nrows(), 12);
        assert_eq!(scores.ncols(), 2);
    }

    #[test]
    fn test_sgd_classifier_shape_mismatch() {
        let x = Array2::from_shape_vec((3, 2), vec![0.0; 6]).unwrap();
        let y = array![0.0, 1.0];
        assert!(SgdClassifier::new().fit(&x, &y).is_err());
    }

    #[test]
    fn test_sgd_classifier_empty_input() {
        let x = Array2::<f64>::zeros((0, 2));
        let y = Array1::<f64>::zeros(0);
        assert!(SgdClassifier::new().fit(&x, &y).is_err());
    }

    #[test]
    fn test_sgd_classifier_single_class() {
        let x = Array2::from_shape_vec((3, 1), vec![1.0, 2.0, 3.0]).unwrap();
        let y = array![0.0, 0.0, 0.0];
        assert!(SgdClassifier::new().fit(&x, &y).is_err());
    }

    #[test]
    fn test_sgd_classifier_elastic_net() {
        let (x, y) = make_binary_data();
        let clf = SgdClassifier::new()
            .with_penalty(Penalty::ElasticNet)
            .with_l1_ratio(0.5)
            .with_max_iter(500);
        let fitted = clf.fit(&x, &y).unwrap();
        let preds = fitted.predict(&x).unwrap();
        assert_eq!(preds.len(), 12);
    }

    #[test]
    fn test_sgd_classifier_constant_lr() {
        let (x, y) = make_binary_data();
        let clf = SgdClassifier::new()
            .with_learning_rate(LearningRate::Constant)
            .with_eta0(0.01)
            .with_max_iter(500);
        let fitted = clf.fit(&x, &y).unwrap();
        let preds = fitted.predict(&x).unwrap();
        assert_eq!(preds.len(), 12);
    }
}

impl anofox_ml_core::ClassifierScore<f64> for FittedSgdClassifier<f64> {}