H2O Gain/Lift table
H2O Gain/Lift table
我的问题是关于 H2O Gain/Lift table。我理解的响应率是属于group/bin的所有事件的比例。如何获取落入 bin 1、bin 2 等的数据? 我想看看关键变量在每个 group/bin 中的响应率如何。
最好能完整描述 Gain/Lift table 中的度量是如何计算的(公式)
增益图和提升图的方程式可在此文件中找到: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*圆周率
累积_response_rate = 100*Σiei/Σini
capture_rate = 100*ei/E
累积_capture_rate = 100*Σiei/E
增益 = 100*(lift-1)
cumulative_gain = 100*(sum_lift-1)
平均_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)
Table 概述
正如预期的那样,我们有 16 个组,因为这是硬编码的默认行为。
- 累计数据分数
- 阈值概率值
- 响应率(作为组中事件的观测值的比例)
- 累计回复率
- 事件捕获率
- 累计捕获率
- 收益(事件的总体比例与观察到的组中事件的观察比例之间的百分比差异)
- 累计收益
如果我只想要十分位数怎么办
默认情况下,增益和提升 Table 为您提供的不仅仅是十分位数或百分位数,这意味着您可以更灵活地选择您感兴趣的百分位数。
让我们以获取十分位数为例。在此示例中,我们看到我们可以从第 6 行开始,跳过第 7 行,然后获取其余行以获得我们的十分位数。
由于增益和提升 Table returns a TwoDimTable 我们可以使用我们的组号作为 select 离子指数。
# 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
如果我只想要 Ventiles 怎么办
这些也可供 select 使用,所以让我们接下来做。
gainslift_ventiles = pandas_gl.iloc[pd.np.r_[7,9,11,13,15], :]
gainslift_ventiles
我的问题是关于 H2O Gain/Lift table。我理解的响应率是属于group/bin的所有事件的比例。如何获取落入 bin 1、bin 2 等的数据? 我想看看关键变量在每个 group/bin 中的响应率如何。
最好能完整描述 Gain/Lift table 中的度量是如何计算的(公式)
增益图和提升图的方程式可在此文件中找到: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*圆周率
累积_response_rate = 100*Σiei/Σini
capture_rate = 100*ei/E
累积_capture_rate = 100*Σiei/E
增益 = 100*(lift-1)
cumulative_gain = 100*(sum_lift-1)
平均_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)
Table 概述
正如预期的那样,我们有 16 个组,因为这是硬编码的默认行为。
- 累计数据分数
- 阈值概率值
- 响应率(作为组中事件的观测值的比例)
- 累计回复率
- 事件捕获率
- 累计捕获率
- 收益(事件的总体比例与观察到的组中事件的观察比例之间的百分比差异)
- 累计收益
如果我只想要十分位数怎么办
默认情况下,增益和提升 Table 为您提供的不仅仅是十分位数或百分位数,这意味着您可以更灵活地选择您感兴趣的百分位数。
让我们以获取十分位数为例。在此示例中,我们看到我们可以从第 6 行开始,跳过第 7 行,然后获取其余行以获得我们的十分位数。
由于增益和提升 Table returns a TwoDimTable 我们可以使用我们的组号作为 select 离子指数。
# 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
如果我只想要 Ventiles 怎么办
这些也可供 select 使用,所以让我们接下来做。
gainslift_ventiles = pandas_gl.iloc[pd.np.r_[7,9,11,13,15], :]
gainslift_ventiles