【问题标题】:h2o: F1 score and other binary classification metrics missingh2o:F1 分数和其他二元分类指标缺失
【发布时间】:2021-05-23 01:52:03
【问题描述】:

我能够运行以下示例代码并获得 F1 分数:

import h2o
from h2o.estimators.gbm import H2OGradientBoostingEstimator
h2o.init()

# import the airlines dataset:
# This dataset is used to classify whether a flight will be delayed 'YES' or not "NO"
# original data can be found at http://www.transtats.bts.gov/
airlines= h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/airlines/allyears2k_headers.zip")

# convert columns to factors
airlines["Year"]= airlines["Year"].asfactor()
airlines["Month"]= airlines["Month"].asfactor()
airlines["DayOfWeek"] = airlines["DayOfWeek"].asfactor()
airlines["Cancelled"] = airlines["Cancelled"].asfactor()
airlines['FlightNum'] = airlines['FlightNum'].asfactor()

# set the predictor names and the response column name
predictors = ["Origin", "Dest", "Year", "UniqueCarrier",
              "DayOfWeek", "Month", "Distance", "FlightNum"]
response = "IsDepDelayed"

# split into train and validation sets
train, valid = airlines.split_frame(ratios = [.8], seed = 1234)

# train your model
airlines_gbm = H2OGradientBoostingEstimator(sample_rate = .7, seed = 1234)
airlines_gbm.train(x = predictors,
                   y = response,
                   training_frame = train,
                   validation_frame = valid)

# retrieve the model performance
perf = airlines_gbm.model_performance(valid)
perf

输出如下:

ModelMetricsBinomial: gbm
** Reported on test data. **

MSE: 0.20546330299964743
RMSE: 0.4532806007316521
LogLoss: 0.5967028742962095
Mean Per-Class Error: 0.31720065289432364
AUC: 0.7414970113257631
AUCPR: 0.7616331690362552
Gini: 0.48299402265152613

Confusion Matrix (Act/Pred) for max f1 @ threshold = 0.35417599264806404: 
NO  YES Error   Rate
0   NO  1641.0  2480.0  0.6018  (2480.0/4121.0)
1   YES 595.0   4011.0  0.1292  (595.0/4606.0)
2   Total   2236.0  6491.0  0.3524  (3075.0/8727.0)

...

然而,我的数据集并没有以类似的方式工作,尽管看起来是相同的形式。我的数据集目标变量也有一个二进制标签。关于我的数据集的一些信息:

y_test.nunique()
failure    2
dtype: int64

然而,我的性能 (perf) 指标只是示例代码的一小部分:

perf = gbm.model_performance(hf_test)
perf
ModelMetricsRegression: gbm
** Reported on test data. **

MSE: 0.02363221438767555
RMSE: 0.1537277281028883
MAE: 0.07460874699751764
RMSLE: 0.12362377397478382
Mean Residual Deviance: 0.02363221438767555

由于其敏感性质,很难共享我的数据。关于检查什么的任何想法?

【问题讨论】:

    标签: python h2o gbm


    【解决方案1】:

    您正在训练回归模型,这就是您缺少二元分类指标的原因。 H2O 知道是否训练回归与分类模型的方法是查看响应列的数据类型。

    我们在 H2O 用户指南中解释了 here,但这是我们经常遇到的问题,因为它与 scikit-learn 的工作方式不同,后者使用不同的回归和分类方法,不需要您考虑列类型。

    y_test.nunique()
    failure    2
    dtype: int64
    

    在训练数据的响应列上,您可以执行以下操作:

    train["response"] = train["response"].asfactor()
    

    或者,当您从磁盘读取文件时,您可以将响应列解析为“枚举”类型,因此您不必事后对其进行转换。在 Python here 中有一些如何做到这一点的示例。如果响应存储为整数,H2O 在从磁盘读取数据时只是假设它是一个数字列,但如果响应存储为字符串,它将正确地将其解析为分类(又名“枚举”)列和您无需指定或转换它。

    【讨论】:

      猜你喜欢
      • 2016-11-15
      • 2018-03-13
      • 2016-09-30
      • 2017-10-20
      • 2019-06-29
      • 2021-04-11
      • 1970-01-01
      • 2020-04-03
      • 2019-05-29
      相关资源
      最近更新 更多