如何解决RuntimeWarning:python中sqrt中遇到的值无效

时间:2017-06-18 23:15:38

标签: python mysql numpy scipy correlation

我试图让两个列表的pearson corrleation和它的作品相当不错,但我也得到了这个错误。

/usr/lib/python2.7/dist- packages/scipy/stats/_stats_mstats_common.py:93: RuntimeWarning: invalid  value encountered in sqrt
t = r * np.sqrt(df / ((1.0 - r + TINY)*(1.0 + r + TINY)))
/usr/lib/python2.7/dist-packages/scipy/stats/_stats_mstats_common.py:97: RuntimeWarning: invalid value encountered in sqrt
sterrest = np.sqrt((1 - r**2) * ssym / ssxm / df)

因此在结果中,我无法得到像这样的pvalue和stderr值。

LinregressResult(slope=0.99429193644763636, intercept=-0.12339201101613284,
rvalue=0.99998196438744391, pvalue=nan, stderr=nan)

我的代码如下

import csv
import datetime
import numpy as np
import pandas as pd
from collections import defaultdict
from datetime import datetime
import mysql.connector
from mysql.connector import errorcode
from scipy.stats import pearsonr
from scipy.stats import linregress

# for temp
dat1 = []
cnx = mysql.connector.connect(user='roby', password='xxxx', database='rob')
cursor = cnx.cursor()
cursor.execute('select  usec ,`temp.tab.1` \
           from robin_tab1 WHERE usec >= 1469833200000000 \
           AND usec <= 1469916000000000') 
rows = cursor.fetchall()
rows_arr = np.array(rows)
dat1.append([i[1] for i in rows_arr])


# for pressure
dat2 = []
cnx = mysql.connector.connect(user='roby', password='xxxx', database='rob')
cursor = cnx.cursor()
cursor.execute('select  usec ,`pres.tab1` \
           from robin_tab2 WHERE usec >= 1469833200000000 \
           AND usec <= 1469916000000000')
rows = cursor.fetchall()
rows_arr = np.array(rows)
dat2.append([i[1] for i in rows_arr])
print linregress(dat1, dat2)

dat1和dat2看起来像

dat1 . .[24.335809999999999, 24.194980000000001, 24.06935, 23.915240000000001,
         23.75497,...... 23.621960000000001, 23.578779999999998]

dat2 . .[24.088159999999998, 23.918780000000002, 23.817270000000001, 23.660900000000002,
         23.505980000000001. . . .. .  24.128170000000001, 24.098600000000001]

如果我在列表中有负数,有人可以帮助我或指导我如何删除此错误或处理它,因为我无法删除这些负数,因为它们是分析的一部分。 感谢

0 个答案:

没有答案