def kmeans (): print 'KMeans' from shogun.Distance import EuclidianDistance from shogun.Features import RealFeatures from shogun.Clustering import KMeans k=3 feats_train=RealFeatures(fm_train) distance=EuclidianDistance(feats_train, feats_train) kmeans=KMeans(k, distance) kmeans.train() kmeans.get_cluster_centers() kmeans.get_radiuses()
def run_clustering(data, k): from shogun.Clustering import KMeans from shogun.Mathematics import Math_init_random Math_init_random(42) fea = RealFeatures(data) distance = EuclidianDistance(fea, fea) kmeans=KMeans(k, distance) print("Running clustering...") kmeans.train() return kmeans.get_cluster_centers()
def run_clustering(data, k): from shogun.Clustering import KMeans from shogun.Mathematics import Math_init_random Math_init_random(42) fea = RealFeatures(data) distance = EuclidianDistance(fea, fea) kmeans = KMeans(k, distance) print("Running clustering...") kmeans.train() return kmeans.get_cluster_centers()
def run_clustering(data, k): from shogun.Clustering import KMeans from shogun.Distance import EuclideanDistance from shogun.Features import RealFeatures fea = RealFeatures(data) distance = EuclideanDistance(fea, fea) kmeans = KMeans(k, distance) #print("Running clustering...") kmeans.train() return kmeans.get_cluster_centers()
def run_clustering(data, k): from shogun.Clustering import KMeans from shogun.Distance import EuclideanDistance from shogun.Features import RealFeatures fea = RealFeatures(data) distance = EuclideanDistance(fea, fea) kmeans=KMeans(k, distance) #print("Running clustering...") kmeans.train() return kmeans.get_cluster_centers()
def bench_shogun(X, y, T, valid): # # .. Shogun .. # from shogun.Distance import EuclidianDistance from shogun.Features import RealFeatures from shogun.Clustering import KMeans start = datetime.now() feat = RealFeatures(X.T) distance = EuclidianDistance(feat, feat) clf = KMeans(n_components, distance) clf.train() return inertia(X, clf.get_cluster_centers()), datetime.now() - start
def kmeans(train, k=3): Math_init_random(17) feats_train = RealFeatures(train) distance = EuclidianDistance(feats_train, feats_train) kmeans = KMeans(k, distance) kmeans.train() out_centers = kmeans.get_cluster_centers() kmeans.get_radiuses() return out_centers, kmeans
def bench_shogun(X, y, T, valid): # # .. Shogun .. # from shogun.Distance import EuclidianDistance from shogun.Features import RealFeatures from shogun.Clustering import KMeans start = datetime.now() feat = RealFeatures(X.T) distance = EuclidianDistance(feat, feat) clf = KMeans(n_components, distance) clf.train() delta = datetime.now() - start return inertia(X, clf.get_cluster_centers().T), delta
def clustering_kmeans_modular (fm_train=traindat,k=3): from shogun.Distance import EuclideanDistance from shogun.Features import RealFeatures from shogun.Clustering import KMeans from shogun.Mathematics import Math_init_random Math_init_random(17) feats_train=RealFeatures(fm_train) distance=EuclideanDistance(feats_train, feats_train) kmeans=KMeans(k, distance) kmeans.train() out_centers = kmeans.get_cluster_centers() kmeans.get_radiuses() return out_centers, kmeans
def clustering_kmeans_modular(fm_train=traindat, k=3): from shogun.Distance import EuclidianDistance from shogun.Features import RealFeatures from shogun.Clustering import KMeans from shogun.Mathematics import Math_init_random Math_init_random(17) feats_train = RealFeatures(fm_train) distance = EuclidianDistance(feats_train, feats_train) kmeans = KMeans(k, distance) kmeans.train() out_centers = kmeans.get_cluster_centers() kmeans.get_radiuses() return out_centers, kmeans