sustainable-processes / summit

Optimising chemical reactions using machine learning
https://gosummit.readthedocs.io/en/latest/
MIT License
118 stars 24 forks source link

Error in training using get_bnn() function while trying to access BNNRegressor #267

Closed Mishal-Benz closed 4 months ago

Mishal-Benz commented 4 months ago

Description

Trying to train using the BNNRegressor using get_bnn() function in the summit/benchmarks/experimental_emulator.py file but getting errors with the regressor

What I Did

emul = ExperimentalEmulator(model_name='model_bnn', domain=domain, dataset=ds,regressor=get_bnn())
emul.train(max_epochs=1000, cv_fold=2, test_size=0.25, verbose=0)

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[17], line 3
      1 # Training
      2 emul = ExperimentalEmulator(model_name='model_bnn', domain=domain, dataset=ds,regressor=get_bnn())
----> 3 emul.train(max_epochs=1000, cv_fold=2, test_size=0.25, verbose=0)

File ../summit/benchmarks/experimental_emulator.py:310, in ExperimentalEmulator.train(self, **kwargs)
    308 if not initializing:
    309     self.logger.info("Starting training.")
--> 310 res = cross_validate(
    311     predictor,
    312     self.X_train,
    313     y_train,
    314     scoring=scoring,
    315     cv=folds,
    316     return_estimator=True,
    317 )
    319 self.predictors = res.pop("estimator")
    320 # Rename from test to validation

File ../python3.9/site-packages/sklearn/utils/_param_validation.py:211, in validate_params.<locals>.decorator.<locals>.wrapper(*args, **kwargs)
    205 try:
    206     with config_context(
    207         skip_parameter_validation=(
    208             prefer_skip_nested_validation or global_skip_validation
    209         )
    210     ):
--> 211         return func(*args, **kwargs)
    212 except InvalidParameterError as e:
    213     # When the function is just a wrapper around an estimator, we allow
    214     # the function to delegate validation to the estimator, but we replace
    215     # the name of the estimator by the name of the function in the error
    216     # message to avoid confusion.
    217     msg = re.sub(
    218         r"parameter of \w+ must be",
    219         f"parameter of {func.__qualname__} must be",
    220         str(e),
    221     )

File ../python3.9/site-packages/sklearn/model_selection/_validation.py:328, in cross_validate(estimator, X, y, groups, scoring, cv, n_jobs, verbose, fit_params, pre_dispatch, return_train_score, return_estimator, return_indices, error_score)
    308 parallel = Parallel(n_jobs=n_jobs, verbose=verbose, pre_dispatch=pre_dispatch)
    309 results = parallel(
    310     delayed(_fit_and_score)(
    311         clone(estimator),
   (...)
    325     for train, test in indices
    326 )
--> 328 _warn_or_raise_about_fit_failures(results, error_score)
    330 # For callable scoring, the return type is only know after calling. If the
    331 # return type is a dictionary, the error scores can now be inserted with
    332 # the correct key.
    333 if callable(scoring):

File ../python3.9/site-packages/sklearn/model_selection/_validation.py:414, in _warn_or_raise_about_fit_failures(results, error_score)
    407 if num_failed_fits == num_fits:
    408     all_fits_failed_message = (
    409         f"\nAll the {num_fits} fits failed.\n"
    410         "It is very likely that your model is misconfigured.\n"
    411         "You can try to debug the error by setting error_score='raise'.\n\n"
    412         f"Below are more details about the failures:\n{fit_errors_summary}"
    413     )
--> 414     raise ValueError(all_fits_failed_message)
    416 else:
    417     some_fits_failed_message = (
    418         f"\n{num_failed_fits} fits failed out of a total of {num_fits}.\n"
    419         "The score on these train-test partitions for these parameters"
   (...)
    423         f"Below are more details about the failures:\n{fit_errors_summary}"
    424     )

ValueError: 
All the 5 fits failed.
It is very likely that your model is misconfigured.
You can try to debug the error by setting error_score='raise'.

Below are more details about the failures:
--------------------------------------------------------------------------------
5 fits failed with the following error:
Traceback (most recent call last):
  File "../python3.9/site-packages/sklearn/model_selection/_validation.py", line 729, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File "../python3.9/site-packages/summit/benchmarks/experimental_emulator.py", line 1051, in fit
    self.regressor_.fit(X, y_trans, **fit_params)
  File "../python3.9/site-packages/sklearn/base.py", line 1152, in wrapper
    return fit_method(estimator, *args, **kwargs)
  File "../python3.9/site-packages/sklearn/pipeline.py", line 427, in fit
    self._final_estimator.fit(Xt, y, **fit_params_last_step)
  File "../python3.9/site-packages/skorch/regressor.py", line 91, in fit
    return super(NeuralNetRegressor, self).fit(X, y, **fit_params)
  File "../python3.9/site-packages/skorch/net.py", line 1213, in fit
    self.initialize()
  File "../python3.9/site-packages/skorch/net.py", line 816, in initialize
    self._initialize_module()
  File "../python3.9/site-packages/skorch/net.py", line 715, in _initialize_module
    self.initialize_module()
  File "../python3.9/site-packages/skorch/net.py", line 567, in initialize_module
    module = self.initialized_instance(self.module, kwargs)
  File "../python3.9/site-packages/skorch/net.py", line 544, in initialized_instance
    return instance_or_cls(**kwargs)
TypeError: 'NoneType' object is not callable