Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 스택
- 파이썬을파이썬답게
- SMAPE
- Python
- 에러해결
- mes
- Alignments
- python 갯수세기
- 논문editor
- iNT
- Pycaret
- 논문
- n_sample
- Scienceplots
- 평가지표
- PAPER
- Mae
- n_neighbors
- 카카오
- mMAPE
- 프로그래머스
- knn
- 논문작성
- MAPE
- Tire
- KAKAO
- Overleaf
- 코테
- RMES
- TypeError
Archives
- Today
- Total
EunGyeongKim
[pycaret] Knn 오류 (Expected n_neighbors <= n_samples,) 본문
pycaret의 Knn(KNeighborsClassifier)을 튜닝할때 생기는 오류 중하나를 정리하였다.
#라이브러리 불러오기
from pycaret.regression import *
#setup
MachineLearning_Model = setup(data = df)
# 모델생성
knn = create_model('knn')
# 모델 튜닝
tuned_knn = tune_model(knn)
맨 마지막 knn모델을 튜닝할때 오류가 난다.

The above exception was the direct cause of the following exception:
ValueError Traceback (most recent call last)
<ipython-input-25-66e865e7c45e> in <module>() ----> 1 tuned_knn = tune_model(knn)
10 frames
/usr/lib/python3.7/concurrent/futures/_base.py in __get_result(self) 382 def __get_result(self): 383 if self._exception: --> 384 raise self._exception 385 else: 386 return self._result
ValueError: Expected n_neighbors <= n_samples, but n_samples = 43, n_neighbors = 49
knn에서 만들어진 n_neighbor가 n_samples의 갯수보다 작아야하는데 커서 생기는 오류이다.
해결방법
tuned_knn = tune_model(knn, custom_grid = {'n_neighbors' : np.arange(0,30,1)})
knn을 튜닝할때 custom_grid를 이용하여 n_neighbors를 설정하였다.
걍 int형을 써서 설정한 경우도 있었으나. 그럴경우
TypeError: Parameter value is not iterable or distribution (key='actual_estimator__n_neighbors', value=2)
에러가 뜬다.
Reference
https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsRegressor.html
'ML & DL' 카테고리의 다른 글
딥러닝 단어 정리 (0) | 2022.07.23 |
---|---|
[NN] MNIST 분류 Neural Network (0) | 2022.07.22 |
[deep learning] early stopping (0) | 2022.02.06 |
[통계] 기초통계 (0) | 2022.02.05 |
[머신러닝] EDA(Exploratory Data Analysis) 탐색적 데이터 분석 (0) | 2022.02.04 |