【问题标题】:How can I access to text data (value) of feature importance from a traiend model on Vertex AI with Python如何使用 Python 从 Vertex AI 上的训练模型访问特征重要性的文本数据(值)
【发布时间】:2021-11-28 05:46:27
【问题描述】:

我正在 Vertex AI 上使用 AutoML 进行预测建模,并获得了经过训练的模型。我在 Vertex AI 的模型选项卡中以图形方式检查了它的特征重要性,然后我想用下面的代码获得其特征重要性的文本数据,但只能看到它,无法将每个项目作为值。

------------ Python代码

from google.cloud import aiplatform_v1 as aiplatform2
api_endpoint = 'us-central1-aiplatform.googleapis.com'
client_options = {"api_endpoint": api_endpoint} # api_endpoint is required for client_options
client_model = aiplatform2.services.model_service.ModelServiceClient(client_options=client_options)
project_id = 'this is my project id'
location = 'us-central1'
model_id = 'my trained id'
model_name = f'projects/{project_id}/locations/{location}/models/{model_id}'

list_eval_request = aiplatform2.types.ListModelEvaluationsRequest(parent=model_name)
list_eval = client_model.list_model_evaluations(request=list_eval_request)
list_eval.model_evaluations

------------------------ 在 Notebook 上直观地获取此内容

[name: "projects/*********/locations/us-central1/models/*********/evaluations/*********"
metrics_schema_uri: "gs://google-cloud-aiplatform/schema/modelevaluation/regression_metrics_1.0.0.yaml"
metrics {
  struct_value {
    fields {
      key: "meanAbsoluteError"
      value {
        number_value: 2863.7043
      }
    }
    fields {
      key: "meanAbsolutePercentageError"
      value {
        number_value: 197.63817
      }

------------问题

如何访问“键”及其“值”。 示例键:“meanAbsoluteError”/值:number_value:2863.7043

【问题讨论】:

    标签: google-ai-platform google-cloud-vertex-ai


    【解决方案1】:

    我是这样理解的

    for a in list_eval.model_evaluations[0].metrics:
        b = str(list_eval.model_evaluations[0].metrics[a])
        v_str = a + ' : ' + b
        print(v_str)
    
    rootMeanSquaredLogError : 1.2712421
    rootMeanSquaredError : 26191.564
    rSquared : 0.31798086
    meanAbsoluteError : 5698.832
    meanAbsolutePercentageError : 262.9534
    

    “metrics”只是一个字典

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 2021-11-11
      • 2020-07-30
      • 2020-12-29
      • 2021-09-21
      • 2022-06-22
      • 2016-03-02
      • 2020-09-22
      • 2019-10-05
      相关资源
      最近更新 更多