'LinearRegression' object has no attribute 'positive'
Hi,
I have got this error while running the code in the lecture, any advise?
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
tand
p 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,
n_jobs=1):
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
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.
I am getting the same error while running the code
AttributeError: 'LinearRegression' object has no attribute 'positive'
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?
You need to update the code from Fernando a bit to make it work (at least on my end):
# nothing changes in __init__
def __init__(self, fit_intercept=True, normalize=False, copy_X=True,
n_jobs=1):
super().__init__(fit_intercept=fit_intercept, 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