sklears_python/
model_selection.rs1use numpy::{PyArray1, PyArray2, PyReadonlyArray1, PyReadonlyArray2, PyUntypedArrayMethods};
7use pyo3::prelude::*;
8use scirs2_core::ndarray::{Array1, Array2};
9
10#[pyfunction]
12#[allow(clippy::too_many_arguments)]
13#[pyo3(signature = (x, _y=None, _test_size=None, _train_size=None, _random_state=None, _shuffle=true, _stratify=None))]
14pub fn train_test_split(
15 py: Python<'_>,
16 x: PyReadonlyArray2<f64>,
17 _y: Option<PyReadonlyArray1<f64>>,
18 _test_size: Option<f64>,
19 _train_size: Option<f64>,
20 _random_state: Option<u64>,
21 _shuffle: bool,
22 _stratify: Option<PyReadonlyArray1<f64>>,
23) -> PyResult<(
24 Py<PyArray2<f64>>,
25 Py<PyArray2<f64>>,
26 Py<PyArray1<f64>>,
27 Py<PyArray1<f64>>,
28)> {
29 let _n_samples = x.shape()[0];
31
32 let x_train = Array2::<f64>::zeros((1, 1));
33 let x_test = Array2::<f64>::zeros((1, 1));
34 let y_train = Array1::<f64>::zeros(1);
35 let y_test = Array1::<f64>::zeros(1);
36
37 Ok((
38 PyArray2::from_array(py, &x_train).unbind(),
39 PyArray2::from_array(py, &x_test).unbind(),
40 PyArray1::from_array(py, &y_train).unbind(),
41 PyArray1::from_array(py, &y_test).unbind(),
42 ))
43}
44
45#[pyclass(name = "KFold")]
47pub struct PyKFold {
48 n_splits: usize,
49}
50
51#[pymethods]
52impl PyKFold {
53 #[new]
54 fn new(n_splits: usize) -> Self {
55 Self { n_splits }
56 }
57
58 fn get_n_splits(&self) -> usize {
59 self.n_splits
60 }
61
62 fn split(&self, _x: PyReadonlyArray2<f64>) -> PyResult<Vec<(Vec<usize>, Vec<usize>)>> {
63 Ok(vec![(vec![0], vec![1])])
65 }
66}