Exibir uma avaliação de modelo

Mostra como exibir uma avaliação do modelo.

Exemplo de código


# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_display_name = 'MODEL_DISPLAY_NAME_HERE'
# filter = 'filter expression here'

from google.cloud import automl_v1beta1 as automl

client = automl.TablesClient(project=project_id, region=compute_region)

# List all the model evaluations in the model by applying filter.
response = client.list_model_evaluations(
    model_display_name=model_display_name, filter=filter

# Iterate through the results.
for evaluation in response:
    # There is evaluation for each class in a model and for overall model.
    # Get only the evaluation of overall model.
    if not evaluation.annotation_spec_id:
        model_evaluation_name = evaluation.name

# Get a model evaluation.
model_evaluation = client.get_model_evaluation(

classification_metrics = model_evaluation.classification_evaluation_metrics
if str(classification_metrics):
    confidence_metrics = classification_metrics.confidence_metrics_entry

    # Showing model score based on threshold of 0.5
    print("Model classification metrics (threshold at 0.5):")
    for confidence_metrics_entry in confidence_metrics:
        if confidence_metrics_entry.confidence_threshold == 0.5:
                "Model Precision: {}%".format(
                    round(confidence_metrics_entry.precision * 100, 2)
                "Model Recall: {}%".format(
                    round(confidence_metrics_entry.recall * 100, 2)
                "Model F1 score: {}%".format(
                    round(confidence_metrics_entry.f1_score * 100, 2)
    print("Model AUPRC: {}".format(classification_metrics.au_prc))
    print("Model AUROC: {}".format(classification_metrics.au_roc))
    print("Model log loss: {}".format(classification_metrics.log_loss))

regression_metrics = model_evaluation.regression_evaluation_metrics
if str(regression_metrics):
    print("Model regression metrics:")
        "Model RMSE: {}".format(regression_metrics.root_mean_squared_error)
    print("Model MAE: {}".format(regression_metrics.mean_absolute_error))
        "Model MAPE: {}".format(
    print("Model R^2: {}".format(regression_metrics.r_squared))

A seguir

Para pesquisar e filtrar amostras de código para outros produtos do Google Cloud, consulte o Navegador de amostra do Google Cloud