모델 평가를 표시하는 방법을 보여줍니다.
코드 샘플
Python
AutoML Tables에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.
# 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
break
# Get a model evaluation.
model_evaluation = client.get_model_evaluation(
model_evaluation_name=model_evaluation_name
)
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:
print(
"Model Precision: {}%".format(
round(confidence_metrics_entry.precision * 100, 2)
)
)
print(
"Model Recall: {}%".format(
round(confidence_metrics_entry.recall * 100, 2)
)
)
print(
"Model F1 score: {}%".format(
round(confidence_metrics_entry.f1_score * 100, 2)
)
)
print(f"Model AUPRC: {classification_metrics.au_prc}")
print(f"Model AUROC: {classification_metrics.au_roc}")
print(f"Model log loss: {classification_metrics.log_loss}")
regression_metrics = model_evaluation.regression_evaluation_metrics
if str(regression_metrics):
print("Model regression metrics:")
print(f"Model RMSE: {regression_metrics.root_mean_squared_error}")
print(f"Model MAE: {regression_metrics.mean_absolute_error}")
print(
"Model MAPE: {}".format(regression_metrics.mean_absolute_percentage_error)
)
print(f"Model R^2: {regression_metrics.r_squared}")
다음 단계
다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.