Linear Model Class#

class LinearModel(name: str, task: str, auth_key: str | None = None, environment: str = 'default', env_var: str = 'JAI_AUTH', verbose: int = 1, safe_mode: bool = False)#

Linear Model class.

An authorization key is needed to use the Jai API.

Parameters:
  • name (str) – String with the name of a database in your JAI environment.

  • task (str) – Task of the linear model. One of {regression, sgd_regression, classification, sgd_classification}.

  • environment (str) – Jai environment id or name to use. Defaults to “default”

  • env_var (str) – The environment variable that contains the JAI authentication token. Defaults to “JAI_AUTH”.

  • verbose (int) – The level of verbosity. Defaults to 1

  • safe_mode (bool) – When safe_mode is True, responses from Jai API are validated. If the validation fails, the current version you are using is probably incompatible with the current API version. We advise updating it to a newer version. If the problem persists and you are on the latest SDK version, please open an issue so we can work on a fix. Defaults to False.

property db_type#
describe()#

Get the database hyperparameters and parameters of a specific database.

Parameters:

name (str) – String with the name of a database in your JAI environment.

Returns:

response – Dictionary with database description.

Return type:

dict

fit(X: DataFrame, y: Series, pretrained_bases: list | None = None, overwrite: bool = False, frequency_seconds: int = 1)#

Train a new linear model.

Parameters:
  • X (pd.DataFrame)) – dataframe of features.

  • y (pd.Series):) – The target variable.

  • pretrained_bases (list) – mapping of ids to previously trained databases.

  • overwrite (bool) – If True, will overwrite the model if it already exists. Defaults to False.

Returns:

  • A dictionary with information about the training.

  • - id_train (List[Any])

  • - id_test (List[Any])

  • - metrics (Dict[str, Union[float, str]])

get_model_weights()#
is_valid()#

Check if a given name is a valid database name (i.e., if it is in your environment).

Returns:

response – True if name is in your environment. False, otherwise.

Return type:

bool

learn(X: DataFrame, y: Series, learning_rate: float | None = 0.01, l2: float | None = 0.0, n_iterations: int = 1, scheduler_type: SchedulerType = SchedulerType.constant, scheduler_argument: float | None = None, train_mode: TrainMode = TrainMode.always)#

Improves an existing model with informantion from a new data.

Parameters:
  • X (pd.DataFrame) – dataframe of features.

  • y (pd.Series) – The target variable.

Returns:

response – A dictionary with the learning report. - before: Dict[str, Union[float, str]] - after: Dict[str, Union[float, str]] - change: bool

Return type:

dict

property model_parameters#
property name#
predict(X: DataFrame, predict_proba: bool = False, as_frame: bool = True)#

Makes the prediction using the linear models.

Parameters:
  • X (pd.DataFrame) – Raw data to be predicted.

  • predict_proba (bool):) – If True, the model will return the probability of each class. Defaults to False.

  • as_frame (bool) – If True, the result will be returned as a pandas DataFrame. If False, it will be

  • True. (returned as a list of dictionaries. Defaults to) –

Return type:

A list of dictionaries.

report(verbose: int = 2, return_report: bool = False)#

Get a report about the training model.

Parameters:
  • verbose (int, optional) – Level of description. The default is 2. Use verbose 2 to get the loss graph, verbose 1 to get only the metrics result.

  • return_report (bool, optional) – Returns the report dictionary and does not print or plot anything. The default is False.

Returns:

Dictionary with the information.

Return type:

dict

Example

>>> from jai import Trainer
...
>>> trainer = Trainer(name)
>>> trainer.report()
set_parameters(learning_rate: float | None = 0.01, l2: float = 0.0, scheduler_type: str = 'constant', scheduler_argument: float | None = None, model_parameters: dict | None = None)#
status()#

Get the status of your JAI environment when training.

Returns:

response – A JSON file with the current status of the training tasks.

Return type:

dict

property url#

Get name and type of each database in your environment.

wait_setup(frequency_seconds: int = 1)#

Wait for the fit (model training) to finish

Parameters:

frequency_seconds (int, optional) – Number of seconds apart from each status check. Default is 5.

Return type:

None.