Skip to content

Commit

Permalink
[UPDATE] comments
Browse files Browse the repository at this point in the history
  • Loading branch information
vmspereira committed Sep 21, 2023
1 parent 284a598 commit f5a5508
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/si/supervised/linreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def fit(self, dataset):
self.is_fitted = True

def train_closed(self, X, y):
""" Uses closed form linear algebra to fit the model. Prefered to GD.
""" Uses closed form linear algebra to fit the model.
Prefered to GD when some assumptions are met.
theta = inv(XT*X)*XT*y
-----------------------------------------------------------------
Expand Down Expand Up @@ -90,7 +91,15 @@ def train_closed(self, X, y):
in the derivative resulting from adding the L2 regulation term.
Note that the matrix is not an identity matrix as the first entry is 0.
The regulatization is not applied to the intersect (bias) term.
You may, as exercice, derive the closed form.
You may, as exercice, derive the closed form.
The closed form computation of weight can not be applyied in certain cases, such as,
when the det(XT X) is zero or when the number of data points is not large enought.
Indeed, it can be demonstrated that when P >> N (The Curse of dimentionality), the
inv(XT X) ~ 1/det(XT X) -> inf
where P is the number of feature and N the number of data points.
"""
if self.lbd>0:
n = X.shape[1]
Expand Down

0 comments on commit f5a5508

Please sign in to comment.