Now define the "fit" method that takes in that data and calculates the mean, normalizes the data, computes the covariance matrix, eigenvalues, and eigenvectors. Then the Eigenvectors are sorted based on eigenvalues. You may ask how, eigen vectors does dimensionality reduction?
@sumanth_077
-

PCA Class Implementation: Initializing Components and Eigenvectors
By
–
First Import numpy and define a class named "PCA" to encapsulate the operations. In the __init__ constructor let's initialize the number of components to reduce to, which is n_components, and similarly create placeholders for mean and eigenvectors.
-
Principal Component Analysis PCA Explained and Implemented from Scratch
By
–
Princiapal Component Analysis (PCA) clearly explained and implemented from scratch in Python:
-

CodeRabbit: AI-Powered Code Review Solution for Developers
By
–
Introducing CodeRabbit, The Future of AI-Powered Code Reviews! While the LLMs have significantly transformed code generation, the code review process still lags behind and remains stressful! Having efficient and effective code review processes is crucial! That's where
-
Wrapping up daily Python, ML, MLOps and LLMs content sharing
By
–
That's a wrap! Every day, I share and simply content around Python, Machine Learning, MLOps & LLMs. Find me →
@Sumanth_077 Like/RT the first tweet and help this reach more people. -

Implementing the Predict Method for Data Classification
By
–
Finally define the "predict" method to make the predictions on a set of data. For each data in "X" it runs the above "_predict_single" method and returns the class label.
-

_predict_single Method: Class Prediction Using Posterior Probability
By
–
_predict_single This method predicts the class label for a single instance. This is done by calculating posterior probability This is a conditional probability that we get after updating the previous probabilities. Now return the class label with the highest probability.
-

Calculate Feature Probabilities for Class C in Classification
By
–
Similarly calculate the probabilities of individual features for the current class "c". To simplify this is the probability of occurrence of that feature given that the class is c.
-

Alpha Parameter Prevents Zero Probability in Unseen Feature Data
By
–
Here you can see we have multiple by "alpha". For example if you have unseen feature data. Since it is unseen, the algorithm calculates it's probability as 0. By multiplying this with the probability the entire value is 0. To avoid this alpha is used whose default value is 1.
