【问题标题】:Conduct a Chi-square test to check the values independent or correlated进行卡方检验以检查独立或相关的值
【发布时间】:2021-05-17 13:22:40
【问题描述】:

全部 你能帮我如何检查食物的类型和条目的匿名性吗 使用卡方检验独立还是相关?我必须找到组列和制造商之间的相关性。问题在这里是 fgroup 和制造商列重新对象类型,我得到不同的错误:例如:

from scipy.stats import chisquare
chisquare(df['fgroup'], df['manufacurer  '])

错误:-: 'str' 和 'NoneType' 的操作数类型不受支持 数据在这里: 提前致谢:

【问题讨论】:

    标签: python pandas hypothesis-test


    【解决方案1】:

    最简单的方法最有可能首先将它们制成表格,使用pd.crosstab() 并使用chi2_contingency

    import pandas as pd
    from scipy.stats import chi2_contingency
    import numpy as np
    
    np.random.seed(111)
    df = pd.DataFrame({'fgroup':np.random.choice(['f1','f2','f3'],50),
                       'manufacturer':np.random.choice(['m1','m2'],50)})
    
    chisquare(pd.crosstab(df['fgroup'],df['manufacturer']))
    

    请参阅here 了解输出值的含义。

    【讨论】:

      猜你喜欢
      • 2020-10-12
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 1970-01-01
      • 2021-06-16
      • 1970-01-01
      相关资源
      最近更新 更多