Added Principal Component Analysis - #9610
Open
kausthub-kannan wants to merge 7 commits into
Open
Conversation
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
jhaji12
approved these changes
Oct 3, 2023
tianyizheng02
requested changes
Oct 26, 2023
tianyizheng02
left a comment
Contributor
There was a problem hiding this comment.
Small nitpicks, but otherwise LGTM
Comment on lines
+1
to
+14
| """ | ||
| Principal Component Analysis (PCA) is an unsupervised learning | ||
| algorithm that is used for the dimensionality reduction in machine | ||
| learning. It is a statistical procedure that uses an orthogonal | ||
| transformation to convert a set of observations of possibly correlated | ||
| variables into a set of values of linearly uncorrelated variables called | ||
| principal components. | ||
|
|
||
| Data: The data used for PCA is a set of 500 data points, each with 4 | ||
| features. The data is assumed to be in normal form. | ||
|
|
||
| Reference: https://en.wikipedia.org/wiki/Principal_component_analysis | ||
|
|
||
| """ |
Contributor
There was a problem hiding this comment.
Suggested change
| """ | |
| Principal Component Analysis (PCA) is an unsupervised learning | |
| algorithm that is used for the dimensionality reduction in machine | |
| learning. It is a statistical procedure that uses an orthogonal | |
| transformation to convert a set of observations of possibly correlated | |
| variables into a set of values of linearly uncorrelated variables called | |
| principal components. | |
| Data: The data used for PCA is a set of 500 data points, each with 4 | |
| features. The data is assumed to be in normal form. | |
| Reference: https://en.wikipedia.org/wiki/Principal_component_analysis | |
| """ | |
| """ | |
| Principal Component Analysis (PCA) is an unsupervised learning | |
| algorithm that is used for the dimensionality reduction in machine | |
| learning. It is a statistical procedure that uses an orthogonal | |
| transformation to convert a set of observations of possibly correlated | |
| variables into a set of values of linearly uncorrelated variables called | |
| principal components. | |
| Data: The data used for PCA is a set of 500 data points, each with 4 | |
| features. The data is assumed to be in normal form. | |
| Reference: https://en.wikipedia.org/wiki/Principal_component_analysis | |
| """ |
Comment on lines
+80
to
+81
| vector = vector - self.mean | ||
| return np.dot(vector, np.transpose(self.components)) |
Contributor
There was a problem hiding this comment.
Suggested change
| vector = vector - self.mean | |
| return np.dot(vector, np.transpose(self.components)) | |
| vector -= self.mean | |
| return np.dot(vector, np.transpose(self.components)) |
| >>> test_pca.fit(test_data) | ||
| """ | ||
| self.mean = np.mean(vector, axis=0) | ||
| vector = vector - self.mean |
Contributor
There was a problem hiding this comment.
Suggested change
| vector = vector - self.mean | |
| vector -= self.mean |
Comment on lines
+54
to
+60
| eigen_vector, eigen_value = np.linalg.eig(cov) | ||
| eigen_vector = eigen_vector.T | ||
|
|
||
| indexes = np.argsort(eigen_value)[::-1] | ||
| eigen_vector = eigen_vector[indexes] | ||
|
|
||
| self.components = eigen_vector[: self.n] |
Contributor
There was a problem hiding this comment.
Suggested change
| eigen_vector, eigen_value = np.linalg.eig(cov) | |
| eigen_vector = eigen_vector.T | |
| indexes = np.argsort(eigen_value)[::-1] | |
| eigen_vector = eigen_vector[indexes] | |
| self.components = eigen_vector[: self.n] | |
| eigenvector, eigenvalue = np.linalg.eig(cov) | |
| eigenvector = eigenvector.T | |
| indexes = np.argsort(eigenvalue)[::-1] | |
| eigenvector = eigenvector[indexes] | |
| self.components = eigenvector[:self.n] |
Nitpick: "eigenvector" and "eigenvalue" are each one word (no spaces)
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe your change:
Checklist: