0

I'm in a spot where I need to convert then save h2o4gpu Kmeans object to just a sklearn object.

I thought maybe I could just do this? I was expecting I would be able to save sklearn_model and load it, but I get error: AttributeError: 'KMeans' object has no attribute '_n_threads'

from h2o4gpu.solvers import KMeans as GPUKMeans
from sklearn.cluster import KMeans

...

gpu_model = GPUKMeans(n_clusters=num_clusters)

gpu_model.fit(embeddings)

sklearn_model = KMeans(n_clusters=num_clusters)
sklearn_model.cluster_centers_= gpu_model.cluster_centers_;

...


Taylor Hawkes
  • 641
  • 7
  • 10

1 Answers1

0

After digging into source code I found some code that was doing a similar thing:

from h2o4gpu.solvers import KMeans as GPUKMeans
from sklearn.cluster import KMeans
from sklearn.utils._openmp_helpers import _openmp_effective_n_threads    

...

gpu_model = GPUKMeans(n_clusters=num_clusters)

gpu_model.fit(embeddings)

kmeans_model = KMeans(n_clusters=num_clusters)
kmeans_model.cluster_centers_= gpu_model.cluster_centers_;
kmeans_model.labels_= gpu_model.labels_;
kmeans_model.inertia_= gpu_model.inertia_;
kmeans_model._n_threads = _openmp_effective_n_threads()



...
Taylor Hawkes
  • 641
  • 7
  • 10