是的,AutoML Tables支持多标签分类。下面是一个使用AutoML Tables进行多标签分类的代码示例:
from google.cloud import automl
# 设置 Google Cloud 项目 ID
project_id = "your-project-id"
# 设置模型 ID
model_id = "your-model-id"
# 创建 AutoML Tables 客户端
client = automl.TablesClient(project=project_id, region="us-central1")
# 加载模型
model = client.get_model(model=model_id)
# 准备输入数据
input_data = [
{"feature_1": value_1, "feature_2": value_2, ...},
{"feature_1": value_3, "feature_2": value_4, ...},
...
]
# 进行预测
response = client.batch_predict(
model=model, input_config={"instances": input_data}
)
# 处理预测结果
for result in response.payload:
# 获取预测标签和对应的置信度
labels = result.tables.value.string_value
confidences = result.tables.score
# 打印预测结果
print(f"Labels: {labels}")
print(f"Confidences: {confidences}")
在上述代码中,你需要将your-project-id
替换为你的Google Cloud项目ID,将your-model-id
替换为你的AutoML Tables模型ID。然后,你需要准备输入数据,其中每个输入数据都包含特征值并以字典形式表示。最后,使用batch_predict
方法进行预测,并遍历预测结果以获取标签和置信度。