machine-learning - 从 BigQuery ML 中的训练数据中排除列

标签 machine-learning google-bigquery

我正在使用 BigQuery ML 训练模型,我的输入有多个字段,其中一个是客户编号,该编号作为预测功能没有用处,但我在最终输出中确实需要它,以便我可以引用哪些用户得分高,哪些用户得分低。如何从模型训练中排除此列而不完全删除它?

阅读文档,我发现排除列的唯一方法是将其添加到 input_label_cols显然不是,或者 data_split_col这是不可取的。

最佳答案

您不需要包含到不需要成为模型一部分的模型字段中 - 根本不需要。
相反,您需要在预测期间包含它们

例如,在下面的模型中,您只有 6 个字段作为输入(载体、出发地、目的地、dep_delay、taxi_out、距离)

#standardsql
CREATE OR REPLACE MODEL flights.ontime
OPTIONS
  (model_type='logistic_reg', input_label_cols=['on_time']) AS
SELECT
  IF(arr_delay < 15, 1, 0) AS on_time,
  carrier,
  origin,
  dest,
  dep_delay,
  taxi_out,
  distance
FROM `cloud-training-demos.flights.tzcorr`
WHERE arr_delay IS NOT NULL   

在预测时,您可以使用所有额外字段,如下所示(您可以将它们放在 SELECT 的任何位置 - 但请注意 - 预测列将首先出现:

#standardsql
SELECT * FROM ml.PREDICT(MODEL `cloud-training-demos.flights.ontime`, (
  SELECT
    UNIQUE_CARRIER,         -- extra column
    ORIGIN_AIRPORT_ID,      -- extra column
    IF(arr_delay < 15, 1, 0) AS on_time,
    carrier,
    origin,
    dest,
    dep_delay,
    taxi_out,
    distance
  FROM `cloud-training-demos.flights.tzcorr`
  WHERE arr_delay IS NOT NULL
  LIMIT 5
))   

显然input_label_cols and data_split_col有不同的目的

input_label_cols STRING The label column name(s) in the training data.

data_split_col STRING This option identifies the column used to split the data [into training and evaluation sets]. This column cannot be used as a feature or label, and will be excluded from features automatically.

关于machine-learning - 从 BigQuery ML 中的训练数据中排除列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51856202/

相关文章:

google-bigquery - Avro 纪元日期时间到 bq 时间戳

javascript - 如何限制 Google Bigquery 中的作业数量

sql - BigQuery 比较日期

python - scipy.io fft 和 ifft 的问题

python - 属性错误: 'Word2Vec' object has no attribute 'endswith'

pandas - 如何更改 tensorflow 的 numpy 数组的数据类型

python - 如何将对象传递给使用 hyperopt 优化的函数?

python - 从 Apache Beam 读取 CSV 并写入 BigQuery

google-bigquery - 如何从 BigQuery 结果中去除非数字字符

machine-learning - 使用已知项目相似性和丰度设置相似性度量