explore.py
def explicit_ttest(df, alpha=0.05):
    '''
    This function takes in a DataFrame and an alpha value (default is .05)
    and prints off the Independent T-Test to compare mean popularity
    of explicit tracks versus non-explicit tracks.
    '''
    print('Set the alpha/significance level:')
    print('  alpha =', alpha)
    
    print('\n---\n')
    
    print('Check for normal distribution:')
    sns.distplot(df.popularity)
    plt.show()
    
    print('---\n')
    
    print('Check values counts:')
    print(df.explicit.value_counts())
    
    print('\n---\n')
    
    print('Compare variances:')
    explicit_sample = df[df.explicit==True].popularity
    not_explicit_sample = df[df.explicit==False].popularity
    
    # if [results of lavenes variance test], then equal_var = __ (automate checking similar variance)
    print(explicit_sample.var())
    print(not_explicit_sample.var())
          
    print("They are of relatively equal variance, so we will set the argument of equal_var to True. After the MVP this will be done with the Levene test instead of by hand.")
    
    print('\n---\n')
          
    print("Compute test statistic and probability (t-statistic & p-value)")
    t, p = stats.ttest_ind(explicit_sample, not_explicit_sample, equal_var = True)
    print('Test statistic:', t, '\np-value:', p/2, '\nalpha:', alpha)
    
    print('\n---\n')
    
    null_hypothesis = "there is no significant difference between the mean popularity of explicit tracks and non-explicit tracks."
    if p/2 < alpha:
        print("We reject the hypothesis that", null_hypothesis)
    else:
        print("We fail to reject the null hypothesis.")
        
    print('\n---\n')
          
    print('mean of non-explicit songs:', not_explicit_sample.mean(), '\nmean of explicit songs:', explicit_sample.mean())

    This function takes in a DataFrame and an alpha value (default is .05)
    and prints off the Independent T-Test to compare mean popularity
    of explicit tracks versus non-explicit tracks.
    
This function takes in a DataFrame and an alpha value (default is .05)
and prints off the Independent T-Test to compare mean popularity
of explicit tracks versus non-explicit tracks.
This function takes in a DataFrame and an alpha value ( default is . 05 ) and prints off the Independent T - Test to compare mean popularity of explicit tracks versus non - explicit tracks .
def explicit_ttest(df, alpha=0.05):
    print('Set the alpha/significance level:')
    print('  alpha =', alpha)
    print('\n---\n')
    print('Check for normal distribution:')
    sns.distplot(df.popularity)
    plt.show()
    print('---\n')
    print('Check values counts:')
    print(df.explicit.value_counts())
    print('\n---\n')
    print('Compare variances:')
    explicit_sample = df[df.explicit==True].popularity
    not_explicit_sample = df[df.explicit==False].popularity
    print(explicit_sample.var())
    print(not_explicit_sample.var())
    print("They are of relatively equal variance, so we will set the argument of equal_var to True. After the MVP this will be done with the Levene test instead of by hand.")
    print('\n---\n')
    print("Compute test statistic and probability (t-statistic & p-value)")
    t, p = stats.ttest_ind(explicit_sample, not_explicit_sample, equal_var = True)
    print('Test statistic:', t, '\np-value:', p/2, '\nalpha:', alpha)
    print('\n---\n')
    null_hypothesis = "there is no significant difference between the mean popularity of explicit tracks and non-explicit tracks."
    if p/2 < alpha:
        print("We reject the hypothesis that", null_hypothesis)
    else:
        print("We fail to reject the null hypothesis.")
    print('\n---\n')
    print('mean of non-explicit songs:', not_explicit_sample.mean(), '\nmean of explicit songs:', explicit_sample.mean())
def explicit_ttest ( df , alpha = 0.05 ) : print ( 'Set the alpha/significance level:' ) print ( '  alpha =' , alpha ) print ( '\n---\n' ) print ( 'Check for normal distribution:' ) sns . distplot ( df . popularity ) plt . show ( ) print ( '---\n' ) print ( 'Check values counts:' ) print ( df . explicit . value_counts ( ) ) print ( '\n---\n' ) print ( 'Compare variances:' ) explicit_sample = df [ df . explicit == True ] . popularity not_explicit_sample = df [ df . explicit == False ] . popularity print ( explicit_sample . var ( ) ) print ( not_explicit_sample . var ( ) ) print ( "They are of relatively equal variance, so we will set the argument of equal_var to True. After the MVP this will be done with the Levene test instead of by hand." ) print ( '\n---\n' ) print ( "Compute test statistic and probability (t-statistic & p-value)" ) t , p = stats . ttest_ind ( explicit_sample , not_explicit_sample , equal_var = True ) print ( 'Test statistic:' , t , '\np-value:' , p / 2 , '\nalpha:' , alpha ) print ( '\n---\n' ) null_hypothesis = "there is no significant difference between the mean popularity of explicit tracks and non-explicit tracks." if p / 2 < alpha : print ( "We reject the hypothesis that" , null_hypothesis ) else : print ( "We fail to reject the null hypothesis." ) print ( '\n---\n' ) print ( 'mean of non-explicit songs:' , not_explicit_sample . mean ( ) , '\nmean of explicit songs:' , explicit_sample . mean ( ) )
This function takes in a DataFrame and an alpha value (default is .05)
and prints off the Independent T-Test to compare mean popularity
of explicit tracks versus non-explicit tracks.
This function takes in a DataFrame and an alpha value ( default is . 05 ) and prints off the Independent T - Test to compare mean popularity of explicit tracks versus non - explicit tracks .
'''
    This function takes in a DataFrame and an alpha value (default is .05)
    and prints off the Independent T-Test to compare mean popularity
    of explicit tracks versus non-explicit tracks.
    ''' # if [results of lavenes variance test], then equal_var = __ (automate checking similar variance)
df
alpha