[Python] AttributeError: 'function' object has no attribute 'implicit' when trying to use...

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    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!

    Continue reading...

Compartilhe esta Página