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

Function sb_fit_predict_regressor

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

Source from the content-addressed store, hash-verified

54 random_state=42,
55 sample_weight=None
56))]
57fn sb_fit_predict_regressor(
58 py: Python<'_>,
59 x: Vec<Vec<f64>>,
60 y: Vec<f64>,
61 ind_mat: Vec<Vec<u8>>,
62 n_estimators: usize,
63 max_samples: f64,
64 max_features: f64,
65 random_state: u64,
66 sample_weight: Option<Vec<f64>>,
67) -> PyResult<PyObject> {
68 let x_mat = matrix_from_rows(x)?;
69
70 let mut reg =
71 openquant::sb_bagging::SequentiallyBootstrappedBaggingRegressor::new(random_state);
72 reg.n_estimators = n_estimators;
73 reg.max_samples = openquant::sb_bagging::MaxSamples::Float(max_samples);
74 reg.max_features = openquant::sb_bagging::MaxFeatures::Float(max_features);
75 reg.oob_score = true;
76
77 reg.fit(&x_mat, &y, &ind_mat, sample_weight.as_deref()).map_err(to_py_err)?;
78 let predictions = reg.predict(&x_mat).map_err(to_py_err)?;
79
80 let d = PyDict::new(py);
81 d.set_item("predictions", predictions)?;
82 d.set_item("oob_score", reg.oob_score_value)?;
83 Ok(d.into_pyobject(py).unwrap().into_any().unbind())
84}
85

Callers

nothing calls this directly

Calls 3

matrix_from_rowsFunction · 0.85
fitMethod · 0.45
predictMethod · 0.45

Tested by

no test coverage detected