mljar-supervised: Problems loading models

OK. I have trained models and I have them sitting in this directory.

C:\Users\User\GBAW23

When I try to run this code.

automl = AutoML(results_path=r"C:\Users\User\GBAW23")

I get this error

What am I doing wrong?

2023-05-19 20:24:33,807 supervised.exceptions ERROR Cannot load AutoML directory. Expecting value: line 1 column 1 (char 0)


JSONDecodeError Traceback (most recent call last) File ~\anaconda3\lib\site-packages\supervised\base_automl.py:211, in BaseAutoML.load(self, path) 210 else: –> 211 m = ModelFramework.load(path, model_subpath, lazy_load) 212 self._models += [m]

File ~\anaconda3\lib\site-packages\supervised\model_framework.py:570, in ModelFramework.load(results_path, model_subpath, lazy_load) 568 logger.info(f"Loading model framework from {model_path}") –> 570 json_desc = json.load(open(os.path.join(model_path, “framework.json”))) 571 mf = ModelFramework(json_desc[“params”])

File ~\anaconda3\lib\json_init_.py:293, in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 276 “”“Deserialize fp (a .read()-supporting file-like object containing 277 a JSON document) to a Python object. 278 (…) 291 kwarg; otherwise JSONDecoder is used. 292 “”” –> 293 return loads(fp.read(), 294 cls=cls, object_hook=object_hook, 295 parse_float=parse_float, parse_int=parse_int, 296 parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)

File ~\anaconda3\lib\json_init_.py:346, in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 343 if (cls is None and object_hook is None and 344 parse_int is None and parse_float is None and 345 parse_constant is None and object_pairs_hook is None and not kw): –> 346 return _default_decoder.decode(s) 347 if cls is None:

File ~\anaconda3\lib\json\decoder.py:337, in JSONDecoder.decode(self, s, _w) 333 “”“Return the Python representation of s (a str instance 334 containing a JSON document). 335 336 “”” –> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end()

File ~\anaconda3\lib\json\decoder.py:355, in JSONDecoder.raw_decode(self, s, idx) 354 except StopIteration as err: –> 355 raise JSONDecodeError(“Expecting value”, s, err.value) from None 356 return obj, end

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

AutoMLException Traceback (most recent call last) Cell In[13], line 2 1 automl = AutoML(results_path=r"C:\Users\User\GBAW23") ----> 2 automl.predict(X)

File ~\anaconda3\lib\site-packages\supervised\automl.py:387, in AutoML.predict(self, X) 370 def predict(self, X: Union[List, numpy.ndarray, pandas.DataFrame]) -> numpy.ndarray: 371 “”" 372 Computes predictions from AutoML best model. 373 (…) 385 AutoMLException: Model has not yet been fitted. 386 “”" –> 387 return self._predict(X)

File ~\anaconda3\lib\site-packages\supervised\base_automl.py:1369, in BaseAutoML._predict(self, X) 1367 def _predict(self, X): -> 1369 predictions = self._base_predict(X) 1370 # Return predictions 1371 # If classification task the result is in column ‘label’ 1372 # If regression task the result is in column ‘prediction’ 1373 return ( 1374 predictions[“label”].to_numpy() 1375 if self._ml_task != REGRESSION 1376 else predictions[“prediction”].to_numpy() 1377 )

File ~\anaconda3\lib\site-packages\supervised\base_automl.py:1301, in BaseAutoML._base_predict(self, X, model) 1299 if model is None: 1300 if self._best_model is None: -> 1301 self.load(self.results_path) 1302 model = self._best_model 1304 if model is None:

File ~\anaconda3\lib\site-packages\supervised\base_automl.py:234, in BaseAutoML.load(self, path) 231 self.n_classes = self._data_info[“n_classes”] 233 except Exception as e: –> 234 raise AutoMLException(f"Cannot load AutoML directory. {str(e)}")

AutoMLException: Cannot load AutoML directory. Expecting value: line 1 column 1 (char 0)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 29 (10 by maintainers)

Most upvoted comments

Good news! cracked it. When I was doing feature selection before sending the data to MLJAR I converted my category fields into categories using Pandas. If I just leave them as Ints everything works fine!

The accuracy of the models seems unimpaired.,

Woohoo! So there must be the issue with converting categoricals to numeric

found it. Testing now.

So the problem is in the XGBOOST model. Applies also to derivatives of XGBOOST model. Workaround. find the model(s) in the errors section . Delete any of those from params.json and ensemble.JSON. It then runs, obvs accuracy may drop 😃 . Quick fix would be to preclude any models that get into the errors file from being used in the ensemble/stack models. Stack models is worse hit as it uses more models so is more likely to use a damaged one, NB some XGBOOST models are fine so its an intermittent little beast.