SelfExplainML / PiML-Toolbox

PiML (Python Interpretable Machine Learning) toolbox for model development & diagnostics
https://selfexplainml.github.io/PiML-Toolbox
Apache License 2.0
912 stars 109 forks source link

Getting the error: AttributeError: function 'GetOutputTypeStr' not found #56

Open sauvikd opened 1 month ago

sauvikd commented 1 month ago

I have two simple codes to test the PIML:

CODE 1:

from piml import Experiment
from piml.models import GAMINetRegressor

"""## Load and Prepare Data"""
exp = Experiment()
exp.data_loader(data="BikeSharing")
exp.data_summary(feature_exclude=["yr", "mnth", "temp"])        # , silent=True
exp.data_prepare(target="cnt", task_type="regression")

# In[]
exp.model_train(model=GAMINetRegressor())

CODE 2:

# LOAD DATA AND BASIC PREVIEW
# ---------------------------------------------------------------------------------------------
df = pd.read_csv(r"H:\WORK\ML Project (EBM)\Dataset\CO2_MMP.csv")
print("First few rows of the data:")
print(df.head())

# In[]
input_features = ['T', 'C1', 'C2-C6', 'Vol', 'Int', 'C7+', 'MWC5+']
output = ['MMP']
X_train, X_test, y_train, y_test = train_test_split(df[input_features], df[output], test_size = 0.2, random_state = 42)

# In[]
gaminet_param_grid = {    }
gaminet_kf = KFold(n_splits=10, shuffle=True, random_state = 42)
gaminet_model = GAMINetRegressor(random_state = 42)   # GAMINet: generalized additive model with structured pairwise interactions network

# HP Tuning(Grid, kfold, model)
grid_search = GridSearchCV(gaminet_model, gaminet_param_grid, cv=gaminet_kf, scoring='neg_mean_squared_error', n_jobs=-1, error_score='raise')
grid_search.fit(X_train, y_train)

# Best parameters and model
best_gaminet_params = grid_search.best_params_                # Optimal parameters
best_gaminet_model = grid_search.best_estimator_               # Best GAMINet Model

In both the codes I'm getting the same error as below. AttributeError: function 'GetOutputTypeStr' not found

I couldnt figure out the reason behind it. I have also pasted the full error message from both codes. Can you provide a solution?

{
    "name": "AttributeError",
    "message": "function 'GetOutputTypeStr' not found",
    "stack": "---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File h:\\WORK\\ML Project (EBM)\\PIML_example_bikesharing.py:2
      1 # In[]
----> 2 exp.model_train(model=GAMINetRegressor())
      3 # exp.model_train()

File piml\\api.py:735, in piml.api.Experiment.model_train()

File piml\\api.py:2128, in piml.api.Experiment._model_train_api()

File piml\\workflow\\model_train_api.py:271, in piml.workflow.model_train_api.ModelAPI.singlerun()

File piml\\workflow\\pipeline.py:58, in piml.workflow.pipeline.ModelPipeline.fit()

File piml\\models\\gaminet\\api.py:453, in piml.models.gaminet.api.GAMINetRegressor.fit()

File piml\\models\\gaminet\\base.py:1277, in piml.models.gaminet.base.GAMINet._fit()

File piml\\models\\gaminet\\base.py:951, in piml.models.gaminet.base.GAMINet._add_interaction()

File piml\\models\\gaminet\\base.py:937, in piml.models.gaminet.base.GAMINet._get_interaction_list()

File piml\\models\\gaminet\\base.py:763, in piml.models.gaminet.base.GAMINet._interaction_screening()

File piml\\models\\ebm\\utils\\_measure_interactions.py:90, in piml.models.ebm.utils._measure_interactions.measure_interactions()

File piml\\models\\ebm\\utils\\_native.py:49, in piml.models.ebm.utils._native.Native.get_native_singleton()

File piml\\models\\ebm\\utils\\_native.py:1034, in piml.models.ebm.utils._native.Native._initialize()

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\ctypes\\__init__.py:387, in CDLL.__getattr__(self, name)
    385 if name.startswith('__') and name.endswith('__'):
    386     raise AttributeError(name)
--> 387 func = self.__getitem__(name)
    388 setattr(self, name, func)
    389 return func

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\ctypes\\__init__.py:392, in CDLL.__getitem__(self, name_or_ordinal)
    391 def __getitem__(self, name_or_ordinal):
--> 392     func = self._FuncPtr((name_or_ordinal, self))
    393     if not isinstance(name_or_ordinal, int):
    394         func.__name__ = name_or_ordinal

AttributeError: function 'GetOutputTypeStr' not found"
}
{
    "name": "AttributeError",
    "message": "function 'GetOutputTypeStr' not found",
    "stack": "---------------------------------------------------------------------------
_RemoteTraceback                          Traceback (most recent call last)
_RemoteTraceback: 
\"\"\"
Traceback (most recent call last):
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\externals\\loky\\process_executor.py\", line 463, in _process_worker
    r = call_item()
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\externals\\loky\\process_executor.py\", line 291, in __call__
    return self.fn(*self.args, **self.kwargs)
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py\", line 598, in __call__
    return [func(*args, **kwargs)
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py\", line 598, in <listcomp>
    return [func(*args, **kwargs)
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\sklearn\\utils\\parallel.py\", line 127, in __call__
    return self.function(*args, **kwargs)
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\sklearn\\model_selection\\_validation.py\", line 729, in _fit_and_score
    estimator.fit(X_train, y_train, **fit_params)
  File \"piml\\models\\gaminet\\api.py\", line 453, in piml.models.gaminet.api.GAMINetRegressor.fit
  File \"piml\\models\\gaminet\\base.py\", line 1277, in piml.models.gaminet.base.GAMINet._fit
  File \"piml\\models\\gaminet\\base.py\", line 951, in piml.models.gaminet.base.GAMINet._add_interaction
  File \"piml\\models\\gaminet\\base.py\", line 937, in piml.models.gaminet.base.GAMINet._get_interaction_list
  File \"piml\\models\\gaminet\\base.py\", line 763, in piml.models.gaminet.base.GAMINet._interaction_screening
  File \"piml\\models\\ebm\\utils\\_measure_interactions.py\", line 90, in piml.models.ebm.utils._measure_interactions.measure_interactions
  File \"piml\\models\\ebm\\utils\\_native.py\", line 49, in piml.models.ebm.utils._native.Native.get_native_singleton
  File \"piml\\models\\ebm\\utils\\_native.py\", line 1034, in piml.models.ebm.utils._native.Native._initialize
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\ctypes\\__init__.py\", line 387, in __getattr__
    func = self.__getitem__(name)
  File \"c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\ctypes\\__init__.py\", line 392, in __getitem__
    func = self._FuncPtr((name_or_ordinal, self))
AttributeError: function 'GetOutputTypeStr' not found
\"\"\"

The above exception was the direct cause of the following exception:

AttributeError                            Traceback (most recent call last)
File h:\\WORK\\ML Project (EBM)\\PIML_CO2_MMP.py:22
     20 # HP Tuning(Grid, kfold, model)
     21 grid_search = GridSearchCV(gaminet_model, gaminet_param_grid, cv=gaminet_kf, scoring='neg_mean_squared_error', n_jobs=-1, error_score='raise')
---> 22 grid_search.fit(X_train, y_train)
     24 # Best parameters and model
     25 best_gaminet_params = grid_search.best_params_                # Optimal parameters

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\sklearn\\base.py:1152, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs)
   1145     estimator._validate_params()
   1147 with config_context(
   1148     skip_parameter_validation=(
   1149         prefer_skip_nested_validation or global_skip_validation
   1150     )
   1151 ):
-> 1152     return fit_method(estimator, *args, **kwargs)

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\sklearn\\model_selection\\_search.py:898, in BaseSearchCV.fit(self, X, y, groups, **fit_params)
    892     results = self._format_results(
    893         all_candidate_params, n_splits, all_out, all_more_results
    894     )
    896     return results
--> 898 self._run_search(evaluate_candidates)
    900 # multimetric is determined here because in the case of a callable
    901 # self.scoring the return type is only known after calling
    902 first_test_score = all_out[0][\"test_scores\"]

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\sklearn\\model_selection\\_search.py:1422, in GridSearchCV._run_search(self, evaluate_candidates)
   1420 def _run_search(self, evaluate_candidates):
   1421     \"\"\"Search all candidates in param_grid\"\"\"
-> 1422     evaluate_candidates(ParameterGrid(self.param_grid))

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\sklearn\\model_selection\\_search.py:845, in BaseSearchCV.fit.<locals>.evaluate_candidates(candidate_params, cv, more_results)
    837 if self.verbose > 0:
    838     print(
    839         \"Fitting {0} folds for each of {1} candidates,\"
    840         \" totalling {2} fits\".format(
    841             n_splits, n_candidates, n_candidates * n_splits
    842         )
    843     )
--> 845 out = parallel(
    846     delayed(_fit_and_score)(
    847         clone(base_estimator),
    848         X,
    849         y,
    850         train=train,
    851         test=test,
    852         parameters=parameters,
    853         split_progress=(split_idx, n_splits),
    854         candidate_progress=(cand_idx, n_candidates),
    855         **fit_and_score_kwargs,
    856     )
    857     for (cand_idx, parameters), (split_idx, (train, test)) in product(
    858         enumerate(candidate_params), enumerate(cv.split(X, y, groups))
    859     )
    860 )
    862 if len(out) < 1:
    863     raise ValueError(
    864         \"No fits were performed. \"
    865         \"Was the CV iterator empty? \"
    866         \"Were there no candidates?\"
    867     )

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\sklearn\\utils\\parallel.py:65, in Parallel.__call__(self, iterable)
     60 config = get_config()
     61 iterable_with_config = (
     62     (_with_config(delayed_func, config), args, kwargs)
     63     for delayed_func, args, kwargs in iterable
     64 )
---> 65 return super().__call__(iterable_with_config)

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py:2007, in Parallel.__call__(self, iterable)
   2001 # The first item from the output is blank, but it makes the interpreter
   2002 # progress until it enters the Try/Except block of the generator and
   2003 # reach the first `yield` statement. This starts the aynchronous
   2004 # dispatch of the tasks to the workers.
   2005 next(output)
-> 2007 return output if self.return_generator else list(output)

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py:1650, in Parallel._get_outputs(self, iterator, pre_dispatch)
   1647     yield
   1649     with self._backend.retrieval_context():
-> 1650         yield from self._retrieve()
   1652 except GeneratorExit:
   1653     # The generator has been garbage collected before being fully
   1654     # consumed. This aborts the remaining tasks if possible and warn
   1655     # the user if necessary.
   1656     self._exception = True

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py:1754, in Parallel._retrieve(self)
   1747 while self._wait_retrieval():
   1748 
   1749     # If the callback thread of a worker has signaled that its task
   1750     # triggered an exception, or if the retrieval loop has raised an
   1751     # exception (e.g. `GeneratorExit`), exit the loop and surface the
   1752     # worker traceback.
   1753     if self._aborting:
-> 1754         self._raise_error_fast()
   1755         break
   1757     # If the next job is not ready for retrieval yet, we just wait for
   1758     # async callbacks to progress.

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py:1789, in Parallel._raise_error_fast(self)
   1785 # If this error job exists, immediatly raise the error by
   1786 # calling get_result. This job might not exists if abort has been
   1787 # called directly or if the generator is gc'ed.
   1788 if error_job is not None:
-> 1789     error_job.get_result(self.timeout)

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py:745, in BatchCompletionCallBack.get_result(self, timeout)
    739 backend = self.parallel._backend
    741 if backend.supports_retrieve_callback:
    742     # We assume that the result has already been retrieved by the
    743     # callback thread, and is stored internally. It's just waiting to
    744     # be returned.
--> 745     return self._return_or_raise()
    747 # For other backends, the main thread needs to run the retrieval step.
    748 try:

File c:\\Users\\sauvikdas\\.conda\\envs\\__DSX_310__\\lib\\site-packages\\joblib\\parallel.py:763, in BatchCompletionCallBack._return_or_raise(self)
    761 try:
    762     if self.status == TASK_ERROR:
--> 763         raise self._result
    764     return self._result
    765 finally:

AttributeError: function 'GetOutputTypeStr' not found"
}
ZebinYang commented 4 weeks ago

This error says that the compiled EBM FAST screening library cannot be loaded properly, which means that your current computing environment is not supported.