Coder Social home page Coder Social logo

Comments (6)

joshlk avatar joshlk commented on August 20, 2024

Hi, thanks for taking the time and filing a issue. Can you please provide the full error as I think you have forgot to include it? Could you also provide me with the sklearn, scipy and numpy version. And what system are you using? Mac/Linux/Windows?

from k-means-constrained.

zjorgensenbits avatar zjorgensenbits commented on August 20, 2024

Thanks for the quick response, and sorry for the omission. The exception is getting thrown by this check on line 483 of k_means_contrained_.py:

if min_cost_flow.Solve() != min_cost_flow.OPTIMAL:
   raise Exception('There was an issue with the min cost flow input.')

Digging into it deeper, I see that min_cost_flow.Solve() is returning 3, while min_cost_flow.OPTIMAL is 1.

Versions:
numpy==1.13.3
scikit_learn==0.24.1
k-means-constrained==0.5.1

OS: Ubuntu 18.04.5

from k-means-constrained.

joshlk avatar joshlk commented on August 20, 2024

Could you also please provide a minimal working example that produces the error

from k-means-constrained.

zjorgensenbits avatar zjorgensenbits commented on August 20, 2024
from k_means_constrained import KMeansConstrained
import numpy as np

X = np.array([[11.43817265911908, 3.0796017788793604], [8.656592391707292, -0.5358447753622294], [7.302104968579831, -2.2195335805441103], [7.1817782508003924, 5.142237391259907], [6.672130682774286, 1.9154397778535366], [6.335350488151739, -5.14734393191299], [-4.467719064297461, 2.198353204833053], [6.259064200368242, 4.7330446470564445], [10.769348531911556, 0.7475931768575942], [12.555003395037621, -0.8724602182508533], [10.9665526970981, -4.4246780352423]])

clf = KMeansConstrained(n_clusters=2, size_min=2, size_max=5, random_state=0)
clf.fit_predict(X)

Traceback (most recent call last):
File "/home/tatooine/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 3343, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 5, in
clf.fit_predict(X)
File "/home/tatooine/.local/lib/python3.6/site-packages/k_means_constrained/k_means_constrained_.py", line 730, in fit_predict
return self.fit(X).labels_
File "/home/tatooine/.local/lib/python3.6/site-packages/k_means_constrained/k_means_constrained_.py", line 642, in fit
return_n_iter=True)
File "/home/tatooine/.local/lib/python3.6/site-packages/k_means_constrained/k_means_constrained_.py", line 180, in k_means_constrained
x_squared_norms=x_squared_norms, random_state=random_state)
File "/home/tatooine/.local/lib/python3.6/site-packages/k_means_constrained/k_means_constrained_.py", line 328, in kmeans_constrained_single
labels_constrained(X, centers, size_min, size_max, distances=distances)
File "/home/tatooine/.local/lib/python3.6/site-packages/k_means_constrained/k_means_constrained
.py", line 399, in labels_constrained
labels = solve_min_cost_flow_graph(edges, costs, capacities, supplies, n_C, n_X)
File "/home/tatooine/.local/lib/python3.6/site-packages/k_means_constrained/k_means_constrained
.py", line 484, in solve_min_cost_flow_graph
raise Exception('There was an issue with the min cost flow input.')
Exception: There was an issue with the min cost flow input.

from k-means-constrained.

joshlk avatar joshlk commented on August 20, 2024

Hi @zjorgensenbits,

The constraints you have provided make the problem unsolvable i.e. you have 11 data points and said you want 2 clusters with max size 5. There is no way of solving this as 2*5=10<11.

However, the user input should be validated before trying to solve the solve_min_cost_flow_graph - I will add to the code 😃 thanks.

Josh

from k-means-constrained.

zjorgensenbits avatar zjorgensenbits commented on August 20, 2024

doh! you're right--I'm an idiot. I misinterpreted "min_size" and "max_size" as the min and max number of clusters...
I'll go ahead and close this. Thanks for catching my error!

from k-means-constrained.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.