from sklearn.svm import SVC
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import GridSearchCV
def fit_clasifiers(gs_clfs, X, y):
for clf in gs_clfs:
print(X.shape)
clf.fit(X, y)
def show_gridsearch_result(gs_clfs):
estimators = []
scores = []
params = []
for clf in gs_clfs:
estimators.append(str(clf.estimator))
scores.append(clf.best_score_)
params.append(clf.best_params_)
for i, val in enumerate(estimators):
print(val)
print(scores[i])
print(params[i])
X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2)
svc = SVC(probability=True)
rf = RandomForestClassifier()
param_lr = {"penalty":["l1", "l2", "elasticnet", "none"]}
param_svc = {"kernel":["linear", "poly", "rbf", "sigmoid"]}
param_tree = {
"max_depth" : [3, 4, 5, 6],
"min_samples_split" : [2, 3]
}
gs_svc = GridSearchCV(svc, param_grid=param_svc, cv=5, refit=True
)
gs_rf = GridSearchCV(rf, param_grid=param_tree, cv=5, refit=True)
gs_clfs = [gs_svc,gs_rf]
fit_clasifiers(gs_clfs, X_train, y_train)
show_gridsearch_result(gs_clfs)
이코드에서 어떻게 피벨류 구하는지 아시는분
-코드는 캐글에서 가지고왔습니다.- 개인적으로 공부하려고