Model¶
-
class
previsionio.model.
Model
(_id, uc_id, uc_version, name=None, **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: -
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
-
deploy
() → previsionio.deployed_model.DeployedModel¶ (Not Implemented yet) Deploy the model as a REST API app.
Keyword Arguments: {enum} -- it can be 'model', 'notebook', 'shiny', 'dash' or 'node' application (app_type) – Returns: Path of the deployed application Return type: str
-
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
-
hyperparameters
¶ Return the hyperparameters of a model.
Returns: Hyperparameters of the model Return type: dict
-
predict
(df, confidence=False) → 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, confidence=False, dataset_folder=None) → 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_name
(dataset_name, confidence=False) → pandas.core.frame.DataFrame¶ Make a prediction for a dataset stored in the current active [client] workspace (referenced by name).
Parameters: Returns: Prediction results dataframe
Return type: pd.DataFrame
-
predict_single
(confidence=False, explain=False, **predict_data)¶ 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, uc_id, name=None, **other_params)¶ Bases:
previsionio.model.Model
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=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
-
optimal_threshold
¶ Get the value of threshold probability that optimizes the F1 Score.
Returns: Optimal value of the threshold (if it not a classification problem it returns None
)Return type: float Raises: PrevisionException
– Any error while fetching data from the platform or parsing the result
-
predict_proba
(df, confidence=False)¶ Make a prediction in a Scikit-learn blocking style and return probabilities.
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: (Formatted) prediction results dataframe
Return type: pd.DataFrame
- df (
-
-
class
previsionio.model.
MultiClassificationModel
(_id, uc_id, uc_version, name=None, **other_params)¶ Bases:
previsionio.model.Model
A model object for a multi-classification usecase, i.e. a usecase where the target is categorical with strictly more than 2 modalities.
Parameters: -
predict
(df, confidence=False)¶ 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: (Formatted) prediction results dataframe
Return type: pd.DataFrame
- df (
-
predict_proba
(df, confidence=False)¶ Make a prediction in a Scikit-learn blocking style and return probabilities.
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: (Formatted) prediction results dataframe
Return type: pd.DataFrame
- df (
-
-
class
previsionio.model.
RegressionModel
(_id, uc_id, uc_version, name=None, **other_params)¶ Bases:
previsionio.model.Model
A model object for a regression usecase, i.e. a usecase where the target is numerical.
Parameters: -
predict
(df, confidence=False)¶ 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 (
-