You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Python获取已训练Vertex AI表格回归模型的特征重要性

解决方法

你当前调用list_model_evaluations返回的结果中没有特征重要性字段,是因为Vertex Tabular AutoML内置生成的特征重要性数据存储在训练流水线资源中,而非模型评估对象下,你可以通过以下步骤获取:

  • 首先通过模型资源查询关联的训练流水线ID
  • 调用训练流水线服务接口拉取流水线产出的特征重要性数据

完整可运行代码如下:

from google.cloud import aiplatform

# 基础参数配置
project_id = '你的项目ID'
location = 'us-central1'
model_id = '你的模型ID'

# 初始化Vertex SDK
aiplatform.init(project=project_id, location=location)

# 加载模型对象
model = aiplatform.Model(model_name=f"projects/{project_id}/locations/{location}/models/{model_id}")

# 获取关联的训练流水线资源名
training_pipeline_name = model.to_dict()['trainingPipeline']

# 加载训练流水线对象
training_pipeline = aiplatform.TrainingPipeline(training_pipeline_name=training_pipeline_name)

# 提取特征重要性数据,返回格式为 {特征名: 重要性分值}
feature_importance = training_pipeline.to_dict()['jobDetail']['tabularTrainingJobDetail']['structuredTrainingJob']['modelInfo']['featureImportances']

print(feature_importance)

如果需要直接做可视化,可参考以下代码转换为图表:

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# 转换为DataFrame并按重要性排序
fi_df = pd.DataFrame.from_dict(feature_importance, orient='index', columns=['importance']).sort_values('importance', ascending=True)

# 绘制水平柱状图
plt.figure(figsize=(10, 6))
sns.barplot(x=fi_df['importance'], y=fi_df.index, palette='viridis')
plt.title('Tabular AutoML 模型特征重要性')
plt.xlabel('重要性分值')
plt.ylabel('特征名')
plt.show()

内容的提问来源于stack exchange,提问作者Zotara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 03:15:03