我写了这段代码来计算大样本的模式和标准偏差:
import numpy as np import csv import scipy.stats as sp import math r=open('stats.txt', 'w') #file with results r.write('Data File'+'\t'+ 'Mode'+'\t'+'Std Dev'+'\n') f=open('data.ls', 'rb') #file with the data files for line in f: dataf=line.strip() data=csv.reader(open(dataf, 'rb')) data.next() data_list=[] datacol=[] data_list.extend(data) for rows in data_list: datacol.append(math.log10(float(rows[73]))) m=sp.mode(datacol) s=sp.std(datacol) r.write(dataf+'\t'+str(m)+'\t'+str(s)+'\n') del(datacol) del(data_list)哪个好用 - 我想! 然而,在我运行代码后,我的终端上出现了一条错误消息,我想知道是否有人可以告诉我这意味着什么?
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1328: DeprecationWarning: scipy.stats.std is deprecated; please update your code to use numpy.std. Please note that: - numpy.std axis argument defaults to None, not 0 - numpy.std has a ddof argument to replace bias in a more general manner. scipy.stats.std(a, bias=True) can be replaced by numpy.std(x, axis=0, ddof=0), scipy.stats.std(a, bias=False) by numpy.std(x, axis=0, ddof=1). ddof=1).""", DeprecationWarning) /usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1304: DeprecationWarning: scipy.stats.var is deprecated; please update your code to use numpy.var. Please note that: - numpy.var axis argument defaults to None, not 0 - numpy.var has a ddof argument to replace bias in a more general manner. scipy.stats.var(a, bias=True) can be replaced by numpy.var(x, axis=0, ddof=0), scipy.stats.var(a, bias=False) by var(x, axis=0, ddof=1). ddof=1).""", DeprecationWarning) /usr/lib/python2.6/dist-packages/scipy/stats/stats.py:420: DeprecationWarning: scipy.stats.mean is deprecated; please update your code to use numpy.mean. Please note that: - numpy.mean axis argument defaults to None, not 0 - numpy.mean has a ddof argument to replace bias in a more general manner. scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x, axis=0, ddof=1). axis=0, ddof=1).""", DeprecationWarning)I wrote this code to calculate the mode and standard deviation for a large sample:
import numpy as np import csv import scipy.stats as sp import math r=open('stats.txt', 'w') #file with results r.write('Data File'+'\t'+ 'Mode'+'\t'+'Std Dev'+'\n') f=open('data.ls', 'rb') #file with the data files for line in f: dataf=line.strip() data=csv.reader(open(dataf, 'rb')) data.next() data_list=[] datacol=[] data_list.extend(data) for rows in data_list: datacol.append(math.log10(float(rows[73]))) m=sp.mode(datacol) s=sp.std(datacol) r.write(dataf+'\t'+str(m)+'\t'+str(s)+'\n') del(datacol) del(data_list)Which is working well -I think! However after I run the code there is an error message on my terminal and I am wondering if anybody can tell me what it means?
/usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1328: DeprecationWarning: scipy.stats.std is deprecated; please update your code to use numpy.std. Please note that: - numpy.std axis argument defaults to None, not 0 - numpy.std has a ddof argument to replace bias in a more general manner. scipy.stats.std(a, bias=True) can be replaced by numpy.std(x, axis=0, ddof=0), scipy.stats.std(a, bias=False) by numpy.std(x, axis=0, ddof=1). ddof=1).""", DeprecationWarning) /usr/lib/python2.6/dist-packages/scipy/stats/stats.py:1304: DeprecationWarning: scipy.stats.var is deprecated; please update your code to use numpy.var. Please note that: - numpy.var axis argument defaults to None, not 0 - numpy.var has a ddof argument to replace bias in a more general manner. scipy.stats.var(a, bias=True) can be replaced by numpy.var(x, axis=0, ddof=0), scipy.stats.var(a, bias=False) by var(x, axis=0, ddof=1). ddof=1).""", DeprecationWarning) /usr/lib/python2.6/dist-packages/scipy/stats/stats.py:420: DeprecationWarning: scipy.stats.mean is deprecated; please update your code to use numpy.mean. Please note that: - numpy.mean axis argument defaults to None, not 0 - numpy.mean has a ddof argument to replace bias in a more general manner. scipy.stats.mean(a, bias=True) can be replaced by numpy.mean(x, axis=0, ddof=1). axis=0, ddof=1).""", DeprecationWarning)最满意答案
这些是弃用警告 ,通常意味着您的代码可以正常工作,但可能会在将来的版本中停止工作。
目前你有这一行s=sp.std(datacol) 。 看起来警告建议使用numpy.std()而不是scipy.stats.std()此更改可能会使此警告消失。
如果您不关心弃用警告并希望按原样使用代码,则可以使用警告模块对其进行抑制。 例如,如果你有一个生成DeprecationWarning的函数fxn() ,你可以像这样包装它:
with warnings.catch_warnings(): warnings.simplefilter("ignore") fxn() #this function generates DeprecationWarningsThose are deprecation warnings, which usually mean that your code will work, but may stop working in a future release.
Currently you have this line s=sp.std(datacol). It looks like the warning suggests using numpy.std() instead of scipy.stats.std() Making this change could make this warning go away.
If you don't care about the deprecation warning and want to use your code as is, you can suppress it with the warnings module. For example, if you have a function fxn() that generates a DeprecationWarning, you can wrap it like this:
with warnings.catch_warnings(): warnings.simplefilter("ignore") fxn() #this function generates DeprecationWarnings更多推荐
发布评论