tick
tick copied to clipboard
Manual alter weights of GLM
I want to extract coefficients of a GLM, then alter them, and set them again as the weight matrix.
However, weights
is readonly.
data_x = np.random.rand(512, 300)
data_y = np.random.randint(0, 2, 512)
clf = LogisticRegression()
clf.fit(data_x, data_y)
clf.weights *= 3.14
# AttributeError: weights is readonly in LogisticRegression
Is there any way to manually set weights to a GLM?
you can set them like this if you want to https://github.com/X-DataInitiative/tick/blob/master/tick/base/learner/learner_glm.py#L206
Indeed, these weights are supposed to be read-only. If you want to set this attribute manually, you can run clf._set("weights", clf.weights * 3.14)
. But do it at your own risks :)