增益和提升图的公式可以在此文件中找到:https://github.com/h2oai/h2o-3/blob/master/h2o-core/src/main/java/hex/GainsLift.java
其中显示:
E = 事件总数
N = 观察次数
G = 组数(十分位数为 10 或半十分位数为 20)
P = 作为事件的观察的总体比例 (P = E/N)
ei = i 组中的事件数,i=1,2,...,G
ni = i 组中的观察次数
pi = 第 i 组中作为事件的观察的比例 (pi = ei/ni)
组:硬编码为 16;如果唯一概率值少于 16 个,则组数减少到唯一分位数阈值的数量。
累积数据分数 = sum_n_i/N
lower_threshold = 由分位数箱设置
提升 = pi/P
cumulative_lift = (Σiei/Σini)/P
response_rate = 100*pi
cumulative_response_rate = 100*Σiei/Σini
capture_rate = 100*ei/E
cumulative_capture_rate = 100*Σiei/E
增益 = 100*(lift-1)
cumulative_gain = 100*(sum_lift-1)
average_response_rate = E/N
以下是使用 H2O-3 Python API 的示例演练:
import h2o
import pandas as pd
import numpy as np
from h2o.estimators.gbm import H2OGradientBoostingEstimator
h2o.init()
# import and split the dataset
cars = h2o.import_file("https://s3.amazonaws.com/h2o-public-test-data/smalldata/junit/cars_20mpg.csv")
convert response column to a factor
cars["economy_20mpg"] = cars["economy_20mpg"].asfactor()
# set the predictor names and the response column name
predictors = ["displacement","power","weight","acceleration","year"]
response = "economy_20mpg"
# split dataset
train, valid = cars.split_frame(ratios=[.7],seed=1234)
# Initialize and train a GBM
cars_gbm = H2OGradientBoostingEstimator(seed = 1234)
cars_gbm.train(x = predictors, y = response, training_frame = train, validation_frame=valid)
# Generate Gains and Lift Table
# documentation on this parameter can be found here:
# http://docs.h2o.ai/h2o/latest-stable/h2o-py/docs/model_categories.html?#h2o.model.H2OBinomialModel.gains_lift
gainslift = cars_gbm.gains_lift(train=False, valid=True, xval=False)
表格概览
正如预期的那样,我们有 16 个组,因为这是硬编码的默认行为。
- 累积数据分数
- 阈值概率值
- 响应率(一组事件的观察比例)
- 累计回复率
- 事件捕获率
- 累计捕获率
- 增益(事件的总比例与观察到的作为组中事件的比例之间的百分比差异)
- 累计收益
如果我只想要十分位数怎么办
默认情况下,增益和提升表为您提供的不仅仅是十分位数或通风,这意味着您可以更灵活地选择您感兴趣的百分位数。
让我们以获取十分位数为例。在这个例子中,我们看到我们可以从第 6 行开始,跳过第 7 行,然后取其余行来获取我们的十分位数。
由于增益和提升表返回一个 TwoDimTable,我们可以使用我们的组号作为选择索引。
# show gains and lift table data type
print('H2O Gains Lift Table is of type: ', type(gainslift))
H2O Gains Lift Table is of type: <class 'h2o.two_dim_table.H2OTwoDimTable'>
# since this table is small and for ease of use let's covert to a pandas dataframe
pandas_gl = gainslift.as_data_frame()
pandas_gl.set_index('group')
gainslift_deciles = pandas_gl.iloc[pd.np.r_[5,7:16], :]
gainslift_deciles
如果我只想要通风口怎么办
这些也可以选择,所以接下来让我们这样做。
gainslift_ventiles = pandas_gl.iloc[pd.np.r_[7,9,11,13,15], :]
gainslift_ventiles