mobook / MO-book

Hands-On Optimization with Python
MIT License
153 stars 40 forks source link

Issue on page /notebooks/02/08-L1-regression-wine-quality.html #76

Closed jon-nowacki closed 3 months ago

jon-nowacki commented 8 months ago

Your issue content here.

the last cell errors out.

ERROR:pyomo.common.numeric_types:evaluating object as numeric value: e_pos[1]
    (object: <class 'pyomo.core.base.var._GeneralVarData'>)
No value for uninitialized NumericValue object e_pos[1]
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-8-b4122d953b2a>](https://localhost:8080/#) in <cell line: 2>()
      1 mad = (wines["alcohol"] - wines["alcohol"].mean()).abs().mean()
----> 2 vars = {i: lad_fit_1(wines, "quality", i).MAD() for i in wines.columns}
      3 colors = plt.get_cmap("tab20c")
      4 fig, ax = plt.subplots()
      5 pd.Series(vars).plot(kind="bar", ax=ax, grid=True, alpha=0.7, color=colors(0.0))

7 frames
[/usr/local/lib/python3.10/dist-packages/pyomo/common/numeric_types.py](https://localhost:8080/#) in value(obj, exception)
    308             tmp = obj(exception=True)
    309             if tmp is None:
--> 310                 raise ValueError(
    311                     "No value for uninitialized NumericValue object %s" % (obj.name,)
    312                 )

ValueError: No value for uninitialized NumericValue object e_pos[1]
alessandrozocca commented 3 months ago

Thanks for spotting the error. The various lad_fit_1(wines, "quality", i) models were built but never solved. The latest commit fixes this issue.