Last answered:

30 Mar 2022

Posted on:

20 Jun 2021


'LinearRegression' object has no attribute 'positive'


I have got this error while running the code in the lecture, any advise?


4 answers ( 0 marked as helpful)
Posted on:

30 Jun 2021


I have faced the same issue, but in my case it was when I created a derived class from LinearRegression that contained some extra functionality to calculate the p-value.
The missing part is initializing the base class during the initialization of the derived class, as I suspect the attribute "positive" has been added in a newer version.

I have added:
super().__init__(fit_intercept=fit_intercept, normalize=normalize, copy_X=copy_X, n_jobs=n_jobs)

Here full code:

class LinearRegression(linear_model.LinearRegression):
    LinearRegression class after sklearn's, but calculate t-statistics
    and p-values for model coefficients (betas).
    Additional attributes available after .fit()
    are tandp which are of the shape (y.shape[1], X.shape[1])
    which is (n_features, n_coefs)
    This class sets the intercept to 0 by default, since usually we include it
    in X.

    # nothing changes in __init__
    def __init__(self, fit_intercept=True, normalize=False, copy_X=True,
        super().__init__(fit_intercept=fit_intercept, normalize=normalize, copy_X=copy_X, n_jobs=n_jobs)
        self.fit_intercept = fit_intercept
        self.normalize = normalize
        self.copy_X = copy_X
        self.n_jobs = n_jobs

Posted on:

09 Sept 2021


Following Fernando's answer, I solved the issue, adding 'positive' attribute:

super().__init__(fit_intercept=fit_intercept, normalize=normalize, copy_X=copy_X, n_jobs=n_jobs, positive=False)
self.positive = positive

'positive' = True, forces coefficient to be positive.

Posted on:

30 Mar 2022


I am getting the same error while running the code

AttributeError: 'LinearRegression' object has no attribute 'positive'
Posted on:

30 Mar 2022


Please also what is this positive attribute all about.
I also want to understand the concept behind the p-value class method.
What is the linear Algebra behind the logistic regression function?

Submit an answer