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.
@sumanth_077
-
Wrapping up daily Python, ML, MLOps and LLMs content sharing
By
–
-

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.
-

Calculating Class Probability in Training Data Loop
By
–
Now loop over each class. And from "X" subset the features corresponding to the current class "c". Using that calculate the probability of that class "c" occurring in the training data. This is calculated by: (Total No of times class "c" occurred)/Total No of classes
-

Defining the Naive Bayes Classifier Fit Method for Training
By
–
Define the fit method to train the Naive Bayes classifier. • Here "X" is the feature matrix that contains the data samples • "y" contains the class labels corresponding to each data sample. Also get the unique class labels and store them in "self.classes".
-

Initializing Class Prior Probabilities and Feature Probabilities Parameters
By
–
Similarly initialise: → class_prior_probs: This stores the probabilities of an individual classes → feature_probs: This stores the feature probabilities or conditional probability. More on these 2 parameters later:
-

Naive Bayes: Independence Assumption and Parameter Initialization
By
–
There reason why it called "naive" is it assumes the features are independent to each other. First, Let's initialise the parameters: → alpha: Just remember this as a smoothing parameter. Will explain it's importance later. → classes: To store the unique class labels.
-
Python ML MLOps CV NLP LLMs Daily Tutorials
By
–
If you are interested in: – Python – Machine Learning – MLOps – CV/NLP – LLMs Find me → @Sumanth_077 Everyday, I share tutorials on above topics! Like/RT the first tweet to help this reach more people!