Model

class deepint.core.Model(organization_id: str, workspace_id: str, credentials: Credentials, info: ModelInfo, input_features: List[ModelFeature], output_features: ModelFeature)

A Deep Intelligence model.

Note: This class should not be instanced directly, and it’s recommended to use the deepint.core.model.Model.build or deepint.core.model.Model.from_url methods.

organization_id

organization where model is located.

workspace_id

workspace where model is located.

info

deepint.core.model.ModelInfo to operate with model’s information.

input_features

list of deepint.core.model.ModelFeature to operate with model’s input features.

output_features

list of deepint.core.model.ModelFeature to operate with model’s output features.

predictions

deepint.core.model.ModelPredictions to operate with model’s predictions.

credentials

credentials to authenticate with Deep Intelligence API and be allowed to perform operations over the model. If not provided, the credentials are generated with the deepint.auth.credentials.Credentials.build.

classmethod build(organization_id: str, workspace_id: str, model_id: str, credentials: Optional[Credentials] = None) Model

Builds a model.

Note: when model is created, the model’s information and features are retrieved from API.

Parameters:
  • organization_id – organization where model is located.

  • workspace_id – workspace where model is located.

  • model_id – model’s id.

  • credentials – credentials to authenticate with Deep Intelligence API and be allowed to perform operations over the model. If not provided, the credentials are generated with the deepint.auth.credentials.Credentials.build.

Returns:

the model build with the given parameters and credentials.

delete()

Deletes a model.

classmethod from_url(url: str, organization_id: Optional[str] = None, credentials: Optional[Credentials] = None) Model

Builds a model from it’s API or web associated URL.

The url must contain the workspace’s id and the model’s id as in the following examples:

Example

Note: when model is created, the model’s information and features are retrieved from API.

Also it is remmarkable that if the API URL is providen, the organization_id must be provided in the optional parameter, otherwise this ID won’t be found on the URL and the Organization will not be created, raising a value error.

Parameters:
  • url – the model’s API or web associated URL.

  • organization_id – the id of the organziation. Must be providen if the API URL is used.

  • credentials – credentials to authenticate with Deep Intelligence API and be allowed to perform operations over the model. If not provided, the credentials are generated with the deepint.auth.credentials.Credentials.build.

Returns:

the model build with the URL and credentials.

load()

Loads the model’s information.

If the model’s information is already loaded, is replace by the new one after retrieval.

to_dict() Dict[str, Any]

Builds a dictionary containing the information stored in current object.

Returns:

dictionary contining the information stored in the current object.

update(name: Optional[str] = None, description: Optional[str] = None)

Updates a model’s name and description.

Parameters:
  • name – model’s name. If not provided the model’s name stored in the deepint.core.model.Model.model_info attribute is taken.

  • descrpition – model’s description. If not provided the model’s description stored in the deepint.core.model.Model.model_info attribute is taken.

class deepint.core.ModelType(value)

Available model types in the system.

classmethod all() List[str]

Returns all available model types serialized to str.

Returns:

all available model types.

classmethod from_string(_str: str) ModelType

Builds the deepint.core.model.ModelType from a str.

Parameters:

_str – name of the model type.

Returns:

the model type converted to deepint.core.model.ModelType.

class deepint.core.ModelMethod(value)

Available model methods in the system.

classmethod all() List[str]

Returns all available model methods serialized to str.

Returns:

all available model methods.

classmethod allowed_methods_for_type(model_type: ModelType) List[ModelMethod]

Returns a list with the allowed model methods for a model type.

Parameters:

model_type – type of model to know about the allowed methods

Returns:

the model methods allowed for the given model type.

classmethod from_string(_str: str) ModelMethod

Builds the deepint.core.model.ModelMethod from a str.

Parameters:

_str – name of the model method.

Returns:

the model method converted to deepint.core.model.ModelMethod.

class deepint.core.model.ModelFeature(name: str, input_type: FeatureType, index: Optional[int] = None)

Stores the index, name, type and stats of a model feature associated with a deepint.net model.

index

Feature index, starting with 0.

name

Feature name (max 120 characters).

input_type

The type of the feature. Must be one of the values given in deepint.core.model.FeatureType.

static from_dict(obj: Any, index: Optional[int] = None) ModelFeature

Builds a ModelFeature with a dictionary.

Parameters:

objobject or dict containing the a serialized ModelFeature.

Returns:

ModelFeature containing the information stored in the given dictionary.

to_dict() Dict[str, Any]

Builds a dictionary containing the information stored in current object.

Returns:

dictionary containing the information stored in the current object.

class deepint.core.model.ModelInfo(model_id: str, name: str, description: str, model_type: ModelType, method: ModelMethod, created: datetime, last_modified: datetime, last_access: datetime, source_train: str, configuration: dict, size_bytes: int)

Stores the information of a Deep Intelligence model.

model_id

model’s id in format uuid4.

name

model’s name.

description

model’s description.

model_type

type of model (classifier or regressor).

method

method for prediction (bayes, logistic, forest, etc.).

created

creation date.

last_modified

last modified date.

last_access

last access date.

size_bytes

source size in bytes.

source_train

source used to train the model.

configuration

advanced model configuration

static from_dict(obj: Any) ModelInfo

Builds a ModelInfo with a dictionary.

Parameters:

objobject or dict containing the a serialized ModelInfo.

Returns:

ModelInfo containing the information stored in the given dictionary.

to_dict() Dict[str, Any]

Builds a dictionary containing the information stored in current object.

Returns:

dictionary containing the information stored in the current object.

class deepint.core.model.ModelPredictions(model: Model)

Operates over the prediction options of a concrete model.

Note: This class should not be instanced, and only be used within an deepint.core.model.Model

model

the model with which to operate with its predictions

evaluation() Dict[str, Any]

Retrieves a model’s evaluation.

Returns:

a dictionary contianing the model’s evaluation

predict(data: DataFrame) DataFrame

Uses a model to predict a single input.

Note: The maximum number of instances to evaluate at once is one. For the evaluation of more instances,

check the deepint.core.model.ModelPredictions.predict_batch

Parameters:

data – data to be used as prediction inputs. The column names must correspond to the model’s input feature names.

Returns:

a copy of the given input data with a new column with the prediction (output features) performed

predict_batch(data: DataFrame) DataFrame

Uses a model to predict multiple inputs.

The maximum number of instances to evaluate at once is 25.

Parameters:

data – data to be used as prediction inputs. The column names must correspond to the model’s input feature names.

Returns:

a copy of the given input data with a new column with the predictions (output features) performed

predict_unidimensional(data: DataFrame, variations: List[Any], variations_feature_name: str) DataFrame

Uses a model to perform an unidimensional predict. Keeping all the input variables with the same value and vary one of them.

Note: The maximum number of instances to evaluate at once is one (with a maximuym of 255 variations).

Note: All values must be providen in the data, including the variated feature (although the last one is not going to be used).

Parameters:
  • data – data to be used as prediction inputs. The column names must correspond to the model’s input feature names.

  • variations – list of variations to perform over a single feature.

  • variations_feature_name – name of the feature on which the variations are to be carried out

Returns:

a copy of the given input data replacing the variated feature with the list of variations, and a new column with the predictions (output features) performed