-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
33 lines (25 loc) · 920 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import time
import matplotlib.pyplot as plt
import numpy as np
#from sklearn.cluster import MeanShift
from sklearn import datasets, cluster
from sklearn.preprocessing import StandardScaler
from meanshift.mean_shift_gpu import MeanShiftEuc
def main():
# Generate a blob dataset.
n_samples = 100000
blobs = datasets.make_blobs(n_samples=n_samples, random_state=9)
# Normalize dataset for easier parameter selection
X, y = blobs
X = StandardScaler().fit_transform(X)
# Estimate bandwidth for mean shift(Select 1000 points)
bandwidth = cluster.estimate_bandwidth(X[0:999])
bandwidth_gpu = 2*bandwidth/(X.max()-X.min())
# Obtain results
ms = MeanShiftEuc(bandwidth=bandwidth_gpu, cluster_all=True, GPU=True)
ms.fit(X)
labels = ms.labels_
return 0
if __name__ == "__main__":
# execute only if run as a script
main()