美文网首页大数据
Chi-square 用途3

Chi-square 用途3

作者: 不连续小姐 | 来源:发表于2018-10-25 10:48 被阅读0次

    Data Science Day 5:

    Chi-Square Application 2:

    Test Independence of Two categorical variables, or known asContingency Table.

    We use the Chi-Square test of Independence to check if two categorical variables are independent, or have a strong association.

    Example 1: Ice-cream Favor VS. Buyer's Gender

    We want to see if there is a preference for ice-cream favor based on the gender of people eating it

    [table id= 3 \]

    H0 (Null Hypothesis):The preference forIce-Cream FavorandBuyer'sGenderareIndependent, (There is no association between Ice-Cream Favor and Gender selection)

    Solution:

    we will useSciPypackage andchi2_contingencyfunction in Python.

    Python Code:

    favor_gender=np.array([[60,120,120,80],[120,250,200,50]])

    stats.chi2_contingency(favor_gender)

    Result:

    We see thep-value is 4.3e-08, which is significantly < 0.05. So weRejectthe Null Hypotheses and Conclude the Ice-Cream Favor is dependent on the buyer's Gender.Note:If if the totalcount is <5the result might be biased, and if it is2 x 2 table(2 categorical variables with 2 observations) we will proceed withFisher's ExactTest.

    Data Visualization:

    From the visualization, we can see the indeed there's more girls prefer Green Tea favor Ice-cream. :)

    Source Code:

    To be continue....

    相关文章

      网友评论

        本文标题:Chi-square 用途3

        本文链接:https://www.haomeiwen.com/subject/idsqtqtx.html