본문으로 바로가기
728x90
from sklearn.linear_model import LogisticRegression / LinearRegression / BayesianRidge / Ridge / Lasso / ElasticNet
from sklearn.svm import SVC / SVR
from sklearn.neighbors import KNeighborsClassifier / KNeighborsRegressor
from sklearn.tree import DecisionTreeClassifier / DecisionTreeRegressor
from sklearn.neural_network import MLPClassifier / MLPRegressor
from sklearn.ensemble import RandomForestClassifier / RandomForestRegressor
                             VotingClassifier / VotingRegressor
                             BaggingClassifier / BaggingRegressor
                             StackingClassifier / StackingRegressor
                             AdaBoostClassifier
                             GradientBoostingClassifier
from sklearn.cluster import KMeans / DBSCAN
from sklearn.naive_bayes import GaussianNB

model = LogisticRegression() / LinearRegression() / BayesianRidge() / Ridge() / Lasso() / ElasticNet()
      = SVC() / SVR(kernel='poly')
      = KNeighborsClassifier(n_neighbors=n) / KNeighborsRegressor()
      = DecisionTreeClassifier() / DecisionTreeRegressor()
      = MLPClassifier() / MLPRegressor()
      = RandomForestClassifier() / RandomForestRegressor()
      = VotingClassifier(estimators=[...], voting='soft') / VotingRegressor(estimators=[...], voting='soft')
      = BaggingClassifier() / BaggingRegressor()
      = StackingClassifier() / StackingRegressor()
      = AdaBoostClassifier()
      = GradientBoostingClassifier()
      = KMeans(n_cluster=k) / DBSCAN(...)
      = GaussianNB()

model.fit(X_scaled_train, y_train)

pred_test = model.predict(X_scaled_test)
          = model.predict_proba(X_scaled_test)

score = model.score(X_scaled_test, y_test)

# 교차검증
from sklearn.model_selection import cross_val_score
from sklearn.model_selection import KFold
kfold = KFold(n_splits=n, shuffle=True, random_state=42)
score = cross_val_score(model, X_scaled_train, y_train, cv=kfold)
728x90