LightGBM在数值+分类+文本特征上的应用 >> TypeError: Unknown type of parameter:boosting_type, got:dict

我正在尝试在一个包含数值、分类和文本数据的数据集上训练一个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

这是我的pipeline:enter image description here

我有两个文本特征,主要是对一些形式的名称进行词干提取。

任何建议都会非常感激。


回答:

您设置分类器的方式是错误的,这导致了错误,您可以在进入pipeline之前先尝试一下:

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 Pipelinefrom sklearn.preprocessing import StandardScaler, OneHotEncoderfrom sklearn.compose import ColumnTransformernumerical_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)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注