OCDocker.OCScore.Utils.TrainOnlyFeatureReduction module

Train-only feature reduction for the unified OCScore modeling protocol.

Fits unsupervised feature reduction on training rows only, freezes selected features, and applies the frozen selection to validation/test and DUDEz rows.

class OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.SelectedFeatureRowCleanupResult(cleaned_df, dropped_rows, kept_mask, summary)[source]

Bases: object

Rows retained/dropped after selected-feature finite-value cleanup.

Parameters:
  • cleaned_df (DataFrame)

  • dropped_rows (DataFrame)

  • kept_mask (ndarray)

  • summary (dict[str, Any])

cleaned_df: DataFrame
dropped_rows: DataFrame
kept_mask: ndarray
summary: dict[str, Any]
class OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.TrainOnlyReductionArtifact(selected_features, removed_features, metadata_columns, target_columns, feature_selection, protocol=<factory>, transform_artifacts=<factory>, transform_artifact_hashes=<factory>)[source]

Bases: object

Frozen train-only feature reduction artifact.

Parameters:
  • selected_features (list[str])

  • removed_features (list[str])

  • metadata_columns (list[str])

  • target_columns (list[str])

  • feature_selection (FeatureSelectionScope)

  • protocol (dict[str, Any])

  • transform_artifacts (list[str])

  • transform_artifact_hashes (dict[str, str])

selected_features: list[str]
removed_features: list[str]
metadata_columns: list[str]
target_columns: list[str]
feature_selection: FeatureSelectionScope
protocol: dict[str, Any]
transform_artifacts: list[str]
transform_artifact_hashes: dict[str, str]
to_dict()[source]

Serialize the frozen reduction artifact for JSON persistence.

Returns:

Selected features, scope metadata, and transform artifact hashes.

Return type:

dict[str, Any]

OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.apply_frozen_feature_selection(df, artifact)[source]

Apply frozen selected features to a wide dataframe.

Parameters:
Returns:

Reduced dataframe containing metadata, targets, and selected features.

Return type:

pd.DataFrame

Raises:

ValueError – If required selected features are missing.

OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.drop_nonfinite_selected_feature_rows(df, selected_features, *, label='dataset', id_columns=None, reset_index=True)[source]

Drop rows with NaN, +inf, or -inf values in selected features.

Selected feature values are coerced to numeric first, so blank strings and non-numeric cells are treated as invalid and reported as dropped rows.

Parameters:
  • df (DataFrame)

  • selected_features (Sequence[str])

  • label (str)

  • id_columns (Sequence[str] | None)

  • reset_index (bool)

Return type:

SelectedFeatureRowCleanupResult

OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.feature_reduction_config_for_feature_blocks(target_column='experimental', feature_blocks=None)[source]

Return the OCScore train-only feature-reduction config for selected descriptor blocks.

feature_blocks=None keeps the full protocol. Otherwise only the requested descriptor families are detectable and eligible for feature selection.

Parameters:
  • target_column (str)

  • feature_blocks (Sequence[str] | None)

Return type:

FeatureReductionConfig

OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.fit_train_only_feature_reduction(train_df, *, config=None, target_column='experimental', fit_split='train', fit_dataset='pdbbind_train', feature_blocks=None, candidate_features=None)[source]

Fit feature reduction on training rows only and freeze selected features.

Parameters:
  • train_df (pd.DataFrame) – Wide PDBbind training partition only.

  • config (FeatureReductionConfig | None, optional) – Feature-reduction configuration.

  • target_column (str, optional) – Regression target column preserved outside descriptor blocks.

  • fit_split (str, optional) – Split label recorded in metadata.

  • fit_dataset (str, optional) – Dataset label recorded in metadata.

  • feature_blocks (Sequence[str] | None, optional) – Descriptor blocks eligible for selection. None keeps ligand, receptor, and scoring-function descriptors.

  • candidate_features (Sequence[str] | None, optional) – Ordered policy-constrained candidate descriptors exposed to train-only feature reduction. Metadata and target columns are preserved separately.

Returns:

Frozen selected/removed features and metadata.

Return type:

TrainOnlyReductionArtifact

OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.load_train_only_reduction_artifact(source)[source]

Load a train-only reduction artifact from a directory or JSON file.

Parameters:

source (str | Path)

Return type:

TrainOnlyReductionArtifact

OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.split_wide_dataset_by_column(merged_df, *, dataset_column='dataset', pdbbind_values=None, dudez_values=None)[source]

Split a merged wide dataframe into PDBbind and DUDEz partitions.

Parameters:
  • merged_df (DataFrame)

  • dataset_column (str)

  • pdbbind_values (set[str] | None)

  • dudez_values (set[str] | None)

Return type:

tuple[DataFrame, DataFrame]

OCDocker.OCScore.Utils.TrainOnlyFeatureReduction.write_train_only_reduction_artifact(output_dir, artifact)[source]

Persist train-only reduction artifacts to output_dir.

Parameters:
Return type:

dict[str, str]