Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Building a simple nowcasting model Error - return (loss_gradient * utils.VectorDict(x), loss_gradient) #1486

Closed
oscarstv opened this issue Jan 9, 2024 · 2 comments

Comments

@oscarstv
Copy link

oscarstv commented Jan 9, 2024

river version: 0.13.0
Python version: 3.10
Operating system: macOS - mambaforge
Using Jupyter Lab

Trying to reproduce this tutorial:
https://riverml.xyz/0.13.0/examples/building-a-simple-nowcasting-model/

Error when Jupiter executes:
evaluate_model(model)

What I get:


TypeError Traceback (most recent call last)
Cell In[6], line 12
4 model = compose.Pipeline(
5 ('ordinal_date', compose.FuncTransformer(get_ordinal_date)),
6 ('scale', preprocessing.StandardScaler()),
7 ('lin_reg', linear_model.LinearRegression(intercept_lr=0)),
8 )
10 model = preprocessing.TargetStandardScaler(regressor=model)
---> 12 evaluate_model(model)

Cell In[4], line 23, in evaluate_model(model)
19 for x, y in datasets.AirlinePassengers():
20
21 # Obtain the prior prediction and update the model in one go
22 y_pred = model.predict_one(x)
---> 23 model.learn_one(x, y)
25 # Update the error metric
26 metric.update(y, y_pred)

File ~/mambaforge/envs/my_jordi_env/lib/python3.10/site-packages/river/preprocessing/scale.py:590, in TargetStandardScaler.learn_one(self, x, y)
588 def learn_one(self, x, y):
589 self.var.update(y)
--> 590 return super().learn_one(x, y)

File ~/mambaforge/envs/my_jordi_env/lib/python3.10/site-packages/river/compose/target_transform.py:62, in TargetTransformRegressor.learn_one(self, x, y)
61 def learn_one(self, x, y):
---> 62 self.regressor.learn_one(x, self.func(y))
63 return self

File ~/mambaforge/envs/my_jordi_env/lib/python3.10/site-packages/river/compose/pipeline.py:533, in Pipeline.learn_one(self, x, y, **params)
531 last_step = next(steps)
532 if last_step._supervised:
--> 533 last_step.learn_one(x=x, y=y, **params)
534 else:
535 last_step.learn_one(x, **params)

File ~/mambaforge/envs/my_jordi_env/lib/python3.10/site-packages/river/linear_model/base.py:166, in GLM.learn_one(self, x, y, w)
164 def learn_one(self, x, y, w=1.0):
165 with self._learn_mode(x):
--> 166 self._fit(x, y, w, get_grad=self._eval_gradient_one)

File ~/mambaforge/envs/my_jordi_env/lib/python3.10/site-packages/river/linear_model/base.py:110, in GLM._fit(self, x, y, w, get_grad)
107 self.optimizer.look_ahead(w=self._weights)
109 # Calculate the gradient
--> 110 gradient, loss_gradient = get_grad(x, y, w)
112 # Update the intercept
113 self.intercept -= self._get_intercept_update(loss_gradient)

File ~/mambaforge/envs/my_jordi_env/lib/python3.10/site-packages/river/linear_model/base.py:162, in GLM._eval_gradient_one(self, x, y, w)
156 if self.l2:
157 return (
158 loss_gradient * utils.VectorDict(x) + self.l2 * self._weights,
159 loss_gradient,
160 )
--> 162 return (loss_gradient * utils.VectorDict(x), loss_gradient)

TypeError: unsupported operand type(s) for *: 'float' and 'river.utils.vectordict.VectorDict'

Thank you!

@oscarstv
Copy link
Author

oscarstv commented Jan 9, 2024

Solved installing from terminal River 0.21.0

@oscarstv
Copy link
Author

oscarstv commented Jan 9, 2024

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant