728x90
from sklearn.model_selection import GridSearchCV
from sklearn.neighbors import KNeighborsClassifier
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import MinMaxScaler
knn_pipe = Pipeline([('mms', MinMaxScaler()),
('knn', KNeighborsClassifier())])
params = [{'knn__n_neighbors': [3, 5, 7, 9],
'knn__weights': ['uniform', 'distance'],
'knn__leaf_size': [15, 20]}]
gs_knn = GridSearchCV(knn_pipe,
param_grid=params,
scoring='accuracy',
cv=5)
gs_knn.fit(X_train, y_train)
gs_knn.best_params_
#Output:
#{'knn__leaf_size': 15, 'knn__n_neighbors': 5, 'knn__weights': 'distance'}
# find best model score
gs_knn.score(X_train, y_train)
#Output: 0.84035137
728x90
'Data Science > Python' 카테고리의 다른 글
[Python] Faiss 활용한 Vector 유사도 측정 및 검색 (0) | 2022.09.17 |
---|---|
[Python] NLP : TreebankWordTokenizer, Pos Tag (0) | 2022.09.17 |
[colab] Kaggle Dataset Load in Colab (0) | 2022.09.08 |
[python] dataframe apply() multiprocessing (0) | 2022.09.05 |
[python] 그래프에서 두 좌표의 거리 계산 (0) | 2022.09.05 |
최근댓글