save_joblib

pyhelpers.store.save_joblib(data, path_to_file, verbose=False, raise_error=False, **kwargs)[source]

Saves data to a Joblib file.

Parameters:
  • data (Any) – The data to be serialized and saved using joblib.dump().

  • path_to_file (str | os.PathLike) – The file path where the Joblib file will be saved.

  • raise_error (bool) – Whether to raise the provided exception; if raise_error=False (default), the error will be suppressed.

  • verbose (bool | int) – Whether to print relevant information to the console; defaults to False.

  • kwargs – [Optional] Additional parameters for the joblib.dump() function.

Examples:

>>> from pyhelpers.store import save_joblib
>>> from pyhelpers.dirs import cd
>>> from pyhelpers._cache import example_dataframe
>>> joblib_pathname = cd("tests", "data", "dat.joblib")
>>> # Example 1:
>>> joblib_dat = example_dataframe().to_numpy()
>>> joblib_dat
array([[-0.1276474, 51.5073219],
       [-1.9026911, 52.4796992],
       [-2.2451148, 53.4794892],
       [-1.5437941, 53.7974185]])
>>> save_joblib(joblib_dat, joblib_pathname, verbose=True)
Saving "dat.joblib" to "./tests/data/" ... Done.
>>> # Example 2:
>>> import numpy as np
>>> from sklearn.linear_model import LinearRegression
>>> np.random.seed(0)
>>> x = example_dataframe().to_numpy()
>>> y = np.random.rand(*x.shape)
>>> reg = LinearRegression().fit(x, y)
>>> reg
LinearRegression()
>>> save_joblib(reg, joblib_pathname, verbose=True)
Updating "dat.joblib" in "./tests/data/" ... Done.

See also