tick icon indicating copy to clipboard operation
tick copied to clipboard

Manual alter weights of GLM

Open skjerns opened this issue 3 years ago • 2 comments

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?

skjerns avatar Feb 08 '21 10:02 skjerns

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

PhilipDeegan avatar Feb 08 '21 11:02 PhilipDeegan

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 :)

Mbompr avatar Feb 15 '21 09:02 Mbompr