Distribution of each feature at each level of the target variable, with ttest and P-value with continuous variable
Tue Mar 15 2022 10:43:24 GMT+0000 (Coordinated Universal Time)
Saved by
@abhin__dev
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)
content_copyCOPY
http://localhost:8888/notebooks/Desktop/Python/Ex_Files_Applied_ML/Ex_Files_Applied_ML/Exercise Files/03_Explore_Data/03_02/Begin/03_02.ipynb
Comments