RuleTree.utils.light_famd package#

Submodules#

RuleTree.utils.light_famd.ca module#

Correspondence Analysis (CA)

class CA(n_components=2, n_iter=10, copy=True, check_input=True, random_state=None, engine='auto')[source]#

Bases: BaseEstimator, TransformerMixin

Correspondence Analysis of a contingency table.

Parameters:
  • n_components (int, default=2) – Number of components.

  • n_iter (int, default=10) – Number of iterations of the randomized SVD.

  • copy (bool, default=True) – Whether to copy the data.

  • check_input (bool, default=True) – Whether to check the input.

  • random_state (int, default=None) – Seed of the SVD.

  • engine ({'auto', 'sklearn', 'fbpca'}, default='auto') – SVD implementation.

fit(X, y=None)[source]#

Fit the CA.

Parameters:
  • X (array-like of shape (n_rows, n_columns)) – Contingency table.

  • y (None) – Not used.

Returns:

self

Return type:

CA

transform(X)[source]#

Computes the row principal coordinates of a dataset.

Same as calling row_coordinates. In most cases you should be using the same dataset as you did when calling the fit method. You might however also want to included supplementary data.

property explained_variance_#

The eigenvalues associated with each principal component.

property explained_variance_ratio_#

The percentage of explained inertia per principal component.

RuleTree.utils.light_famd.famd module#

Factor Analysis of Mixed Data (FAMD)

class FAMD(n_components=2, n_iter=2, copy=False, check_input=True, random_state=None, engine='auto')[source]#

Bases: MFA

Factor Analysis of Mixed Data: an MFA with a group of numerical features and a group of categorical features. Used by RuleTreeCluster for mixed data.

Parameters:
  • n_components – See PCA.

  • n_iter – See PCA.

  • copy – See PCA.

  • check_input – See PCA.

  • random_state – See PCA.

  • engine – See PCA.

fit(X, y=None)[source]#

Fit the FAMD, grouping the columns into numerical and categorical.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

self

Return type:

FAMD

fit_transform(X, y=None)[source]#

Fit the FAMD and return the row principal coordinates.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

coordinates

Return type:

numpy.ndarray of shape (n_samples, n_components)

RuleTree.utils.light_famd.mca module#

Multiple Correspondence Analysis (MCA)

class MCA(n_components=2, n_iter=10, copy=True, check_input=True, random_state=None, engine='auto')[source]#

Bases: CA

Multiple Correspondence Analysis of categorical data: a CA of their one-hot encoding. Used by RuleTreeCluster for categorical data.

fit(X, y=None)[source]#

Fit the MCA.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Categorical data.

  • y (None) – Not used.

Returns:

self

Return type:

MCA

transform(X)[source]#

Computes the row principal coordinates of a dataset.

RuleTree.utils.light_famd.mfa module#

Multiple Factor Analysis (MFA)

class MFA(groups=None, normalize=True, n_components=2, n_iter=2, copy=True, check_input=True, random_state=None, engine='auto')[source]#

Bases: PCA

Multiple Factor Analysis: a PCA of groups of features, each normalized by its first singular value.

Parameters:
  • groups (dict, default=None) – Name -> list of columns of each group.

  • normalize (bool, default=True) – Whether to standardize the numerical groups.

  • n_components – See PCA.

  • n_iter – See PCA.

  • copy – See PCA.

  • check_input – See PCA.

  • random_state – See PCA.

  • engine – See PCA.

fit(X, y=None)[source]#

Fit the MFA.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

self

Return type:

MFA

transform(X)[source]#

Returns the row principal coordinates of a dataset.

fit_transform(X)[source]#

Fit the MFA and return the row principal coordinates.

Parameters:

X (array-like of shape (n_samples, n_features))

Returns:

coordinates

Return type:

numpy.ndarray of shape (n_samples, n_components)

column_correlation(X, same_input=True)[source]#

Correlation between the original columns and the principal components.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • same_input (bool, default=True) – Whether X is the training data.

Returns:

correlation

Return type:

pandas.DataFrame

RuleTree.utils.light_famd.one_hot module#

This module contains a custom one-hot encoder. It inherits from sklearn’s OneHotEncoder and returns a pandas.SparseDataFrame with appropriate column names and index values.

class OneHotEncoder[source]#

Bases: OneHotEncoder

One-hot encoder returning a DataFrame with a column per category.

fit(X, y=None)[source]#

Fit the encoder.

Parameters:
Returns:

self

Return type:

OneHotEncoder

transform(X)[source]#

One-hot encoding of X.

Parameters:

X (pandas.DataFrame)

Returns:

X_encoded

Return type:

pandas.DataFrame

RuleTree.utils.light_famd.pca module#

Principal Component Analysis (PCA)

class PCA(rescale_with_mean=True, rescale_with_std=True, n_components=2, n_iter=2, copy=True, check_input=True, random_state=None, engine='auto')[source]#

Bases: BaseEstimator, TransformerMixin

Principal Component Analysis. Used by RuleTreeCluster for numerical data.

Parameters:
  • rescale_with_mean (bool, default=True) – Whether to subtract the mean of each column.

  • rescale_with_std (bool, default=True) – Whether to divide each column by its standard deviation.

  • n_components (int, default=2) – Number of principal components.

  • n_iter (int, default=2) – Number of iterations of the randomized SVD.

  • copy (bool, default=True) – Whether to copy the data.

  • check_input (bool, default=True) – Whether to check the input.

  • random_state (int, default=None) – Seed of the SVD.

  • engine ({'auto', 'sklearn', 'fbpca'}, default='auto') – SVD implementation.

fit(X, y=None)[source]#

Fit the PCA.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

self

Return type:

PCA

transform(X)[source]#

Computes the row principal coordinates of a dataset.

Same as calling row_coordinates. In most cases you should be using the same dataset as you did when calling the fit method. You might however also want to included supplementary data.

invert_transform(X)[source]#

Map X back to the original space: X @ components_ (whitening is not inverted).

fit_transform(X, y=None)[source]#

Fit the PCA and return the row principal coordinates.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

coordinates

Return type:

numpy.ndarray of shape (n_samples, n_components)

column_correlation(X, same_input=True)[source]#

Returns the column correlations with each principal component.

property explained_variance_#

Returns the eigenvalues associated with each principal component.

property explained_variance_ratio_#

Returns the percentage of explained inertia per principal component.

RuleTree.utils.light_famd.svd module#

Singular Value Decomposition (SVD)

compute_svd(X, n_components, n_iter, random_state, engine)[source]#

Computes an SVD with k components.

RuleTree.utils.light_famd.util module#

Correlation helpers of light_famd.

df_correlation(DF_C, DF_INDEX)[source]#

Correlation between the columns of two DataFrames.

Parameters:
Returns:

correlation

Return type:

pandas.DataFrame

Module contents#

class CA(n_components=2, n_iter=10, copy=True, check_input=True, random_state=None, engine='auto')[source]

Bases: BaseEstimator, TransformerMixin

Correspondence Analysis of a contingency table.

Parameters:
  • n_components (int, default=2) – Number of components.

  • n_iter (int, default=10) – Number of iterations of the randomized SVD.

  • copy (bool, default=True) – Whether to copy the data.

  • check_input (bool, default=True) – Whether to check the input.

  • random_state (int, default=None) – Seed of the SVD.

  • engine ({'auto', 'sklearn', 'fbpca'}, default='auto') – SVD implementation.

fit(X, y=None)[source]

Fit the CA.

Parameters:
  • X (array-like of shape (n_rows, n_columns)) – Contingency table.

  • y (None) – Not used.

Returns:

self

Return type:

CA

transform(X)[source]

Computes the row principal coordinates of a dataset.

Same as calling row_coordinates. In most cases you should be using the same dataset as you did when calling the fit method. You might however also want to included supplementary data.

property explained_variance_

The eigenvalues associated with each principal component.

property explained_variance_ratio_

The percentage of explained inertia per principal component.

class FAMD(n_components=2, n_iter=2, copy=False, check_input=True, random_state=None, engine='auto')[source]

Bases: MFA

Factor Analysis of Mixed Data: an MFA with a group of numerical features and a group of categorical features. Used by RuleTreeCluster for mixed data.

Parameters:
  • n_components – See PCA.

  • n_iter – See PCA.

  • copy – See PCA.

  • check_input – See PCA.

  • random_state – See PCA.

  • engine – See PCA.

fit(X, y=None)[source]

Fit the FAMD, grouping the columns into numerical and categorical.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

self

Return type:

FAMD

fit_transform(X, y=None)[source]

Fit the FAMD and return the row principal coordinates.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

coordinates

Return type:

numpy.ndarray of shape (n_samples, n_components)

class MCA(n_components=2, n_iter=10, copy=True, check_input=True, random_state=None, engine='auto')[source]

Bases: CA

Multiple Correspondence Analysis of categorical data: a CA of their one-hot encoding. Used by RuleTreeCluster for categorical data.

fit(X, y=None)[source]

Fit the MCA.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Categorical data.

  • y (None) – Not used.

Returns:

self

Return type:

MCA

transform(X)[source]

Computes the row principal coordinates of a dataset.

class PCA(rescale_with_mean=True, rescale_with_std=True, n_components=2, n_iter=2, copy=True, check_input=True, random_state=None, engine='auto')[source]

Bases: BaseEstimator, TransformerMixin

Principal Component Analysis. Used by RuleTreeCluster for numerical data.

Parameters:
  • rescale_with_mean (bool, default=True) – Whether to subtract the mean of each column.

  • rescale_with_std (bool, default=True) – Whether to divide each column by its standard deviation.

  • n_components (int, default=2) – Number of principal components.

  • n_iter (int, default=2) – Number of iterations of the randomized SVD.

  • copy (bool, default=True) – Whether to copy the data.

  • check_input (bool, default=True) – Whether to check the input.

  • random_state (int, default=None) – Seed of the SVD.

  • engine ({'auto', 'sklearn', 'fbpca'}, default='auto') – SVD implementation.

fit(X, y=None)[source]

Fit the PCA.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

self

Return type:

PCA

transform(X)[source]

Computes the row principal coordinates of a dataset.

Same as calling row_coordinates. In most cases you should be using the same dataset as you did when calling the fit method. You might however also want to included supplementary data.

invert_transform(X)[source]

Map X back to the original space: X @ components_ (whitening is not inverted).

fit_transform(X, y=None)[source]

Fit the PCA and return the row principal coordinates.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

coordinates

Return type:

numpy.ndarray of shape (n_samples, n_components)

column_correlation(X, same_input=True)[source]

Returns the column correlations with each principal component.

property explained_variance_

Returns the eigenvalues associated with each principal component.

property explained_variance_ratio_

Returns the percentage of explained inertia per principal component.

class MFA(groups=None, normalize=True, n_components=2, n_iter=2, copy=True, check_input=True, random_state=None, engine='auto')[source]

Bases: PCA

Multiple Factor Analysis: a PCA of groups of features, each normalized by its first singular value.

Parameters:
  • groups (dict, default=None) – Name -> list of columns of each group.

  • normalize (bool, default=True) – Whether to standardize the numerical groups.

  • n_components – See PCA.

  • n_iter – See PCA.

  • copy – See PCA.

  • check_input – See PCA.

  • random_state – See PCA.

  • engine – See PCA.

fit(X, y=None)[source]

Fit the MFA.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • y (None) – Not used.

Returns:

self

Return type:

MFA

transform(X)[source]

Returns the row principal coordinates of a dataset.

fit_transform(X)[source]

Fit the MFA and return the row principal coordinates.

Parameters:

X (array-like of shape (n_samples, n_features))

Returns:

coordinates

Return type:

numpy.ndarray of shape (n_samples, n_components)

column_correlation(X, same_input=True)[source]

Correlation between the original columns and the principal components.

Parameters:
  • X (array-like of shape (n_samples, n_features))

  • same_input (bool, default=True) – Whether X is the training data.

Returns:

correlation

Return type:

pandas.DataFrame