简体   繁体   English

scipy AttributeError,似乎无法修复

[英]scipy AttributeError, cant seem to fix it

I'm doing some statistics with t and z , z is working fine, but when I run with an AttributeError with t , specifically: AttributeError: 'float' object has no attribute 'sf' 我正在使用tz进行一些统计,但是z可以正常工作,但是当我使用AttributeErrort一起运行时,特别是: AttributeError: 'float' object has no attribute 'sf'

Now, this is the code that is giving me this error: 现在,这是给我这个错误的代码:

    if n >= 30: #i've tried with n being an int and float, error still
        z()
    else:
        gl = n - 1 
        t()

 t = ((xmuestral - mu) / (desv / (math.sqrt(n)))) #i've tried making this into int, error still
 p_value = t.sf(t, gl)

Of course, xmuestral , mu , desv and n are float to get an accurate result, and gl , no matter if Float or Integer gives me the same problem, now, if I try to convert everything into an Integer, now it simply throws AttributeError: 'int' object has no attribute 'sf' 当然, xmuestralmudesvn是float以获得准确的结果,而gl不管Float或Integer是否给我带来相同的问题,现在,如果我尝试将所有内容转换为Integer,现在它只会抛出AttributeError: 'int' object has no attribute 'sf'

honestly i'm stuck, i dont know how to make it work 老实说,我被卡住了,我不知道如何使它工作

t is a float, hence you can't call t.sf. t是浮点数,因此您不能调用t.sf。 Naming matters. 命名很重要。

>>> from scipy import stats
>>> import math
>>> mu = 5
>>> desv = 0.03
>>> n = 8
>>> xmuestral = 5.1
>>> s = ((xmuestral - mu) / (desv / (math.sqrt(n))))
>>> pval = stats.t.sf(s, n-1)
>>> pval
1.5749970000865015e-05

Remark: Also, it seems that you are using t as a function as well. 备注:另外,似乎您也正在使用t作为函数。 It might not be a good practice. 这可能不是一个好习惯。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法修复:AttributeError:startswith - Cant fix: AttributeError: startswith 我似乎无法在我的代码中修复这些错误 - I cant seem to fix these erros in my code 你如何解决这个问题 AttributeError: 'scipy' object (scipy) has no attribute 'misc'? - how u can fix this problem AttributeError: 'scipy' object (scipy) has no attribute 'misc'? 无法修复 Python 错误 AttributeError: 'int' object 没有属性 'get' - Cant fix Python error AttributeError: 'int' object has no attribute 'get' 我该如何解决这个我似乎找不到的缩进错误? - How can i fix this Indentation Error I cant seem to find? 我的乌龟代码有一个错误,我似乎无法解决 - My turtle code has an error i cant seem to fix at the end of it 'str' object 没有属性 'text'。 似乎无法修复它 - 'str' object has no attribute 'text'. Cant seem to be able to fix it 无法修复错误:create()接受1个位置参数,但给出了2个,似乎无法修复 - cant fix error: create() takes 1 positional argument but 2 were given and cant seem to fix it Python:TypeError:“ int”对象不可调用。 最有可能是一个简单的修复。 似乎无法解决该问题 - Python: TypeError: 'int' object is not callable. Most likely a easy fix. cant seem to fiture out how to fix it 无法通过 pip 安装 scipy - Cant install scipy through pip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM