python - 如何从代码中删除 RunTimeWarning 错误?

标签 python numpy linear-regression compiler-warnings spyder

当我在最底部运行回归代码时,我不断收到 RuntimeWarning。我不确定如何修复它们。我相信它可能是 attencoef 列表,因为其中有一些 nan 值。有什么建议么?

这些是我得到的错误:

C:\Users\MTM User\Anaconda3\lib\site-packages\scipy\stats\_stats_mstats_common.py:106: RuntimeWarning: invalid value encountered in double_scalars
  slope = r_num / ssxm
C:\Users\MTM User\Anaconda3\lib\site-packages\scipy\stats\_stats_mstats_common.py:116: RuntimeWarning: invalid value encountered in sqrt
  t = r * np.sqrt(df / ((1.0 - r + TINY)*(1.0 + r + TINY)))
C:\Users\MTM User\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py:879: RuntimeWarning: invalid value encountered in greater
  return (self.a < x) & (x < self.b)
C:\Users\MTM User\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py:879: RuntimeWarning: invalid value encountered in less
  return (self.a < x) & (x < self.b)
C:\Users\MTM User\Anaconda3\lib\site-packages\scipy\stats\_distn_infrastructure.py:1818: RuntimeWarning: invalid value encountered in less_equal
  cond2 = cond0 & (x <= self.a)
C:\Users\MTM User\Anaconda3\lib\site-packages\scipy\stats\_stats_mstats_common.py:118: RuntimeWarning: invalid value encountered in double_scalars
  sterrest = np.sqrt((1 - r**2) * ssym / ssxm / df)

代码:

for depthvalues in split_depth.values(): # only takes the values (separated lists), removes keys

    # takes into account the number of yows
    count+=1

    depthlst = depthvalues
    depthfirst = depthlst[0] #find my first depth or deepest depth
    depthlast = depthlst[-1] # find my last depth, or shallowest

    depthfirst_index = depth.index(depthfirst) #finds the index of my deepest depth for this segment in the filtered lists
    depthlast_index = depth.index(depthlast) #finds the index of my shallowest depth for this segment in the filtered lists

    irradlst = irrad[depthfirst_index:depthlast_index+1]

    irrad_first = irradlst[0] #finds the corresponding irradiance
    irrad_last = irradlst[-1] 
    irrad_last = float(irrad_last)

    irradlst = np.array(irradlst).astype(np.float)
    depthlst = np.array(depthlst).astype(np.float)

    attencoef = [np.log(i/irrad_last) for i in irradlst]

    #whenever I use this line of code(below) I get a bunch of errors
    regress = linregress(attencoef,depthlst) 

最佳答案

您应该过滤警告:

import warnings
warnings.filterwarnings("ignore", category=RuntimeWarning) 

类别 是您想要静音的警告类型。

关于python - 如何从代码中删除 RunTimeWarning 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44933518/

相关文章:

python - 如何在给定时间记录和保存用户可编辑的 Django 模型实例

python - 如何检查一个数字是否已经在二维 numpy 数组的第一列中

Python广播: how to unleash NumPy speed when filling in a One-Hot vector?

python - 我不断收到线性回归过程的错误 :"ValueError: Expected 2D array, got 1D array instead:"

javascript - 使用 mx + b 在 Highcharts 中绘制回归线

python - basemap 错误: module object is not callable

python - 日期与时间图上数据的颜色映射

python - 对与列表中的项目匹配的字典值执行操作?

Python - 使用 OpenCV 将字节图像转换为 NumPy 数组

python - 双对数图上的线性拟合不是线性的