Model¶
-
class
previsionio.model.
Model
(_id: str, usecase_version_id: str, project_id: str, model_name: str = None, deployable: bool = False, **other_params)¶ Bases:
previsionio.api_resource.ApiResource
A Model object is generated by Prevision AutoML plateform when you launch a use case. All models generated by Prevision.io are deployable in our Store
With this Model class, you can select the model with the optimal hyperparameters that responds to your buisiness requirements, then you can deploy it as a real-time/batch endpoint that can be used for a web Service.
Parameters: -
classmethod
from_id
(_id: str) → Union[previsionio.model.RegressionModel, previsionio.model.ClassificationModel, previsionio.model.MultiClassificationModel, previsionio.model.TextSimilarityModel]¶ Get a usecase from the platform by its unique id.
Parameters: Returns: Fetched usecase
Return type: Raises: PrevisionException
– Any error while fetching data from the platform or parsing result
-
hyperparameters
¶ Return the hyperparameters of a model.
Returns: Hyperparameters of the model Return type: dict
-
predict
(df: pandas.core.frame.DataFrame, confidence: bool = False, prediction_dataset_name: str = None) → pandas.core.frame.DataFrame¶ Make a prediction in a Scikit-learn blocking style.
Warning
For large dataframes and complex (blend) models, this can be slow (up to 1-2 hours). Prefer using this for simple models and small dataframes or use option
use_best_single = True
.Parameters: - df (
pd.DataFrame
) – Apandas
dataframe containing the testing data - confidence (bool, optional) – Whether to predict with confidence estimator (default:
False
)
Returns: Prediction results dataframe
Return type: pd.DataFrame
- df (
-
predict_from_dataset
(dataset: previsionio.dataset.Dataset, confidence: bool = False, dataset_folder: previsionio.dataset.Dataset = None) → previsionio.prediction.ValidationPrediction¶ Make a prediction for a dataset stored in the current active [client] workspace (using the current SDK dataset object).
Parameters: Returns: Prediction object
Return type: pd.DataFrame
-
classmethod
-
class
previsionio.model.
ClassicModel
(_id: str, usecase_version_id: str, project_id: str, model_name: str = None, deployable: bool = False, **other_params)¶ Bases:
previsionio.model.Model
-
chart
()¶ Return chart analysis information for a model.
Returns: Chart analysis results Return type: dict Raises: PrevisionException
– Any error while fetching data from the platform or parsing the result
-
cross_validation
¶ Get model’s cross validation dataframe.
Returns: Cross-validation dataframe Return type: pd.Dataframe
-
feature_importance
¶ Return a dataframe of feature importances for the given model features, with their corresponding scores (sorted by descending feature importance scores).
Returns: Dataframe of feature importances Return type: pd.DataFrame
Raises: PrevisionException
– Any error while fetching data from the platform or parsing the result
-
predict_single
(data: Dict, confidence: bool = False, explain: bool = False)¶ Make a prediction for a single instance. Use
predict_from_dataset_name()
or predict methods to predict multiple instances at the same time (it’s faster).Parameters: Note
You can set both
confidence
andexplain
to true.Returns: Dictionary containing the prediction result Note
The prediction format depends on the problem type (regression, classification, etc…)
Return type: dict
-
-
class
previsionio.model.
ClassificationModel
(_id, usecase_version_id, **other_params)¶ Bases:
previsionio.model.ClassicModel
A model object for a (binary) classification usecase, i.e. a usecase where the target is categorical with exactly 2 modalities.
Parameters: -
get_dynamic_performances
(threshold: float = 0.5)¶ Get model performance for the given threshold.
Parameters: threshold (float, optional) – Threshold to check the model’s performance for (default: 0.5) Returns: Model classification performance dict with the following keys: confusion_matrix
accuracy
precision
recall
f1_score
Return type: dict Raises: PrevisionException
– Any error while fetching data from the platform or parsing the result
-
-
class
previsionio.model.
MultiClassificationModel
(_id: str, usecase_version_id: str, project_id: str, model_name: str = None, deployable: bool = False, **other_params)¶ Bases:
previsionio.model.ClassicModel
A model object for a multi-classification usecase, i.e. a usecase where the target is categorical with strictly more than 2 modalities.
Parameters:
-
class
previsionio.model.
RegressionModel
(_id: str, usecase_version_id: str, project_id: str, model_name: str = None, deployable: bool = False, **other_params)¶ Bases:
previsionio.model.ClassicModel
A model object for a regression usecase, i.e. a usecase where the target is numerical.
Parameters:
-
class
previsionio.model.
TextSimilarityModel
(_id: str, usecase_version_id: str, project_id: str, model_name: str = None, deployable: bool = False, **other_params)¶ Bases:
previsionio.model.Model
-
predict
(df: pandas.core.frame.DataFrame, queries_dataset_content_column: str, top_k: int = 10, queries_dataset_matching_id_description_column: str = None, prediction_dataset_name: str = None) → Optional[pandas.core.frame.DataFrame]¶ Make a prediction for a dataset stored in the current active [client] workspace (using the current SDK dataset object).
Parameters: Returns: Prediction results dataframe
Return type: pd.DataFrame
-
predict_from_dataset
(queries_dataset: previsionio.dataset.Dataset, queries_dataset_content_column: str, top_k: int = 10, queries_dataset_matching_id_description_column: str = None) → previsionio.prediction.ValidationPrediction¶ Make a prediction for a dataset stored in the current active [client] workspace (using the current SDK dataset object).
Parameters: Returns: Prediction object
Return type: pd.DataFrame
-