MCPcopy Create free account
hub / github.com/Open-Quant/openquant / sb_fit_predict_classifier

Function sb_fit_predict_classifier

crates/pyopenquant/src/sb_bagging.rs:17–43  ·  view source on GitHub ↗
(
    py: Python<'_>,
    x: Vec<Vec<f64>>,
    y: Vec<u8>,
    ind_mat: Vec<Vec<u8>>,
    n_estimators: usize,
    max_samples: f64,
    max_features: f64,
    random_state: u64,
    sample_weight: O

Source from the content-addressed store, hash-verified

15 sample_weight=None
16))]
17fn sb_fit_predict_classifier(
18 py: Python<'_>,
19 x: Vec<Vec<f64>>,
20 y: Vec<u8>,
21 ind_mat: Vec<Vec<u8>>,
22 n_estimators: usize,
23 max_samples: f64,
24 max_features: f64,
25 random_state: u64,
26 sample_weight: Option<Vec<f64>>,
27) -> PyResult<PyObject> {
28 let x_mat = matrix_from_rows(x)?;
29
30 let mut clf =
31 openquant::sb_bagging::SequentiallyBootstrappedBaggingClassifier::new(random_state);
32 clf.n_estimators = n_estimators;
33 clf.max_samples = openquant::sb_bagging::MaxSamples::Float(max_samples);
34 clf.max_features = openquant::sb_bagging::MaxFeatures::Float(max_features);
35 clf.oob_score = true;
36
37 clf.fit(&x_mat, &y, &ind_mat, sample_weight.as_deref()).map_err(to_py_err)?;
38 let predictions = clf.predict(&x_mat).map_err(to_py_err)?;
39
40 let d = PyDict::new(py);
41 d.set_item("predictions", predictions)?;
42 d.set_item("oob_score", clf.oob_score_value)?;
43 Ok(d.into_pyobject(py).unwrap().into_any().unbind())
44}
45
46#[pyfunction(name = "fit_predict_sb_regressor")]

Callers

nothing calls this directly

Calls 3

matrix_from_rowsFunction · 0.85
fitMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected