X-DataInitiative / tick

Module for statistical learning, with a particular emphasis on time-dependent modelling
https://x-datainitiative.github.io/tick/
BSD 3-Clause "New" or "Revised" License
484 stars 105 forks source link

Manual alter weights of GLM #471

Open skjerns opened 3 years ago

skjerns commented 3 years ago

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?

PhilipDeegan commented 3 years ago

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

Mbompr commented 3 years ago

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