Descriptor Preprocessor

class DescriptorPreprocessor(nan_strategy='median', max_nan_fraction=0.2, variance_threshold=0.0, with_mean=True, with_std=True)[source]

Clean and standardize a molecular descriptor matrix.

Performs the following steps, in order, on a numeric descriptor matrix:

  1. Drop high-NaN columns — any column whose fraction of NaN values exceeds max_nan_fraction is removed.

  2. Drop constant columns — any column whose variance (computed ignoring NaNs, only over columns that survived step 1) is less than or equal to variance_threshold is removed. This catches descriptors that are identical for every molecule and would carry no information.

  3. Impute remaining NaNs — leftover NaNs in the kept columns are filled with the per-column median or mean learned at fit time.

  4. Standardize — the surviving columns are mean-centered and scaled to unit variance with StandardScaler (each step optional via with_mean / with_std).

The class follows scikit-learn conventions: hyperparameters are stored verbatim in __init__, fitted state lives in trailing-underscore attributes, and the class inherits fit_transform from TransformerMixin. It can therefore be dropped into a Pipeline or ColumnTransformer.

Parameters:
  • nan_strategy ({"median", "mean"}, default="median") – Statistic used to impute remaining NaNs in columns that survive the max_nan_fraction filter. Median is more robust to outlier descriptor values.

  • max_nan_fraction (float, default=0.2) – Columns whose fraction of NaN values strictly exceeds this threshold are dropped. Use 1.0 to keep every column regardless of NaN count, and 0.0 to drop any column containing a single NaN.

  • variance_threshold (float, default=0.0) – Columns with variance <= variance_threshold (computed ignoring NaNs) are dropped. The default removes truly constant descriptors; raise it to also drop near-constant ones.

  • with_mean (bool, default=True) – Mean-center each surviving column. Passed through to the underlying StandardScaler.

  • with_std (bool, default=True) – Scale each surviving column to unit variance. Passed through to the underlying StandardScaler.

kept_columns_

Boolean mask of columns retained after the NaN and variance filters. True means the column was kept.

Type:

ndarray of bool, shape (n_features,)

kept_indices_

Integer indices of the retained columns, equivalent to np.where(kept_columns_)[0].

Type:

ndarray of int

impute_values_

Per-column imputation value (median or mean) for the retained columns, computed on the training data ignoring NaNs.

Type:

ndarray of shape (n_kept_features,)

scaler_

Fitted scaler applied to the imputed, retained columns.

Type:

sklearn.preprocessing.StandardScaler

n_features_in_

Number of features seen during fit.

Type:

int

n_features_out_

Number of features produced by transform.

Type:

int

Examples

>>> import numpy as np
>>> X = np.array([[1.0, 2.0, 5.0, np.nan],
...               [2.0, 2.0, 6.0, 1.0],
...               [3.0, 2.0, 7.0, 2.0]])
>>> pre = DescriptorPreprocessor()
>>> X_clean = pre.fit_transform(X)
>>> X_clean.shape  # NaN and constant columns dropped (1/3 > 0.2), rest scaled
(3, 2)
fit(X, y=None)[source]

Learn the column mask, imputation values, and scaler.

Parameters:
  • X (array-like of shape (n_samples, n_features)) – Raw descriptor matrix. May contain NaNs (but not infs).

  • y (Ignored) – Present for scikit-learn API compatibility.

Returns:

self – The fitted transformer.

Return type:

DescriptorPreprocessor

Raises:

ValueError – If hyperparameters are invalid, or if every column gets dropped by the NaN and variance filters.

transform(X)[source]

Apply the learned column mask, imputation, and scaling.

Parameters:

X (array-like of shape (n_samples, n_features)) – Raw descriptor matrix with the same number of columns as the matrix seen during fit. May contain NaNs (but not infs).

Returns:

X_out – Cleaned, imputed, and (optionally) standardized matrix.

Return type:

ndarray of shape (n_samples, n_features_out_)

Raises:
  • sklearn.exceptions.NotFittedError – If fit has not been called.

  • ValueError – If the number of features in X does not match the training matrix.

get_feature_names_out(input_features=None)[source]

Return the names of the retained features.

Parameters:

input_features (array-like of str, optional) – Names of the input columns. If None, generic names of the form "x0", "x1", … are generated.

Returns:

Names of the features produced by transform, in order.

Return type:

ndarray of str