무던히 하다보면 느는

[파이썬/Python] 파이프라인 본문

파이썬

[파이썬/Python] 파이프라인

무던히 하다보면 느는 2022. 7. 12. 00:46
X_features = df.iloc[:,:-1]
y_target = df.iloc[:,-1]

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X_features, y_target, test_size=0.3, random_state=1, stratify=y_target)

 

scaler = MinMaxScaler()
base_model = SVC(random_state=1)

pipe = Pipeline([('scaler',scaler),
                 ('base_model',base_model)])  
                 
# 그리드 서치

from sklearn.model_selection import KFold, GridSearchCV
kfold=KFold(n_splits=3,shuffle=True,random_state=1)

param_grid = {'base_model__C':[0.03,0.05,10],
              'base_model__gamma':[0.03,0.05,10],
              'base_model__degree':[1,2,3,4,5,6,7,8,9,10]}
pipe = Pipeline([('scaler',scaler),
                 ('base_model',base_model)]) 
grid_model=GridSearchCV(estimator=pipe,
                        param_grid=param_grid,
                        cv=kfold,
                        #iid=True,
                        n_jobs=-1).fit(X_train,y_train)