According to the answer to this post, it is recommended to use one-way anova to compute the dependence between a categorical and a numerical variable.

Besides, the second answer to this post says that:

The most classic "correlation" measure between a nominal and an interval ("numeric") variable is Eta, also called correlation ratio, and equal to the root R-square of the one-way ANOVA (with p-value = that of the ANOVA).

I would appreciate if you could let me know:

  1. how the correlation ratio is computed using one-way anova?
  2. why this kernel in the following code used np.log(1./anova['p']) when it intends to plot the correlation between a categorical and a numeric feature using one-way anova?

The code:

for cat in cat_features:
    group_prices = []
    for group in train[cat].unique():
        group_prices.append(train[train[cat] == group]['SalePrice'].values)
    f, p = scipy.stats.f_oneway(*group_prices)
anova = pd.DataFrame(anova)
anova = anova[['feature','f','p']]
anova.sort_values('p', inplace=True)
# Plot
sns.barplot(anova.feature, np.log(1./anova['p']))

Thanks in advance.

  • $\begingroup$ Hi! about the second question I don't know unfortunately but as the response to the first question, have you seen here? $\endgroup$ – Media Jul 8 '18 at 13:11
  • 1
    $\begingroup$ Eta squared = SSbetween-groups / SStotal. (where SSbetween-groups = SStotal - SSwithin-groups). $\endgroup$ – ttnphns Jul 8 '18 at 15:17
  • $\begingroup$ @ttnphns Thanks a lot. Could you please let me know if the above one-way anova code are more informative to show the dependence between categorical and numerical variables or the following correlation ratio code:? towardsdatascience.com/… $\endgroup$ – ebrahimi Jul 8 '18 at 17:46
  • $\begingroup$ The kernel claims that: we took the log of the inverse of the p-value (np.log(1./anova['p']): the inverse so that when we take the log we get positive numbers, and log so that we don't just see a single bar. In other words, the p-value is a magnitude of about 300 times smaller than the next feature! $\endgroup$ – ebrahimi Jul 8 '18 at 17:55
  • $\begingroup$ @Media based on the above quotation, it seems that the kaggler just did it to be able to plot the p-value. $\endgroup$ – ebrahimi Jul 8 '18 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.