# Can machine learning find a set of ages that has best survival chance? Titanic

I'm new to machine learning, and I have gone through a bunch of tutorials on youtube, but I'm still having some trouble understanding the limitations of machine learning as well as how to apply them beyond the simple examples given in tutorials.

I"m playing around with the titanic data using scikit learn and seaborn.

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt

titanic = sns.load_dataset("titanic")
df =titanic[['age','survived']]
df['age']= df.fillna(df.age.mean())  #filling NA values with mean

g= sns.FacetGrid(titanic, col ='survived', size = 3, aspect = 2)
g.map(plt.hist, 'age', color = 'r'), plt.show()
plt.show()


So just looking at the chart it seems children less than around 10 or so seem to have a much higher chance of survival than those older. 10-20 age range doesn't look as bad as those in the 20+ range. So I'm guessing those in the age range 0-17 have a much higher chance of surviving than those older. If I do a little bit of data exploring with pandas etc, I think I would be able to find a range of ages that has much higher chance of living than their counterparts regardless of the other features. Thus allowing me to label some as group 1 (belonging to an age range that has survival privileges) and group 2 who has no such privileges.

Would machine learning be able calculate such a range as an output if the input is df.age and df.survived? Would I have to manually divide up the age ranges on my own and transform them into [0,1,2] each number representing a different age group. Or can a machine learning algorithm some how do this classification on their own.

I was thinking of playing around with the Random Forest classifier, but I guess I just want to make sure what I"m trying do is somewhat possible.

I'm sorry if my question is a little vague, as I'm still not fully understanding what exactly machine learning is capable of despite going through vast amount of tutorials.

## 1 Answer

Would machine learning be able calculate such a range as an output if the input is df.age and df.survived? ...can a machine learning algorithm some how do this classification on their own.

What you're asking about is a classic example of unsupervised learning and an application of clustering algorithms.

Essentially you're looking for an algorithm that can find data points that are similar to each other (those with high survival rate) and at the same time dissimilar from others (those with low survival rate). A good place to start is k-means. As you'll read, the trick is finding the right number of clusters, k. In your example you have 3, but that's based on some analysis you did yourself. It's unclear if that's the "perfect" number of clusters. However there are ways to identify a good number of clusters vs. a bad number.