June 2018
Intermediate to advanced
248 pages
5h 27m
English
In this section, we will cluster housing data with scikit-learn's k-means algorithm, as shown here:
from sklearn.cluster import KMeans from sklearn.datasets import load_boston boston = load_boston()# As previously, you have implemented the KMeans from scracth and in this example, you use sklearns API k_means = KMeans(n_clusters=3) # Training k_means.fit(boston.data)KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300, n_clusters=3, n_init=10, n_jobs=1, precompute_distances='auto', random_state=None, tol=0.0001, verbose=0)print(k_means.labels_)
The output of the preceding code is as follows:
[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 11 1 1 1 ...