river icon indicating copy to clipboard operation
river copied to clipboard

Applying TimeRolling in LogisticRegression

Open cdeterman opened this issue 1 year ago β€’ 0 comments

river version: 0.21.2 Python version: 3.10 Operating system: Windows

Describe the bug

Steps/code to reproduce

# Sample code to reproduce the problem
# Please do your best to provide a Minimal, Reproducible Example: https://stackoverflow.com/help/minimal-reproducible-example

def define_model(alpha):
    regression = linear_model.LogisticRegression(intercept_lr=0,
                                                            optimizer=optim.SGD(0.0001),
                                                            loss=optim.losses.Quantile(alpha))

        pipeline = compose.Pipeline(
            # THIS IS THE LOCATION FOR FEATURE ENGINEERING
            ('features', compose.TransformerUnion(
                compose.Select(β€˜var1’, β€˜var2’),
                ('Target_30_days', feature_extraction.TargetAgg(
                    by=['group'],
                    how=utils.TimeRolling(stats.Mean(), dt.timedelta(days=30))
                ))
            )),
            ('scale', preprocessing.StandardScaler()),
            ('lin_reg', preprocessing.TargetStandardScaler(
                regression
            ))
        )
        return pipeline

def train():

        # set streaming data (ultimately want to connect to Kafka)
        sdf = self.rdm.stream_data()
        i = 0

        for idv, target in sdf:
            # get instance date
            t = idv[self.rdm.target_dt]
            
            # Obtain prior prediction and update model in one go
            y_est = model.predict_one(idv)
            
            # learn
            model.learn_one(x=idv, y=target, t=t)

This then throws the error:

TypeError: TimeRolling.update() missing 1 required keyword-only argument: 't'

cdeterman avatar Aug 28 '24 14:08 cdeterman