-
-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Added Principal Component Analysis #9610
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nitpicks, but otherwise LGTM
""" | ||
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 | ||
|
||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
""" | |
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 | |
""" |
vector = vector - self.mean | ||
return np.dot(vector, np.transpose(self.components)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vector = vector - self.mean | |
vector -= self.mean |
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
Describe your change:
Checklist: