Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does calling FuzzyCMeans.predict_proba() alter the centroids of the fitted model? #626

Open
vnmabus opened this issue Aug 5, 2024 Discussed in #625 · 0 comments
Open
Labels

Comments

@vnmabus
Copy link
Member

vnmabus commented Aug 5, 2024

Discussed in #625

Originally posted by ensley-nexant August 5, 2024
I'm trying to understand why I can call .predict_proba() multiple times on the same fitted model, passing the same function, and get different predictions. Is this the intended behavior?

It looks like the centroids are being updated on every prediction, and I'm not sure why that would be the case. Here is an example:

from skfda import datasets
from skfda.ml.clustering import FuzzyCMeans

X, y = datasets.fetch_weather(return_X_y=True, as_frame=True)
fd = X.iloc[:, 0].values.coordinates[0]

kmeans = FuzzyCMeans(n_clusters=4, random_state=2)
kmeans.fit(fd)

print("Initial centroids")
print(kmeans.cluster_centers_.data_matrix[0][:4])

for i in range(1, 5):
    print("\nPrediction", i)
    print(kmeans.predict_proba(fd[1])[0])
    print("Centroids (head):")
    print(kmeans.cluster_centers_.data_matrix[0][:4])

Output:

Initial centroids
[[-7.48331886]
 [-7.69572714]
 [-8.33347371]
 [-8.2457692 ]]

Prediction 1
[0.81649987 0.04951254 0.12522585 0.00876174]
Centroids (head):
[[-4.4]
 [-4.2]
 [-5.3]
 [-5.4]]

Prediction 2
[0.2 0.2 0.2 0.4]
Centroids (head):
[[-4.4]
 [-4.2]
 [-5.3]
 [-5.4]]

Prediction 3
[0.28571429 0.28571429 0.28571429 0.14285714]
Centroids (head):
[[-4.4]
 [-4.2]
 [-5.3]
 [-5.4]]

Prediction 4
[0.25 0.25 0.25 0.25]
Centroids (head):
[[-4.4]
 [-4.2]
 [-5.3]
 [-5.4]]
``` </div>
@vnmabus vnmabus added the bug label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant