7.12 kmeans example wine dataset

UNDER DEVELOPMENT 20211229 We can illustrate the application of K-Means to a new dataset. The sample dataset contains observations of the chemical analysis of wine. The dataset is available from the UCI Machine Learning repository.

First we download the data from the repository:

wget https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data -O wine.data
wget https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.names -O wine.names

The data is in csv format but without a header, and so some command line tools will help transform it. First we get the variable names from the names file.

egrep '^\s+[0-9][0-9]?)' wine.names |
  cut -d')' -f2 |
  tr 'A-Z' 'a-z' |
  awk '{printf("%s,", $1)}' |
  sed 's|,$||' |
  awk '{print}' > wine.header

Prepend that to the data file after removing the first column which is a wine class variable.

cut -d"," -f2- wine.data | cat wine.header - > wine.csv

The dataset is now in the right csv format:

$ head -4 wine.csv


Notice the scale of the different variables

Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0