google-cloud-platformgoogle-cloud-automlgoogle-ai-platform

Access feature importance from trained Vertex AI Tabular regression model using Python


I am working with models trained using the Tabular automl of Vertex in GCP. Training and batch predictions work fine. I am trying to use the feature importance in visualizations and trying to get to them from within python. I can get to the model evaluations with the code @Ricco D posted for me:


api_endpoint = 'us-central1-aiplatform.googleapis.com'
client_options = {"api_endpoint": api_endpoint} # api_endpoint is required for client_options
client_model = aiplatform.services.model_service.ModelServiceClient(client_options=client_options)
project_id = 't...1'
location = 'us-central1'
model_id = '6...2'

model_name = f'projects/{project_id}/locations/{location}/models/{model_id}'
list_eval_request = aiplatform.types.ListModelEvaluationsRequest(parent=model_name)
list_eval = client_model.list_model_evaluations(request=list_eval_request)
for val in list_eval:
    print(val.model_explanation)

But I can not figure out how to get the trained model's feature importance's that were generated in the training pipeline. I can see them on the model page but can't access them from python: Evaluation page

The code returned ListModelEvaluationsPager object is this:

  name: "projects/7...3/locations/us-central1/models/6...2/evaluations/5...0"
  metrics_schema_uri: "gs://google-cloud-aiplatform/schema/modelevaluation/regression_metrics_1.0.0.yaml"
  metrics {
    struct_value {
      fields {
        key: "meanAbsoluteError"
        value {
          number_value: 27.391115
        }
      }
      fields {
        key: "meanAbsolutePercentageError"
        value {
          number_value: 25.082605
        }
      }
      fields {
        key: "rSquared"
        value {
          number_value: 0.88434035
        }
      }
      fields {
        key: "rootMeanSquaredError"
        value {
          number_value: 47.997845
        }
      }
      fields {
        key: "rootMeanSquaredLogError"
        value {
          number_value: nan
        }
      }
    }
  }
  create_time {
    seconds: 1630550819
    nanos: 842478000
  }
}
>```

This object does not have a model_explanation member and the code returns an error

Solution

  • A working solution with code was posted to answer this by Ricco D here Correct answer by Ricco D