From e397c2388949cbe6232a18a144f37db0924f4ab3 Mon Sep 17 00:00:00 2001 From: Ze Ou <38440136+zeou1@users.noreply.github.com> Date: Sun, 27 Sep 2020 18:03:17 -0400 Subject: [PATCH] Added n_features_in_ to three of the embedded class estimators (continued from #434) (#462) * added n_features_in_ to all four estimator classes * to trigger netlify * revert back for netlify * Fix grammar Co-authored-by: zeou1 Co-authored-by: Benjamin Pedigo --- graspy/embed/ase.py | 3 +++ graspy/embed/base.py | 2 ++ graspy/embed/lse.py | 4 ++++ graspy/embed/mds.py | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/graspy/embed/ase.py b/graspy/embed/ase.py index d0eee17c0..03be2dd3c 100644 --- a/graspy/embed/ase.py +++ b/graspy/embed/ase.py @@ -71,6 +71,8 @@ class AdjacencySpectralEmbed(BaseEmbed): Attributes ---------- + n_features_in_: int + Number of features passed to the fit method. latent_left_ : array, shape (n_samples, n_components) Estimated left latent positions of the graph. latent_right_ : array, shape (n_samples, n_components), or None @@ -154,5 +156,6 @@ def fit(self, graph, y=None): if self.diag_aug: A = augment_diagonal(A) + self.n_features_in_ = len(A) self._reduce_dim(A) return self diff --git a/graspy/embed/base.py b/graspy/embed/base.py index a332fe018..5973e0525 100644 --- a/graspy/embed/base.py +++ b/graspy/embed/base.py @@ -50,6 +50,8 @@ class BaseEmbed(BaseEstimator): ---------- n_components_ : int Dimensionality of the embedded space. + n_features_in_: int + Number of features passed to the fit method. See Also -------- diff --git a/graspy/embed/lse.py b/graspy/embed/lse.py index 9f7d4129f..cb65c9a47 100644 --- a/graspy/embed/lse.py +++ b/graspy/embed/lse.py @@ -66,6 +66,9 @@ class LaplacianSpectralEmbed(BaseEmbed): Attributes ---------- + n_features_in_: int + Number of features passed to the fit method. + latent_left_ : array, shape (n_samples, n_components) Estimated left latent positions of the graph. @@ -157,6 +160,7 @@ def fit(self, graph, y=None): ) warnings.warn(msg, UserWarning) + self.n_features_in_ = len(A) L_norm = to_laplace(A, form=self.form, regularizer=self.regularizer) self._reduce_dim(L_norm) return self diff --git a/graspy/embed/mds.py b/graspy/embed/mds.py index 0ffb67398..34f9ede31 100644 --- a/graspy/embed/mds.py +++ b/graspy/embed/mds.py @@ -60,6 +60,9 @@ class ClassicalMDS(BaseEstimator): Equals the parameter n_components. If input n_components was None, then equals the optimal embedding dimension. + n_features_in_: int + Number of features passed to the fit method. + components_ : array, shape (n_components, n_features) Principal axes in feature space. @@ -192,6 +195,7 @@ def fit(self, X, y=None): self.components_ = U self.singular_values_ = D ** 0.5 self.dissimilarity_matrix_ = dissimilarity_matrix + self.n_features_in_ = X.shape[1] return self