首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将What if工具与xgboost结合使用

将What if工具与xgboost结合使用
EN

Stack Overflow用户
提问于 2019-08-05 15:57:43
回答 1查看 432关注 0票数 2

我正在尝试在我的xgboost模型上使用假设工具。但在link上,我只能找到通过谷歌AI平台使用的xgboost示例。有没有办法在没有谷歌AI平台的情况下在XGboost上使用whatif工具

我尝试了tensorflow和keras示例中使用的函数,并使用了函数set_estimator_and_feature_spec和set_compare_custom_predict_fn

代码语言:javascript
复制
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,我并非无法执行此操作

EN

回答 1

Stack Overflow用户

发布于 2020-09-17 10:25:58

代码语言:javascript
复制
# 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模型

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57354418

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档