首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >LightGBM on Numerical+Categorical+Text Feature >> TypeError:未知类型parameter:boosting_type,got:dict

LightGBM on Numerical+Categorical+Text Feature >> TypeError:未知类型parameter:boosting_type,got:dict
EN

Stack Overflow用户
提问于 2021-02-20 11:08:58
回答 1查看 2.8K关注 0票数 3

我试图在一个由数值、分类和文本数据组成的数据集上训练一个lightGBM模型。但是,在培训阶段,我会遇到以下错误:

代码语言:javascript
复制
params = {
'num_class':5,
'max_depth':8,
'num_leaves':200,
'learning_rate': 0.05,
'n_estimators':500
}

clf = LGBMClassifier(params)
data_processor = ColumnTransformer([
    ('numerical_processing', numerical_processor, numerical_features),
    ('categorical_processing', categorical_processor, categorical_features),
    ('text_processing_0', text_processor_1, text_features[0]),
    ('text_processing_1', text_processor_1, text_features[1])
                                    ]) 
pipeline = Pipeline([
    ('data_processing', data_processor),
    ('lgbm', clf)
                    ])
pipeline.fit(X_train, y_train)

错误是:

代码语言:javascript
复制
TypeError: Unknown type of parameter:boosting_type, got:dict

这是我的管道:

我基本上有两个文本特征,都是某种形式的名字,我主要表现为词干。

任何指示都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-20 12:10:50

您错误地设置了分类器,这给出了错误,在进入管道之前,您可以很容易地尝试:

代码语言:javascript
复制
params = {
'num_class':5,
'max_depth':8,
'num_leaves':200,
'learning_rate': 0.05,
'n_estimators':500
}

clf = LGBMClassifier(params)
clf.fit(np.random.uniform(0,1,(50,2)),np.random.randint(0,5,50))

给出同样的错误:

代码语言:javascript
复制
TypeError: Unknown type of parameter:boosting_type, got:dict

您可以像这样设置分类器:

代码语言:javascript
复制
clf = LGBMClassifier(**params)

然后使用一个例子,您可以看到它正在运行:

代码语言:javascript
复制
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler, OneHotEncoder
from sklearn.compose import ColumnTransformer

numerical_processor = StandardScaler()
categorical_processor = OneHotEncoder()
numerical_features = ['A']
categorical_features = ['B']

data_processor = ColumnTransformer([('numerical_processing', numerical_processor, numerical_features),
('categorical_processing', categorical_processor, categorical_features)])

X_train = pd.DataFrame({'A':np.random.uniform(100),
'B':np.random.choice(['j','k'],100)})

y_train = np.random.randint(0,5,100)

pipeline = Pipeline([('data_processing', data_processor),('lgbm', clf)])

pipeline.fit(X_train, y_train)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66290815

复制
相关文章

相似问题

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