我正在尝试构建一个从sklearn继承类的类
class my_lasso(linear_model.Lasso):
def __init__(self, alpha=1.0, fit_intercept=True, normalize=False,
precompute=False, copy_X=True, max_iter=1000, tol=1e-4,
warm_start=False, positive=False, random_state=None,
selection='cyclic'):
super(my_lasso, self).__init__(
alpha=alpha, fit_intercept=fit_intercept,
normalize=normalize, precompute=precompute, copy_X=copy_X,
max_iter=max_iter, tol=tol, warm_start=warm_start,
positive=positive, random_state=random_state,
selection=selection)
def fit(self, x, y):
super(my_lasso, self).fit(x, y)
self.x = x
self.y = y
self.residus = self.y - self.predict(self.x)
self.r2 = self.score(self.x, self.y)
self.error = np.linalg.norm(self.residus) ** 2
self.support = np.zeros(x.shape[1])
self.support[self.coef_ != 0] = 1
我不明白的是,当我测试我的课时,它会将属性intercept_
更改为数组
In [5]: testlasso.intercept_
Out[5]: array([ 23.44591837])
当我尝试从LinearRegression继承时。 我的coefs现在是双数组
In [7]: testls.coef_
Out[7]:
array([[-0.56194996, 0.80247616, -0.0150445 , -5.76399971, 0.23495704,
2.77166415]])
任何提示?
非常感谢!