nunosempere.github.io/maths-prog/MachineLearningDemystified
2019-10-12 20:02:42 +02:00
..
age_charge_smoking.png Add files via upload 2019-10-12 19:37:33 +02:00
AgglomerativeClustering-age.png Add files via upload 2019-10-12 19:37:33 +02:00
AlgorithmsClassification.py Create AlgorithmsClassification.py 2019-10-09 20:41:24 +02:00
AlgorithmsRegression.py Rename AlgorithmsRegression,py to AlgorithmsRegression.py 2019-10-12 19:00:14 +02:00
Birch-bmi.png Add files via upload 2019-10-12 19:37:33 +02:00
children-charge-smoking.png Add files via upload 2019-10-12 19:37:33 +02:00
CleaningUpData.py Create CleaningUpData.py 2019-10-09 20:40:56 +02:00
Clustering.py Create Clustering.py 2019-10-12 18:55:49 +02:00
GaussianMixture-age.png Add files via upload 2019-10-12 19:37:33 +02:00
GaussianMixture-smoker_numeric.png Add files via upload 2019-10-12 19:37:33 +02:00
KMeans-age.png Add files via upload 2019-10-12 20:01:08 +02:00
KMeans-bmi.png Add files via upload 2019-10-12 20:01:08 +02:00
KMeans-charges.png Add files via upload 2019-10-12 20:01:08 +02:00
KMeans-children.png Add files via upload 2019-10-12 20:01:08 +02:00
KMeans-cluster.png Add files via upload 2019-10-12 20:01:08 +02:00
KMeans-region_numeric.png Add files via upload 2019-10-12 20:01:08 +02:00
KMeans-sex_numeric.png Add files via upload 2019-10-12 20:01:08 +02:00
KMeans-smoker_numeric.png Add files via upload 2019-10-12 20:01:08 +02:00
MeanShift-age.png Add files via upload 2019-10-12 20:01:08 +02:00
readme.md Update readme.md 2019-10-12 20:02:42 +02:00

Machine Learning Demystified

Several friends encouraged me to apply to a Data Scientist position at ID Insights, an organization I greatly admire, and for a position which I would be passionate about. Before doing so, I familiarized myself throrougly with numpy, pandas and sklearn, three of the most important libraries for machine learning in Python.

I used a dataset from Kaggle: Health Care Cost Analysis, referenced as "insurance.csv" thoughout the code. The reader will also have to change the variable "directory" to fit their needs.

Otherwise, the current files in this directory are:

  • CleaningUpData.py. I couldn't work with the dataset directly, so I tweaked it somewhat.
  • AlgorithmsClassification.py. As a first exercise, I try to predict whether the medical bills of a particular individual are higher than the mean of the dataset. Some algorithms, like Naïve Bayes, are not really suitable for regression, but are great for predicting classes. After the first couple of examples, I wrapp everything in a function.
    • Algorithms: Naïve Bayes (Bernoulli & Gaussian), Nearest Neighbours, Support Vector Machines, Decision Trees, Random Forests (and Extrarandom forests), and multilayer perceptron (simple NN).
  • AlgorithmsRegression.py. I try to predict the healthcare costs of a particular individual, using all the features in the dataset.
    • Algorithms: Linear Regression, Lasso, Nearest Neighbours Regression, LinearSVR, SVR with different kernels, Tree regression, Random forest regression (and extra-random forest regression), and multilayer perceptron regression (simple NN).
  • Clustering.py. I then studied some of the most common clustering algorithms. The area seems almost pre-Aristotelian. Clustering algorithms get the task to send a message to Garcia, and they undertake the task, no questions asked. Heroically. I also take the opportunity here to create some visualizations, with the seaborn library.
    • Algorithms: KMeans, Affinity Propagation, Mean Shift, Spectral Clustering, Agglomerative Clustering, DBSCAN, Birch, Gaussian Mixture.

Thoughts on sklearn

The exercise proved highly, highly instructive, because sklearn is really easy to use, and the documentation is also extremely nice. The following captures my current state of mind:

It came as a surprise to me that understanding and implementing the algorithm were two completely different steps.

All KMeans plots produced by the code.

Three highlights.

The code produces the above visualizations for all algorithms. Here are three highlights.

  • Those who have 4+ children get charged less by insurance, and smoke less.

  • The disgreggation by age seems interesting, because there are three prongs, roughly: 1) normal people who don't smoke, 2) those who get charged more: made out of both smokers and nonsmokers, and 3) those who get charged a lot, which only comprises smokers. The Gaussian Mixture & K-Means algorithms do better than most others at discriminating between these threee groups, and made me realize the difference.

  • BMI is interesting, because there seems to be a line at BMI = 30, almost as if someone used that to make decisions about how much to charge, or what to diagnose. Normally, we'd expect something more continuous.