Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linear Discriminant Analysis #88

Open
realamirhe opened this issue Dec 27, 2020 · 1 comment
Open

Linear Discriminant Analysis #88

realamirhe opened this issue Dec 27, 2020 · 1 comment

Comments

@realamirhe
Copy link

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?

cov1 = calculate_covariance_matrix(X1)
cov2 = calculate_covariance_matrix(X2)

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 or X = X - mean(X) and N = |X|

reference

@realamirhe
Copy link
Author

realamirhe commented Dec 31, 2020

in LDA, we can refactor the predict method by NumPy built-ins to a more readable and performant version

def predict(self, X):
y_pred = []
for sample in X:
h = sample.dot(self.w)
y = 1 * (h < 0)
y_pred.append(y)
return y_pred

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant