Data (m.data, m.scale, …)

Loading and preparing data. m.df holds the data frame; m.data_on_model the arrays passed to the model.

m.OHE

m.OHE(cols='all')

Perform one-hot encoding on specified columns

Argument Type Description
cols str or list Columns to encode. Use 'all' for all object-type columns.

Returns

  • pd.DataFrame: DataFrame containing the newly created one-hot encoded columns (with . and spaces in column names replaced by _).
  • Updates on m:
    • m.df: appends the newly created one-hot encoded columns in-place (m.df = pd.concat([m.df, OHE], axis=1)).
    • m.data_modification['OHE']: records cols.

m.data

m.data(path, **kwargs)

Load tabular data.

Argument Type Description
path str, path-like or data frame Path to a CSV file, or an in-memory table: a pandas DataFrame, or anything pandas.DataFrame() accepts (e.g. a dict of columns). R data.frames passed through reticulate arrive as pandas DataFrames, so R users can pass their data directly without writing a file.
**kwargs Additional arguments for pd.read_csv (CSV paths only).

Returns

  • pd.DataFrame: Loaded dataframe (m.df).
  • Updates on m:
    • m.df: stores a copy of the loaded DataFrame.
    • m.data_original_path: stores the CSV path (or None when loaded from an in-memory object).
    • m.data_args: stores the read_csv keyword arguments (dict).
    • m.data_modification: resets to {}.

m.data_to_model

m.data_to_model(cols)

Prepare data for model input in JAX format

Argument Type Description
cols list List of column names from m.df to include in the model data dictionary.

Returns

  • None (populates m.data_on_model in-place).
  • Updates on m:
    • m.data_on_model: sets {col: jnp.array(m.df[col].values)} for each column in cols.
    • m.data_modification['data_on_model']: records cols.

m.index

m.index(cols='all')

Create index encoding for categorical columns

Codes are 0-based and follow the category order: the level order of a pandas Categorical or R factor, alphabetical for text columns. m.index_map[col] maps each code to its level.

Argument Type Description
cols str or list Columns to encode. Use 'all' for all text (object) and category columns (e.g. R factors).

Returns

  • pd.DataFrame: The updated DataFrame m.df with added index_<col> columns.
  • Updates on m:
    • m.df: adds 0-based integer columns index_<col> (int64) for each encoded column and replaces . and spaces in m.df.columns with _.
    • m.index_map: dictionary mapping each encoded column name col to {code: category_label}.
    • m.data_modification['index']: records cols.

m.pd_to_jax

m.pd_to_jax(model, bit=None)

Convert pandas dataframe to JAX compatible format for a model.

Argument Type Description
model callable Model function whose signature determines which columns to extract from m.df.
bit str, optional Bit precision for numbers (e.g. '32' to force 32-bit types; default None preserves m.df dtypes).

Returns

  • dict: Dictionary mapping the model’s parameter names to JAX arrays (extracted from m.df) or static default values.
  • Updates on m: Does not mutate m directly when called standalone, but is called automatically by m.fit() and m.svi() to populate m.data_on_model when m.data_on_model is None.

m.scale

m.scale(data='all')

Standardize specified columns.

Argument Type Description
data str or list Columns of m.df to standardize (pass a list of column names, or 'all' for all columns).

Returns

  • pd.DataFrame: The standardized DataFrame m.df.
  • Updates on m:
    • m.df: standardizes the specified columns in-place to zero mean and unit standard deviation ((col - col.mean()) / col.std()).
    • m.data_modification['scale']: records data.

m.to_float

m.to_float(cols='all', type='float32')

Convert specified columns to float type

Argument Type Description
cols str or list Columns to convert. Use 'all' for all columns.
type str Float dtype to convert to (default: 'float32').

Returns

  • pd.DataFrame: The converted DataFrame m.df.
  • Updates on m:
    • m.df: casts the specified columns of m.df in-place to type.
    • m.data_modification['float']: records cols.

m.to_int

m.to_int(cols='all', type='int32')

Convert specified columns to integer type

Argument Type Description
cols str or list Columns to convert. Use 'all' for all columns.
type str Integer dtype to convert to (default: 'int32').

Returns

  • None (modifies m.df in-place).
  • Updates on m:
    • m.df: casts the specified columns of m.df in-place to type.
    • m.data_modification['int']: records cols.

m.z_score

m.z_score(X, axis=0)

Performs Z-score scaling (standardization) on a JAX array: (X - mean) / std_dev.

Argument Type Description
X jnp.ndarray The input JAX array (e.g., shape (n_samples, n_features)).
axis int The axis along which to calculate mean and std. axis=0 scales features (columns).

Returns

  • jnp.ndarray: The scaled array. Does not modify m.df.