from sklearn.cluster import MeanShift
import numpy as np

mean_shift = MeanShift()

# predefined data
mean_shift.fit(data)

# cluster assignments
print('{}\n'.format(repr(mean_shift.labels_)))
# array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
#        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
#        1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

# centroids
print('{}\n'.format(repr(mean_shift.cluster_centers_)))
# array([[6.21142857, 2.89285714, 4.85285714, 1.67285714],
#        [5.01632653, 3.44081633, 1.46734694, 0.24285714]])

new_obs = np.array([
  [5.1, 3.2, 1.7, 1.9],
  [6.9, 3.2, 5.3, 2.2]])
# predict clusters
print('{}\n'.format(repr(mean_shift.predict(new_obs))))
# array([1, 0])
0d8f03b00d7660235b65daadc587eb1c79eb5d1d
<mask token>

<mask token>
mean_shift.fit(data)
print('{}\n'.format(repr(mean_shift.labels_)))
print('{}\n'.format(repr(mean_shift.cluster_centers_)))
<mask token>
print('{}\n'.format(repr(mean_shift.predict(new_obs))))

<mask token>
mean_shift = MeanShift()
mean_shift.fit(data)
print('{}\n'.format(repr(mean_shift.labels_)))
print('{}\n'.format(repr(mean_shift.cluster_centers_)))
new_obs = np.array([[5.1, 3.2, 1.7, 1.9], [6.9, 3.2, 5.3, 2.2]])
print('{}\n'.format(repr(mean_shift.predict(new_obs))))

from sklearn.cluster import MeanShift
import numpy as np
mean_shift = MeanShift()
mean_shift.fit(data)
print('{}\n'.format(repr(mean_shift.labels_)))
print('{}\n'.format(repr(mean_shift.cluster_centers_)))
new_obs = np.array([[5.1, 3.2, 1.7, 1.9], [6.9, 3.2, 5.3, 2.2]])
print('{}\n'.format(repr(mean_shift.predict(new_obs))))

from sklearn.cluster import MeanShift
import numpy as np

mean_shift = MeanShift()

# predefined data
mean_shift.fit(data)

# cluster assignments
print('{}\n'.format(repr(mean_shift.labels_)))
# array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
#        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
#        1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
#        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

# centroids
print('{}\n'.format(repr(mean_shift.cluster_centers_)))
# array([[6.21142857, 2.89285714, 4.85285714, 1.67285714],
#        [5.01632653, 3.44081633, 1.46734694, 0.24285714]])

new_obs = np.array([
  [5.1, 3.2, 1.7, 1.9],
  [6.9, 3.2, 5.3, 2.2]])
# predict clusters
print('{}\n'.format(repr(mean_shift.predict(new_obs))))
# array([1, 0])