Я запускаю k-means с помощью sklearn, но во время выполнения получаю предупреждение. Можете ли вы объяснить, что происходит? Ниже приведен пример кода для воспроизводимости:
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler
from sklearn.cluster import KMeans
col1 = np.random.normal(loc=0, scale=1, size=1000)
col2 = np.random.normal(loc=1, scale=1, size=1000)
col3 = np.random.normal(loc=2, scale=4, size=1000)
col4 = np.random.normal(loc=3, scale=3, size=1000)
df = pd.DataFrame(list(zip(col1, col2, col3, col4)))
scaler = StandardScaler()
scaled_df = scaler.fit_transform(df)
kmeans = KMeans(n_clusters=2, init='k-means++', max_iter=300, random_state=0)
kmeans.fit(df)
Предупреждения:
miniconda3/lib/python3.13/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: divide by zero encountered in matmul
ret = a @ b
miniconda3/lib/python3.13/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: overflow encountered in matmul
ret = a @ b
miniconda3/lib/python3.13/site-packages/sklearn/utils/extmath.py:203: RuntimeWarning: invalid value encountered in matmul
ret = a @ b
miniconda3/lib/python3.13/site-packages/sklearn/cluster/_kmeans.py:237: RuntimeWarning: divide by zero encountered in matmul
current_pot = closest_dist_sq @ sample_weight
miniconda3/lib/python3.13/site-packages/sklearn/cluster/_kmeans.py:237: RuntimeWarning: overflow encountered in matmul
current_pot = closest_dist_sq @ sample_weight
miniconda3/lib/python3.13/site-packages/sklearn/cluster/_kmeans.py:237: RuntimeWarning: invalid value encountered in matmul
current_pot = closest_dist_sq @ sample_weight
Подробнее здесь: https://stackoverflow.com/questions/796 ... arn-kmeans