관리 메뉴

물 만날 물고기

[KMeans] 'n_init' 관련 경고 메시지 본문

데이터 마이닝/머신러닝 (Machine Learning)

[KMeans] 'n_init' 관련 경고 메시지

Lung Fish 2023. 3. 2. 03:48

🔍 예상 검색어

더보기

# /usr/local/lib/python3.8/dist-packages/sklearn/cluster/_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning
  warnings.warn(

# KMeans 알고리즘 경고메시지

# `n_init` explicitly 


해당 포스팅은 KMeans 알고리즘을 구현할 때 "The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning" 다음과 같이 나타나는 경고메시지에 대해서 정리하였습니다.

 

▼ 해결방법

 

→ n_init 매개변수를 설정하였는지 확인한다.

from sklearn.cluster import KMeans

# n_init 파라미터 확인
kmeans = KMeans(n_clusters=3, n_init=10)

 

1. 경고메시지 발생

 

KMeansSMOTE 를 이용한 불균형 처리를 위하여 아래와 같이 코드를 작성하였고, kmeans_estimator에 KMeans 모델 파라미터를 입력하여 resampling을 하는 순간 아래와 같은 경고메시지가 발생하였습니다.

KMeansSMOTE(sampling_strategy='auto', k_neighbors=5, random_state=42, kmeans_estimator= KMeans(n_clusters=5, random_state=42), n_jobs=-1)

 

>>> Warning 경고! 메시지 발생

/usr/local/lib/python3.8/dist-packages/sklearn/cluster/_kmeans.py:870: FutureWarning: The default value of `n_init` will change from 10 to 'auto' in 1.4. Set the value of `n_init` explicitly to suppress the warning
  warnings.warn(

 

2. Chat GPT 확인

문제 해결을 위하여 저의 깐부치킨인 Chat GPT에게 원인과 해결방법을 물어보았습니다.

 

 

3.  'n_init=10' 매개변수 값 추가

 

▶ 추가 전

 

▶ 추가 후

 

 


 

 이상이며 n_init 매개변수 값 지정 후 경고메시지가 삭제 되었음을 확인할 수 있었습니다. 저와 같이 경고 메시지가 무슨 의미였는지 궁금하셨던 분은 참고하시기 바랍니다.