sklift.models.TwoModels

class sklift.models.models.TwoModels(estimator_trmnt, estimator_ctrl, method='vanilla')[source]

也称为朴素方法,或差异评分方法,或双分类器方法。

拟合两个独立的模型:一个在治疗数据上,另一个在控制数据上。

了解更多,请参阅用户指南

Parameters
  • estimator_trmnt (实现'fit'的估计器对象) – 用于拟合处理数据的对象。

  • estimator_ctrl (实现'fit'的估计器对象) – 用于拟合控制数据的对象。

  • method (string, 'vanilla', 'ddr_control' or 'ddr_treatment', default='vanilla') –

    指定方法:

    • 'vanilla':

      两个独立的模型;

    • 'ddr_control':

      依赖数据表示(首先训练控制估计器)。

    • 'ddr_treatment':

      依赖数据表示(首先训练处理估计器)。

trmnt_preds_

治疗时对样本的估计器预测。

Type

类数组, 形状 (n_samples, )

ctrl_preds_

控制时对样本的估计器预测。

Type

类数组, 形状 (n_samples, )

示例:

# import approach
from sklift.models import TwoModels
# import any estimator adheres to scikit-learn conventions
from catboost import CatBoostClassifier


estimator_trmnt = CatBoostClassifier(silent=True, thread_count=2, random_state=42)
estimator_ctrl = CatBoostClassifier(silent=True, thread_count=2, random_state=42)

# define approach
tm_ctrl = TwoModels(
    estimator_trmnt=estimator_trmnt,
    estimator_ctrl=estimator_ctrl,
    method='ddr_control'
)

# fit the models
tm_ctrl = tm_ctrl.fit(
    X_train, y_train, treat_train,
    estimator_trmnt_fit_params={'cat_features': cat_features},
    estimator_ctrl_fit_params={'cat_features': cat_features}
)
uplift_tm_ctrl = tm_ctrl.predict(X_val)  # predict uplift
References

贝特莱, 阿特姆 & 迪默特, 尤斯塔什 & 阿米尼, 马西-雷扎. (2018). 在不平衡处理和对照条件下使用依赖特征表示的提升预测: 第25届国际会议, ICONIP 2018, 柬埔寨暹粒, 2018年12月13–16日, 会议记录, 第五部分. 10.1007/978-3-030-04221-9_5.

赵岩 & 方晓 & 大卫·西姆奇-莱维. (2017). 多处理和一般响应类型的提升建模. 10.1137/1.9781611974973.66.

另请参阅

其他方法:

其他:

fit(X, y, treatment, estimator_trmnt_fit_params=None, estimator_ctrl_fit_params=None)[source]

根据给定的训练数据拟合模型。

对于每个测试示例,分别使用第一个和第二个模型对新数据集进行预测。 然后计算这些预测之间的差异作为提升值。

返回每个示例的预测差异。

Parameters
  • X (数组形式, 形状 (n_samples, n_features)) – 训练向量,其中 n_samples 是样本数量,n_features 是特征数量。

  • y (数组形式, 形状 (n_samples,)) – 相对于X的目标向量。

  • treatment (array-like, shape (n_samples,)) – 相对于X的二元处理向量。

  • estimator_trmnt_fit_params (dict, optional) – 传递给处理估计器的拟合方法的参数。

  • estimator_ctrl_fit_params (dict, optional) – 传递给控制估计器的拟合方法的参数。

Returns

self

Return type

对象

predict(X)[source]

对X中的样本进行提升。

Parameters

X (数组形式, 形状 (n_samples, n_features)) – 训练向量,其中 n_samples 是样本数量,n_features 是特征数量。

Returns

提升

Return type

数组 (形状 (n_samples,))