Preprocessing Data

class seawrd.preprocessing_data.DataPreprocessor(df: DataFrame, features: Sequence[str] | None = None, label: str | None = None, test_size: float = 0.2, random_state: int | None = 0, quality_column: str | None = 'errcode', quality_value: int | None = 0, normalise: bool = True)

Bases: object

Preprocess planetary data for ML regression training.

This class validates a pandas DataFrame, derives common planet-level features, filters poor-quality rows, and returns train/test splits ready for a Keras regression model.

DERIVED_COLUMNS = {'M_p': ('M_a', 'M_b'), 'R_p': ('R_a', 'R_b')}
get_training_data(return_array: bool = True) Tuple[keras.layers.Normalization | None, pd.DataFrame | np.ndarray, pd.DataFrame | np.ndarray, pd.Series | np.ndarray, pd.Series | np.ndarray]

Return train/test splits and an optional fitted normaliser.

Parameters:

return_array (bool, default=True) – If True, return NumPy arrays instead of DataFrames/Series. These arrays will be of type float32, suitable for Keras models.

Returns:

  • normaliser (Optional[keras.layers.Normalization]) – The fitted Keras Normalization layer if normalization is enabled, otherwise None.

  • train_features (Union[pd.DataFrame, np.ndarray]) – Training features as a pandas DataFrame or NumPy array.

  • test_features (Union[pd.DataFrame, np.ndarray]) – Testing features as a pandas DataFrame or NumPy array.

  • train_labels (Union[pd.Series, np.ndarray]) – Training labels as a pandas Series or NumPy array.

  • test_labels (Union[pd.Series, np.ndarray]) – Testing labels as a pandas Series or NumPy array.

save_to_npz(path: str | PathLike) None

Save the prepared data to a .npz file.

Parameters:

path (Union[str, os.PathLike]) – The file path where the .npz file will be saved.

split() Tuple[DataFrame, DataFrame, Series, Series]

Split the pandas DataFrame into training and testing sets.

Returns:

  • trainn_df (pd.DataFrame) – Training features pandas DataFrame.

  • test_df (pd.DataFrame) – Testing features pandas DataFrame.

  • train_labels (pd.Series) – Training labels pandas Series.

  • test_labels (pd.Series) – Testing labels pandas Series.