question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

local variable 'nb_epoch' referenced before assignment for benchmark xgb model on qm9

See original GitHub issue

Hi,

I am trying to run a XGBoost model on the qm9 dataset, but I run into a “UnboundLocalError: local variable ‘nb_epoch’ referenced before assignment”. The other error that I have run into is there is a 1 missing positional argument with model.

I am trying to run a linear regression.

Code:

import deepchem as dc from deepchem.molnet import load_qm9 tasks, datasets, transformers = dc.molnet.load_qm9(featurizer= dc.feat.CoulombMatrixEig(max_atoms=50)) train_dataset, valid_dataset, test_dataset = datasets metric = dc.metrics.Metric(dc.metrics.mae_score) train_scores, valid_scores, test_scores = benchmark_regression(train_dataset = train_dataset, valid_dataset = valid_dataset, test_dataset = test_dataset, tasks = tasks, transformers = transformers, n_features = 2, metric = metric, model = "xgb_regression")

For reference, I am using the benchmark regression found here: https://github.com/deepchem/deepchem/blob/2313f885cb86a87167e99b875d706abdc6526c35/deepchem/molnet/run_benchmark_models.py#L346

I am using a jupyter notebook, and had ran the benchmark_regression function code in a separate cell. For the function code, I replaced import xgboost xgboost_model = xgboost.XGBRegressor( with from deepchem.models.gbdt_models.gbdt_model import GBDTModel xgboost_model = GBDTModel( due to a prior deprecation in line 736.

On a side note, what would be the correct number of features?

Issue Analytics

  • State:open
  • Created 10 months ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
maithili232commented, Dec 8, 2022

Hi @dgodin19. There is a minor fix in your approach. dc_model should be defined as an XGboost model wrapped using GBDTModel instead of wrapping LinearRegression() in SklearnModel. Also, n_features is an optional argument. which is set to 0 by default. It is usually used when users use their own featurizers. Do let me know if you face any errors after making the change. Thank you for pointing out the change in run_benchmark_models.py, appreciate your input.

0reactions
dgodin19commented, Dec 9, 2022

Hi @maithili232 ,

I still run into “ValueError: GBDTModel is not a supported model instance” with the given snippet.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Local variable 'nb_epoch' referenced before assignment ...
Hi, I am trying to run a XGBoost model on the qm9 dataset, but I run into a “UnboundLocalError: local variable 'nb_epoch' referenced...
Read more >
local variable 'column_indexes' referenced before ...
import pandas as pd import xgboost as xgb def fun(): from dask.distributed import Client, wait from dask_cuda import LocalCUDACluster with ...
Read more >
Python local variable referenced before assignment Solution
You can solve this error by ensuring that a local variable is declared before you assign it a value.
Read more >
dask.ml.xgboost raises UnboundLocalError: local variable ' ...
I found the issue. I wass missing a from_delayed call to transform the geopandas dataframe to a dask one: dxgb.predict(client, model, ...
Read more >
Local vs Global and how to fix "local variable referenced ...
Local vs Global and how to fix " local variable referenced before assignment ". 2.2K views 2 years ago. Ron McKenzie. Ron McKenzie....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found