【问题标题】:'numpy.float64' object has no attribute 'ttest_ind'“numpy.float64”对象没有属性“ttest_ind”
【发布时间】:2021-09-20 14:00:13
【问题描述】:

我正在尝试使用以下内容进行 t 检验。它最初有效。但是,现在,它显示以下错误,

'numpy.float64' 对象没有属性 'ttest_ind'

col=list(somecolumns)
for i in col:
    x = np.array(data1[data1.LoanOnCard == 0][i]) 
    y = np.array(data1[data1.LoanOnCard == 1][i])
    t, p_value  = stats.ttest_ind(x,y, axis = 0,equal_var=False) 
    if p_value < 0.05:  # Setting our significance level at 5%
        print('Rejecting Null Hypothesis. Loan holders and non-Loan holders are not same for',i,'P value is %.2f' %p_value)
    else:
        print('Fail to Reject Null Hypothesis. Loan holders and non-Loan holders are  same for',i,'P value is %.2f' %p_value)

我正在努力寻找答案。无法解决。

【问题讨论】:

  • 不清楚这段代码中stats 是什么。你说它以前有效,你有没有机会创建一个名为stats的变量?

标签: pandas numpy data-science scipy.stats


【解决方案1】:

from scipy import stats 添加到您的代码中。

如果你已经这样做了,这意味着你很可能用另一个对象覆盖了stats。然后你可以使用import scipy.stats 并使用scipy.stats.ttest_ind 而不是stats.ttest_ind

【讨论】:

  • 正确。导入 Scipy.stats 并使用 scipy.stats.ttest_ind 工作。太感谢了。我可能已经写过你提到的统计数据。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-12-09
  • 1970-01-01
  • 1970-01-01
  • 2022-11-17
  • 1970-01-01
  • 2017-12-07
  • 1970-01-01
相关资源
最近更新 更多