ihmeuw-msca / regmod

General regression models.
BSD 2-Clause "Simplified" License
5 stars 3 forks source link

Feature request: Model.predict doesn't automatically modify the input data #61

Open davidshaw2018 opened 1 year ago

davidshaw2018 commented 1 year ago

Ideally, when we predict out on a fitted model, the predict method doesn't automatically modify the input dataset as it does here: https://github.com/ihmeuw-msca/regmod/blob/develop/src/regmod/models/model.py#L621

A proposed alternative:

def predict(df, inplace=True):
    ....
    return_df = pd.DataFrame()
    for i, param_name in enumerate(self.param_names):
        return_df[param_name] = self.params[i].get_param(coefs[i], data)
        if inplace:
            df[param_name] = return_df[param_name]
   return return_df

This way, the same default behavior is provided, but users passing in slices of dataframes or who in general rely on pure functions can also have that behavior enabled optionally.

davidshaw2018 commented 1 year ago

By the way, happy to do this myself too if Kelsey's busy!