Open realamirhe opened 3 years ago
in LDA, we can refactor the predict method by NumPy built-ins to a more readable and performant version https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/linear_discriminant_analysis.py#L37-L43
is equal to this
def predict(self, X):
return np.array([1 * (x.dot(self._w) < 0) for x in X], dtype=np.int)
which can be implemented like this
def predict(self, X):
return np.where(X.dot(self._w) < 0, 1, 0)
First of all thanks for the great reference, you've been created and it performs well in its current format.
But, Is it acceptable to use covariance matrices instead of scatter matrices in LDA? shouldn't it use scatter matrices? https://github.com/eriklindernoren/ML-From-Scratch/blob/a2806c6732eee8d27762edd6d864e0c179d8e9e8/mlfromscratch/supervised_learning/linear_discriminant_analysis.py#L24-L25
As we know the relation between these two matrices is
scatter(X) = X.T.dot(X)
covariance(X) = X.T.dot(X) / N
for a given X orX = X - mean(X)
andN = |X|
reference