我正在使用lightgbm查找功能重要性,但我遇到了错误 lightgbm error:b'len of label is not same with data'. 。 X.形状 (73147、12) Y形 (73147,)
lightgbm error:b'len of label is not same with data'. 。 X.形状 (73147、12) Y形 (73147,)
。 X.形状 (73147、12) Y形 (73147,)
代码: 来自sklearn.model_selection import train_test_split 将lightgbm导入为lgb #初始化空数组以保存功能导入 特征输入=np.zeros(x.shape[1]) #使用多个超参数创建模型 model=lgb.lgbmClassifier(objective='binary',boosting'goss',n'u estimators=10000,class'weight='balanced') #安装模型两次以避免过度安装 对于范围(2)中的i: #分为培训和验证集 x_-train,x_-test,y_-train,y_-test=train_-test_-split(x,y,test_-size=0.25,random_-state=i) #列车使用早停 模型.拟合(x,y_列车,早期停止轮数=100,eval_设置=[(x_测试,y_测试)] eval_metric='auc',verbose=200) #记录特征导入 feature_importances+=型号。feature_importances_ 请参见下面的屏幕截图: . 代码: 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_ 请参见下面的屏幕截图:
代码:
来自sklearn.model_selection import train_test_split 将lightgbm导入为lgb #初始化空数组以保存功能导入 特征输入=np.zeros(x.shape[1]) #使用多个超参数创建模型 model=lgb.lgbmClassifier(objective='binary',boosting'goss',n'u estimators=10000,class'weight='balanced') #安装模型两次以避免过度安装 对于范围(2)中的i: #分为培训和验证集 x_-train,x_-test,y_-train,y_-test=train_-test_-split(x,y,test_-size=0.25,random_-state=i) #列车使用早停 模型.拟合(x,y_列车,早期停止轮数=100,eval_设置=[(x_测试,y_测试)] eval_metric='auc',verbose=200) #记录特征导入 feature_importances+=型号。feature_importances_ 请参见下面的屏幕截图: . 代码: 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_ 请参见下面的屏幕截图:
请参见下面的屏幕截图: . 代码: 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_ 请参见下面的屏幕截图:
请参见下面的屏幕截图:
.
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_
model.fit(X, y_train, [...])
model.fit(X_train, y_train, [...])
X 和 y_train
X
y_train