Now you have understood the internal of k-means on a single variable, you can extend this implementation to multiple variables and apply it to a more realistic dataset.
The dataset to be used in this section is from the UCI Machine Learning Repository (https://archive.ics.uci.edu/ml/datasets/wholesale+customers), and it includes the client information of wholesales distributor. There 440 customers with eight features. In the following list, first six features are related to annual spending for corresponding products, seventh feature shows the channel that this product is bought and the eighth feature shows the region:
- FRESH
- MILK
- GROCERY
- FROZEN
- DETERGENTS_PAPER
- DELICATESSEN
- CHANNEL
- REGION
First download the dataset and read the it as a numpy array:
from numpy import genfromtxt
wholesales_data = genfromtxt('Wholesale customers data.csv', delimiter...