gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:01:47 32 4
gpt4 key购买 nike

我正在尝试在由数字、分类和文本数据组成的数据集上训练 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/

32 4 0