Linear Model Class#

class LinearModel(name: str, task: str, auth_key: Optional[str] = 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: pandas.core.frame.DataFrame, y: pandas.core.series.Series, pretrained_bases: Optional[list] = None, overwrite: bool = False)#

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: pandas.core.frame.DataFrame, y: pandas.core.series.Series, learning_rate: Optional[float] = 0.01, l2: Optional[float] = 0.0, n_iterations: int = 1, scheduler_type: jai.types.linear.SchedulerType = SchedulerType.constant, scheduler_argument: Optional[float] = None, train_mode: jai.types.linear.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: pandas.core.frame.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.

set_parameters(learning_rate: Optional[float] = 0.01, l2: float = 0.0, scheduler_type: str = 'constant', scheduler_argument: Optional[float] = None, model_parameters: Optional[dict] = None)#
property url#

Get name and type of each database in your environment.