最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - AttributeError: 'function' object has no attribute 'implicit' when trying to use SciPy

programmeradmin3浏览0评论

I am trying to fit data using scipy.odr in a Jupyter notebook, but I keep getting an AttributeError. The relevant code is below,

from scipy.odr import *

def linear(U_0, x):
    return U_0[0]*x + U_0[1]

linear_model = Model(linear)

quadratic_data = RealData(angle_squared, flattened_velocity, sx=angle_error_squared, sy=flattened_velocity_error)
cubic_data = RealData(angle_cubed, flattened_velocity, sx=angle_error_cubed, sy=flattened_velocity_error)

quadratic_odr = ODR(quadratic_data, linear, beta0=[1,0])
cubic_odr = ODR(cubic_data, linear, beat0=[1,0])

quadratic_output = quadratic_odr.run()
cubic_output = cubic_odr.run()

quadratic_output.pprint()

When I try and run my code, the error below returns:

AttributeError                            Traceback (most recent call last)
Cell In[25], line 13
     10 quadratic_data = RealData(angle_squared, flattened_velocity, sx=angle_error_squared, sy=flattened_velocity_error)
     11 cubic_data = RealData(angle_cubed, flattened_velocity, sx=angle_error_cubed, sy=flattened_velocity_error)
---> 13 quadratic_odr = ODR(quadratic_data, linear, beta0=[1,0])
     14 cubic_odr = ODR(cubic_data, linear, beat0=[1,0])
     16 quadratic_output = quadratic_odr.SO.run()

File ~/.local/lib/python3.12/site-packages/scipy/odr/_odrpack.py:789, in ODR.__init__(self, data, model, beta0, delta0, ifixb, ifixx, job, iprint, errfile, rptfile, ndigit, taufac, sstol, partol, maxit, stpb, stpd, sclb, scld, work, iwork, overwrite)
    785 self.iwork = _conv(iwork)
    787 self.output = None
--> 789 self._check()

File ~/.local/lib/python3.12/site-packages/scipy/odr/_odrpack.py:800, in ODR._check(self)
    798 if isinstance(self.data.y, np.ndarray):
    799     y_s = list(self.data.y.shape)
--> 800     if self.model.implicit:
    801         raise OdrError("an implicit model cannot use response data")
    802 else:
    803     # implicit model with q == self.data.y

AttributeError: 'function' object has no attribute 'implicit'

I have no idea how to begin fixing this, and from what I can tell this error comes from the module itself and not the code I've written. If anyone could give any insight that would be great, thanks!

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论