From 60b484c1ba0648a52211662038e53818dc0f7afb Mon Sep 17 00:00:00 2001 From: Ainsleigh Hill Date: Fri, 30 Aug 2024 15:47:33 -0700 Subject: [PATCH 1/5] add x_data setter --- parc/_parc.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/parc/_parc.py b/parc/_parc.py index f40a5e9..217b0da 100644 --- a/parc/_parc.py +++ b/parc/_parc.py @@ -17,8 +17,6 @@ class PARC: """``PARC``: ``P``henotyping by ``A``ccelerated ``R``efined ``C``ommunity-partitioning. Attributes: - x_data: - An array of the input x data, with dimensions ``(n_samples, n_features)``. y_data_true: An array of the true output y labels. y_data_pred: @@ -154,6 +152,17 @@ def __init__( self.resolution_parameter = resolution_parameter self.partition_type = partition_type + @property + def x_data(self) -> np.ndarray: + """An array of the input x data, with dimensions ``(n_samples, n_features)``.""" + return self._x_data + + @x_data.setter + def x_data(self, x_data: np.ndarray | pd.DataFrame): + if isinstance(x_data, pd.DataFrame): + x_data = x_data.to_numpy() + self._x_data = x_data + @property def y_data_true(self) -> np.ndarray: return self._y_data_true From 0a1f3fa8060994a2f256af20639e620f45f578dd Mon Sep 17 00:00:00 2001 From: Ainsleigh Hill Date: Fri, 30 Aug 2024 15:51:43 -0700 Subject: [PATCH 2/5] modify the` y_data_true` setter --- parc/_parc.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/parc/_parc.py b/parc/_parc.py index 217b0da..5b6789c 100644 --- a/parc/_parc.py +++ b/parc/_parc.py @@ -17,8 +17,6 @@ class PARC: """``PARC``: ``P``henotyping by ``A``ccelerated ``R``efined ``C``ommunity-partitioning. Attributes: - y_data_true: - An array of the true output y labels. y_data_pred: An array of the predicted output y labels. knn: @@ -110,7 +108,7 @@ class PARC: def __init__( self, x_data: np.ndarray, - y_data_true: np.ndarray | None = None, + y_data_true: np.ndarray | pd.Series | list[int] | None = None, knn: int = 30, n_iter_leiden: int = 5, random_seed: int = 42, @@ -165,12 +163,17 @@ def x_data(self, x_data: np.ndarray | pd.DataFrame): @property def y_data_true(self) -> np.ndarray: + """An array of the true output y labels, with dimensions ``(n_samples, 1)``.""" return self._y_data_true @y_data_true.setter - def y_data_true(self, y_data_true: np.ndarray | None): + def y_data_true(self, y_data_true: np.ndarray | pd.Series | list[int] | None): if y_data_true is None: y_data_true = [1] * self.x_data.shape[0] + elif isinstance(y_data_true, pd.Series): + y_data_true = y_data_true.to_numpy() + elif isinstance(y_data_true, list): + y_data_true = np.array(y_data_true) self._y_data_true = y_data_true @property From acc585aba60199f4ebd43290fb34b4d6bb21c317 Mon Sep 17 00:00:00 2001 From: Ainsleigh Hill Date: Fri, 30 Aug 2024 15:55:04 -0700 Subject: [PATCH 3/5] add `y_data_pred` setter --- parc/_parc.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/parc/_parc.py b/parc/_parc.py index 5b6789c..462d759 100644 --- a/parc/_parc.py +++ b/parc/_parc.py @@ -17,8 +17,6 @@ class PARC: """``PARC``: ``P``henotyping by ``A``ccelerated ``R``efined ``C``ommunity-partitioning. Attributes: - y_data_pred: - An array of the predicted output y labels. knn: The number of nearest neighbors k for the k-nearest neighbours algorithm. Larger k means more neighbors in a cluster and therefore less clusters. @@ -176,6 +174,19 @@ def y_data_true(self, y_data_true: np.ndarray | pd.Series | list[int] | None): y_data_true = np.array(y_data_true) self._y_data_true = y_data_true + @property + def y_data_pred(self) -> np.ndarray | None: + """An array of the predicted output y labels, with dimensions ``(n_samples, 1)``.""" + return self._y_data_pred + + @y_data_pred.setter + def y_data_pred(self, y_data_pred: np.ndarray | pd.Series | list[int] | None): + if isinstance(y_data_pred, pd.Series): + y_data_pred = y_data_pred.to_numpy() + elif isinstance(y_data_pred, list): + y_data_pred = np.array(y_data_pred) + self._y_data_pred = y_data_pred + @property def do_prune_local(self) -> bool: return self._do_prune_local From 0cf4fd47b69f1d3cd9686fb40355b489ad875e0d Mon Sep 17 00:00:00 2001 From: Ainsleigh Hill Date: Fri, 30 Aug 2024 15:55:49 -0700 Subject: [PATCH 4/5] allow `x_data` to be passed in as `pd.DataFrame` --- parc/_parc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parc/_parc.py b/parc/_parc.py index 462d759..93d5904 100644 --- a/parc/_parc.py +++ b/parc/_parc.py @@ -105,7 +105,7 @@ class PARC: """ def __init__( self, - x_data: np.ndarray, + x_data: np.ndarray | pd.DataFrame, y_data_true: np.ndarray | pd.Series | list[int] | None = None, knn: int = 30, n_iter_leiden: int = 5, From 4419f677bd699ad591bc13903010fb2e3644e8a6 Mon Sep 17 00:00:00 2001 From: Ainsleigh Hill Date: Fri, 30 Aug 2024 16:01:02 -0700 Subject: [PATCH 5/5] fix `y_data_true` setter --- parc/_parc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parc/_parc.py b/parc/_parc.py index 93d5904..19aa469 100644 --- a/parc/_parc.py +++ b/parc/_parc.py @@ -167,7 +167,7 @@ def y_data_true(self) -> np.ndarray: @y_data_true.setter def y_data_true(self, y_data_true: np.ndarray | pd.Series | list[int] | None): if y_data_true is None: - y_data_true = [1] * self.x_data.shape[0] + y_data_true = np.array([1] * self.x_data.shape[0]) elif isinstance(y_data_true, pd.Series): y_data_true = y_data_true.to_numpy() elif isinstance(y_data_true, list):