tensorflow - 将 What if 工具与 xgboost 一起使用
问题描述
我正在尝试在我的 xgboost 模型上使用 what if 工具。但在链接上,我只能找到通过 google AI Platform 使用的 xgboost 示例。有没有什么方法可以在没有 Google AI 平台的情况下在 XGboost 上使用 whatif 工具
我尝试了 tensorflow 和 keras 示例中使用的函数,并使用了函数 set_estimator_and_feature_spec 和 set_compare_custom_predict_fn
bst = xgb.XGBClassifier(
objective='reg:logistic'
)
bst.fit(x_train, y_train)
test_examples = df_to_examples(df_test)
config_builder = WitConfigBuilder(test_examples).set_custom_predict_fn(xg.predict)
WitWidget(config_builder)
尝试执行运行推理时,显示错误消息cannot initialize DMatrix from a list
,我无法执行此操作
解决方案
经过大量试验和错误后,我终于使用以下代码使其与 XGBoost 一起使用:
# first argument in my case is a Pandas dataframe of all features and the target 'label';
# extract just the numpy array with 'values', then convert that to a list
# second argument is the column name as a list
# I use a sklearn pipeline, so here I am just accessing the classifier model which is an XGBClassifier instance
# Wit tool expects a 2D array, where the 1st dimension is each sample, and 2nd dimension is probabilities of
# each class; so use 'predict_proba' over 'predict'
config_builder = (WitConfigBuilder(df_sample.values.tolist(), df_sample.columns.tolist())
.set_custom_predict_fn(clf['classifier'].predict_proba)
.set_target_feature('label')
.set_label_vocab(['No Churn', 'Churn']))
这消除了使用他们建议的辅助函数的需要,并且可以与 Pandas DataFrames 和 Sklearn ML 模型一起使用
推荐阅读
- c# - 在 C# 项目中获取 TeamCity 构建版本
- python - 如何在 BeautifulSoup 中找到父 li
- python-3.x - 'Image' 类型的参数不可迭代
- typescript - 在 google 电子表格 api 请求中过滤数据
- docker - Docker 执行用户进程失败导致“没有这样的文件或目录
- rust - 如何使用actix将请求正文作为文本获取?
- python - 这个 datetime.strptime 函数的正确代码格式是什么?
- android - 是否有一个 ViewModel 在 Activity 的 onPause 上被清除(进入后台),我应该改用什么?
- ios - 订阅 RxSwift Observable
不触发 onNext() - python - 有没有办法可以为一个变量分配两个不同的值?