sklears_python/
clustering.rs1use numpy::{PyArray1, PyReadonlyArray2};
7use pyo3::prelude::*;
8use scirs2_core::ndarray::Array1;
9
10#[pyclass(name = "KMeans")]
12pub struct PyKMeans {
13 n_clusters: usize,
14}
15
16#[pymethods]
17impl PyKMeans {
18 #[new]
19 fn new(n_clusters: usize) -> Self {
20 Self { n_clusters }
21 }
22
23 fn fit(&mut self, _x: PyReadonlyArray2<f64>) -> PyResult<()> {
24 let _clusters = self.n_clusters;
26 Ok(())
27 }
28
29 fn predict(&self, _x: PyReadonlyArray2<f64>, py: Python<'_>) -> PyResult<Py<PyArray1<i32>>> {
30 let labels = Array1::<i32>::zeros(1);
31 Ok(PyArray1::from_array(py, &labels).unbind())
32 }
33}
34
35#[pyclass(name = "DBSCAN")]
37pub struct PyDBSCAN {
38 eps: f64,
39}
40
41#[pymethods]
42impl PyDBSCAN {
43 #[new]
44 fn new(eps: f64) -> Self {
45 Self { eps }
46 }
47
48 fn fit(&mut self, _x: PyReadonlyArray2<f64>) -> PyResult<()> {
49 let _epsilon = self.eps;
51 Ok(())
52 }
53
54 fn predict(&self, _x: PyReadonlyArray2<f64>, py: Python<'_>) -> PyResult<Py<PyArray1<i32>>> {
55 let labels = Array1::<i32>::zeros(1);
56 Ok(PyArray1::from_array(py, &labels).unbind())
57 }
58}