把这段代码的PCA换成LDA:LR_grid = LogisticRegression(max_iter=1000, random_state=42)
LR_grid_search = GridSearchCV(LR_grid, param_grid=param_grid, cv=cvx ,scoring=scoring,n_jobs=10,verbose=0)
LR_grid_search.fit(pca_X_train, train_y)
estimators = [
('lr', LR_grid_search.best_estimator_),
('svc', svc_grid_search.best_estimator_),
]
clf = StackingClassifier(estimators=estimators,
final_estimator=LinearSVC(C=5, random_state=42),n_jobs=10,verbose=1)
clf.fit(pca_X_train, train_y)
estimators = [
('lr', LR_grid_search.best_estimator_),
('svc', svc_grid_search.best_estimator_),
]
param_grid = {'final_estimator':[LogisticRegression(C=0.00001),LogisticRegression(C=0.0001),
LogisticRegression(C=0.001),LogisticRegression(C=0.01),
LogisticRegression(C=0.1),LogisticRegression(C=1),
LogisticRegression(C=10),LogisticRegression(C=100),
LogisticRegression(C=1000)]}
Stacking_grid =StackingClassifier(estimators=estimators,)
Stacking_grid_search = GridSearchCV(Stacking_grid, param_grid=param_grid, cv=cvx,
scoring=scoring,n_jobs=10,verbose=0)
Stacking_grid_search.fit(pca_X_train, train_y)
Stacking_grid_search.best_estimator_
train_pre_y = cross_val_predict(Stacking_grid_search.best_estimator_, pca_X_train,train_y, cv=cvx)
train_res1=get_measures_gridloo(train_y,train_pre_y)
test_pre_y = Stacking_grid_search.predict(pca_X_test)
test_res1=get_measures_gridloo(test_y,test_pre_y)
best_pca_train_aucs.append(train_res1.loc[:,"AUC"])
best_pca_test_aucs.append(test_res1.loc[:,"AUC"])
best_pca_train_scores.append(train_res1)
best_pca_test_scores.append(test_res1)
train_aucs.append(np.max(best_pca_train_aucs))
test_aucs.append(best_pca_test_aucs[np.argmax(best_pca_train_aucs)].item())
train_scores.append(best_pca_train_scores[np.argmax(best_pca_train_aucs)])
test_scores.append(best_pca_test_scores[np.argmax(best_pca_train_aucs)])
pca_comp.append(n_components[np.argmax(best_pca_train_aucs)])
print("n_components:")
print(n_components[np.argmax(best_pca_train_aucs)])