我尝试按照here指令设置我的GBDTLRClassifier。首先,我已经对我的列进行了标签编码。然后,我定义了我的分类和连续特征,将列名放在两个列表中。
cat # categorical column names
conts # continuous column names
gbm = lgb.LGBMClassifier(n_estimator = 90)
classifier = GBDTLRClassifier(gbm, LogisticRegression(penalty='l2'))
dm = DataFrameMapper([([cat_col], CategoricalDomain()) for cat_col in cat] + [(conts, ContinuousDomain())])
pipeline = PMMLPipeline([('mapper', dm), ('classifier', classifier)])
pipeline.fit(df[cat + conts], df['y'], classifier__gbdt__eval_set=[(val[cat + conts], val['y'])], classifier__gbdt__early_stopping_rounds = 5, classifier__gbdt__categorical_feature=cat)
pp = make_pmml_pipeline(pipelin, target_fields=['y'])
sklearn2pmml(pp, '/tmp/lgb+lr.pmml')
我在装配时得到错误信息:TypeError: Wrong type(str) or unknown name(root) in categorical_feature
。而root
绝对是在cat
中。看起来lgbm不知道哪些列是分类的,这是令人困惑的。
此外,当我删除映射器部分时,没有拟合错误,但转换失败,无法制作带有消息:transformer object of the first step does not specify the number of input features
的pmml文件。
有没有人能告诉我如何让这个过程。THx
发布于 2019-10-31 11:00:24
基于comment here,在将字符串列名称发送到categorical_feature
中时,需要设置feature_name
。这里有点棘手。
https://stackoverflow.com/questions/58604234
复制相似问题