gpt4 book ai didi

python - LightGBM 错误 - 长度与数据不同

转载 作者:行者123 更新时间:2023-11-30 09:06:26 25 4
gpt4 key购买 nike

我使用 lightGBM 来查找特征重要性,但收到错误 LightGBMError: b'len of label is not same with #data' 。 X形 (73147, 12) y 形状 (73147,)

代码:

from sklearn.model_selection import train_test_split
import lightgbm as lgb

# Initialize an empty array to hold feature importances
feature_importances = np.zeros(X.shape[1])

# Create the model with several hyperparameters
model = lgb.LGBMClassifier(objective='binary', boosting_type = 'goss', n_estimators = 10000, class_weight = 'balanced')

# Fit the model twice to avoid overfitting
for i in range(2):

# Split into training and validation set
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = i)

# Train using early stopping
model.fit(X, y_train, early_stopping_rounds=100, eval_set = [(X_test, y_test)],
eval_metric = 'auc', verbose = 200)

# Record the feature importances
feature_importances += model.feature_importances_

请参阅下面的屏幕截图:

enter image description here

最佳答案

您的代码中似乎有一个拼写错误;而不是

model.fit(X, y_train, [...])

应该是

model.fit(X_train, y_train, [...])

现在,可以理解 Xy_train 的长度不同,因此你的错误。

关于python - LightGBM 错误 - 长度与数据不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51064919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com