【问题标题】:Warning using Scipy with Pandas在 Pandas 中使用 Scipy 发出警告
【发布时间】:2017-09-18 14:02:52
【问题描述】:

我正在使用 Python 2.7 来测试以下示例:

# importando pandas, numpy y matplotlib
import matplotlib as matplotlib
import scipy as scipy
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

# importando los datasets de sklearn
from sklearn import datasets

boston = datasets.load_boston()
boston_df = pd.DataFrame(boston.data, columns=boston.feature_names)
boston_df['TARGET'] = boston.target
boston_df.head() # estructura de nuestro dataset.

from sklearn.linear_model import LinearRegression

rl = LinearRegression() # Creando el modelo.
rl.fit(boston.data, boston.target) # ajustando el modelo
list(zip(boston.feature_names, rl.coef_))

# haciendo las predicciones
predicciones = rl.predict(boston.data)
predicciones_df = pd.DataFrame(predicciones, columns=['Pred'])
predicciones_df.head() # predicciones de las primeras 5 lineas


np.mean(boston.target - predicciones)

但反应是:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/scipy/linalg/basic.py:1018: RuntimeWarning: internal gelsd driver lwork query error, required iwork 尺寸未返回。这可能是 LAPACK 错误的结果 0038,在 LAPACK 3.2.2(2010 年 7 月 21 日发布)中修复。回落到 'gels' 司机。 warnings.warn(mesg, RuntimeWarning)

我使用 Brew 和 PIP 来安装 Scipy。

我该如何解决?

【问题讨论】:

    标签: python python-2.7 pandas numpy scipy


    【解决方案1】:

    这是无害的,可以忽略。

    警告的原因就是它所说的:macOS 上的默认 LAPACK 有点旧,SciPy 可以解决它存在的错误。

    【讨论】:

    • 虽然这个答案或多或少是正确的,但它引发了几个明显的后续问题:SciPy 回退到“gelss”驱动程序是否有任何缺点(例如性能较差,也许)?有没有办法通过升级 LAPACK 来实际解决警告中描述的问题(而不是仅仅将其静音为suggested below)?如果这两个问题的答案都是“是”(我不知道是不是这样),那么这个答案可能不是最佳方法,我们应该升级 LAPACK。
    • FWIW,自从我在上面发表评论以来,我已经非常努力地以 SciPy 将在编译期间实际检测和使用的方式安装更新版本的 LAPACK,但失败了。未来的读者,除非你有一些我缺乏的深刻智慧,否则我建议你不要浪费你的努力,而只是忽略警告(如果它打扰你,就把它过滤掉)。如果你确实有一些我缺乏的深刻智慧,那么请赐教我们!
    • 嗯,我想从 pypi 轮子安装就足够了。
    • 当前 SciPy 不会使用应该已经可用的更新的 LAPACK。因此,除非 SciPy 切换到 LAPACK 的当前版本,或者 LAPACK 开发人员将错误修复移植回旧版本,否则警告将会出现。 github.com/scipy/scipy/issues/5998
    • 最新的 LAPACK 肯定不是,较新的 LAPACK,特别是 3.4.0,是的。
    【解决方案2】:

    试试下面的代码来解决这个问题:

    import warnings
    
    warnings.filterwarnings(action="ignore", module="scipy", message="^internal gelsd")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-12
      • 1970-01-01
      • 1970-01-01
      • 2016-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      相关资源
      最近更新 更多