python - LightGBM on Numerical+Categorical+Text Features >> TypeError : Unknown type of parameter:boosting_type, got:dict

标签 python machine-learning scikit-learn nlp lightgbm

我正在尝试在由数字、分类和文本数据组成的数据集上训练 lightGBM 模型。但是,在训练阶段,出现以下错误:

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)

错误是:

TypeError: Unknown type of parameter:boosting_type, got:dict

这是我的管道: enter image description here

我基本上有两个文本特征,都是某种形式的名称,我主要在这些名称上执行词干提取。

如有任何指点,我们将不胜感激。

最佳答案

你错误地设置了分类器,这给了你错误,你可以在进入管道之前轻松地尝试这个:

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))

给你同样的错误:

TypeError: Unknown type of parameter:boosting_type, got:dict

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

clf = LGBMClassifier(**params)

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

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)

关于python - LightGBM on Numerical+Categorical+Text Features >> TypeError : Unknown type of parameter:boosting_type, got:dict,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66290815/

相关文章:

python - nginx:[警告] 0.0.0.0:80 上的冲突服务器名称 "example.com",已忽略

python - SKlearn 使用什么算法来最小化 MSE?

c++ - Dlib MLP 中的偏置节点?

python - sklearn 绘制 SVM 分类器的结果

python - Lasso 和 RobustScalar 之后如何对回归预测进行逆变换?

python - Seaborn 调色板不适用于线图

python - Celery 在具有其他文件名的文件中发现任务

python - matplotlib中表格和图形大小的关系

python - ValueError : logits and labels must have the same shape ((None, 6, 8, 1) vs (None, 1))

具有混合数据类型(文本、数字、分类)的 Python scikit-learn 分类