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']: recordscols.
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 (orNonewhen loaded from an in-memory object).m.data_args: stores theread_csvkeyword 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(populatesm.data_on_modelin-place).- Updates on
m:m.data_on_model: sets{col: jnp.array(m.df[col].values)}for each column incols.m.data_modification['data_on_model']: recordscols.
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 DataFramem.dfwith addedindex_<col>columns.- Updates on
m:m.df: adds 0-based integer columnsindex_<col>(int64) for each encoded column and replaces.and spaces inm.df.columnswith_.m.index_map: dictionary mapping each encoded column namecolto{code: category_label}.m.data_modification['index']: recordscols.
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 fromm.df) or static default values.- Updates on
m: Does not mutatemdirectly when called standalone, but is called automatically bym.fit()andm.svi()to populatem.data_on_modelwhenm.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 DataFramem.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']: recordsdata.
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 DataFramem.df.- Updates on
m:m.df: casts the specified columns ofm.dfin-place totype.m.data_modification['float']: recordscols.
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(modifiesm.dfin-place).- Updates on
m:m.df: casts the specified columns ofm.dfin-place totype.m.data_modification['int']: recordscols.
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 modifym.df.