def describe_cont_feature(feature):
print('\n*** Results for {} ***'.format(feature))
print(titanic.groupby('Survived')[feature].describe())
print(ttest(feature))
def ttest(feature):
survived = titanic[titanic['Survived']==1][feature]
not_survived = titanic[titanic['Survived']==0][feature]
tstat, pval = stats.ttest_ind(survived, not_survived, equal_var=False)
print('t-statistic: {:.1f}, p-value: {:.3}'.format(tstat, pval))
# Look at the distribution of each feature at each level of the target variable
for feature in ['Pclass', 'Age', 'SibSp', 'Parch', 'Fare']:
describe_cont_feature(feature)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter