<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rotich Kibet on Medium]]></title>
        <description><![CDATA[Stories by Rotich Kibet on Medium]]></description>
        <link>https://medium.com/@ndovu7730?source=rss-f7fb12e32d7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*oJNzUpmPAGQDRpfD</url>
            <title>Stories by Rotich Kibet on Medium</title>
            <link>https://medium.com/@ndovu7730?source=rss-f7fb12e32d7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 23:45:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ndovu7730/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Working with CNNs]]></title>
            <link>https://medium.com/@ndovu7730/working-with-cnns-b2388169f756?source=rss-f7fb12e32d7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2388169f756</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[convolutional-neural-net]]></category>
            <category><![CDATA[computer-vision]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Rotich Kibet]]></dc:creator>
            <pubDate>Fri, 07 Mar 2025 04:00:56 GMT</pubDate>
            <atom:updated>2025-03-07T04:00:56.449Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*IRQDE3wquGZXCv5BkZJc9w.png" /></figure><p>Convolutional Neural Networks (CNNs) are a type of neural network that utilizes convolution operations to extract features from data. They are primarily used in computer vision because they excel at feature extraction. I have worked with YOLOv8, which is a CNN, in a computer vision project, and here is my experience.</p><h4>How do CNNs work?</h4><p>Convolutional Neural Networks (CNNs) use filters to extract features from images. Some filters may focus on vertical lines, while others may concentrate on circular objects. By stacking layers of neural networks on top of each other, the initial layers extract low-level features, while the subsequent layers extract higher-level features from those low-level features.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/1*fWwahfRI7Zb4qAnEqkOqVw.png" /><figcaption>Here is an example of how a vertical filter works</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/794/1*EJUdXM6iFqwI80XVFY4i5Q.png" /><figcaption>The same image subjected to a horizontal filter (kernel)</figcaption></figure><p>In the first image, the vertical features are highlighted, while other areas are darkened. The horizontal filter operates in the same manner, but it focuses on horizontal features. This process is considered low-level; each layer in a Convolutional Neural Network (CNN) extracts increasingly complex features using various types of filters. The features extracted include edges, textures, and shapes.</p><h4>What is YOLO?</h4><p>YOLO stands for “You Only Look Once.” This name reflects the fact that YOLO divides an image into grids and processes it from top left to bottom right in a single pass, rather than scanning it multiple times like other convolutional neural networks (CNNs). This approach makes YOLO incredibly fast. It is preferred for its accuracy, quick inference, and versatility; it can be used for object detection, classification, and segmentation (classifying every pixel in an image). In my project, I used YOLOv8 (version 8).</p><h4>Application.</h4><p>I built a banana ripeness level detector using YOLOv8, which determines whether a banana is ripe or unripe. Since YOLOv8 is already trained for many computer vision applications, my task was to fine-tune it for the banana use case through a process called transfer learning. For training, I utilized the Roboflow banana ripeness classification dataset, which includes images of bananas categorized as unripe, ripe, overripe, and rotten. I conducted the training on Google Colab, as it requires a GPU for efficient processing.</p><p>One of the main challenges I faced was the lengthy training time required by the CNN. Additionally, if the training process were to halt unexpectedly, I would have to wait a day to retrain on Colab unless I opted to pay for computing credits. Overall, the training went well, and the model achieved an impressive accuracy of 98% on the testing dataset.</p><h4>Future Improvements &amp; Conclusion</h4><p>The model shows good accuracy on the testing dataset; however, it struggles with some real-world images. This issue arises because the model was trained on pictures of bananas with clear white backgrounds. As a result, it may make incorrect predictions when faced with different backgrounds or images containing multiple bananas. To address this, I will need to train the model on datasets that include images more representative of what it will encounter in real-world scenarios. Here are a few examples of the inferences I obtained.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/917/1*4HR06hpVEO7GkJ5gqt_T7w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/966/1*2utokSTHHCoSclkwzbNCLQ.png" /><figcaption>It gets these two right.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*KVwEVgQwG0j5xmtoA9-5Ow.png" /><figcaption>It gets it wrong here primarily because it was trained on images like image 1.</figcaption></figure><p>Overall, CNNs are very interesting in how they work. It&#39;s fascinating that computers can understand images just by extracting a few features.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2388169f756" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The basic unit of a neural network]]></title>
            <link>https://medium.com/@ndovu7730/the-basic-unit-of-a-neural-network-24d48e4c4932?source=rss-f7fb12e32d7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/24d48e4c4932</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Rotich Kibet]]></dc:creator>
            <pubDate>Sat, 08 Feb 2025 21:01:17 GMT</pubDate>
            <atom:updated>2025-02-08T21:01:17.738Z</atom:updated>
            <content:encoded><![CDATA[<p>A neural network is a fascinating piece of technology that enables deep learning, which powers AI and machine learning today. How it works is often a mystery, as we can’t easily interpret its decision-making process. At the core of a neural network is its most basic unit: the neuron or node. While not much magic happens at the individual neuron level, combining several neurons and applying various algorithms is where the true power of neural networks emerges.</p><h3>What makes up a neuron?</h3><p>A neuron receives inputs along with its weights and adds a bias term. It computes a weighted sum by multiplying each input by its corresponding weight and then adds the bias term to this sum.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/175/1*jnf0Vl-tK6FkBbGrXEbsKQ.png" /></figure><p>The result is passed through a non-linear function, such as a sigmoid function, which compresses all input values into the range of 0 to 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/212/1*8wKuDFyuWjnEgPFx64_uYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/424/1*ZiD5M_2o-L22BTYcIUK83Q.png" /></figure><p>This final outcome becomes the output of the neuron.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/357/1*5N_HuzOJ6WDKfiqgSnGnHQ.png" /></figure><p>here is a simple implementation with Python.</p><pre>import numpy as np<br><br>class Neuron:<br>    def __init__(self, weights, bias):<br>        &quot;&quot;&quot;<br>        Initialize a neuron with given weights and bias<br>        <br>        Args:<br>            weights (list): List of input weights<br>            bias (float): Bias term<br>        &quot;&quot;&quot;<br>        self.weights = np.array(weights)<br>        self.bias = bias<br>    <br>    def sigmoid(self, x):<br>        &quot;&quot;&quot;Sigmoid activation function&quot;&quot;&quot;<br>        return 1 / (1 + np.exp(-x))<br>    <br>    def compute(self, inputs):<br>        &quot;&quot;&quot;<br>        Compute neuron output<br>        <br>        Args:<br>            inputs (list): Input values<br>            <br>        Returns:<br>            float: Neuron&#39;s output<br>        &quot;&quot;&quot;<br>        # Calculate weighted sum and add bias<br>        weighted_sum = np.dot(inputs, self.weights) + self.bias<br>        # Apply activation function<br>        output = self.sigmoid(weighted_sum)<br>        return output<br><br># Example usage<br>weights = [0.5, 0.5]  <br>bias = -0.2          <br>inputs = [1, 0]      <br><br>neuron = Neuron(weights, bias)<br>output = neuron.compute(inputs)<br>print(f&quot;Neuron output: {output}&quot;)<br><br><br>#output<br>Neuron output: 0.574442516811659</pre><p>There are alternatives to activation functions, with the tanh function being preferred to the sigmoid function. It compresses input values into the range of -1 to 1. Another commonly used activation function is the rectified linear unit <strong>ReLU</strong>, which sets all negative values to 0 while leaving positive values unchanged.</p><h3>Conclusion</h3><p>Through this simple implementation, we can see how a single neuron processes information — taking inputs, applying weights, and producing an output through an activation function. However, the true power of neural networks emerges when these neurons work together in a learning system. During training, neural networks employ backpropagation, a method where the weights of neurons are systematically adjusted to minimize error in the network’s predictions. This process allows the network to “learn” from its mistakes and continuously improve its performance.</p><p>The beauty of neural networks lies in their simplicity at the individual level, yet their capability to solve complex problems when working together — much like the biological neurons that inspired their design.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24d48e4c4932" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How NLP Transforms Raw Emails into Machine Learning Features]]></title>
            <link>https://medium.com/@ndovu7730/how-nlp-transforms-raw-emails-into-machine-learning-features-cceb9df8eea5?source=rss-f7fb12e32d7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/cceb9df8eea5</guid>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[machine-learning-ai]]></category>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Rotich Kibet]]></dc:creator>
            <pubDate>Thu, 06 Feb 2025 05:30:42 GMT</pubDate>
            <atom:updated>2025-02-06T05:55:22.554Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/562/1*U0iW3MUjHQPPJhMRC_0ffg.jpeg" /></figure><p>When working with emails (natural language) in machine learning models, you quickly realize that traditional models, unlike deep learning models, don’t understand text at all — they only understand numbers. So, how do you classify emails using a traditional model? The answer lies in <strong>Natural Language Processing (NLP)</strong>, a set of techniques that convert text into formats that computers can understand. NLP is used in a variety of applications, from machine translation and sentiment analysis to virtual assistants, chatbots, information retrieval, and text summarization.</p><p>In this article, we’ll explore how NLP can transform raw email text into meaningful patterns that machines can learn from, using a project that classifies emails based on their importance. This project leverages the <strong>Enron Email Dataset</strong>, to demonstrate how raw emails can be processed, labelled, and transformed into machine-readable features for training a machine-learning model.</p><h3><strong>Email Priority Classification Using the Enron Dataset</strong></h3><p>The goal of this project is to classify emails as either <strong>high priority</strong> or <strong>normal priority</strong> based on their content and metadata. The Enron dataset is particularly interesting because it contains real-world emails from Enron employees, making it a rich source of natural language data. However, the dataset is not labelled, so I needed to manually label the emails based on certain criteria, such as the presence of priority keywords (e.g., “urgent,” “ASAP”) or the sender’s role (e.g., CEO, CFO).</p><p>Here’s how I approached the problem:</p><h4><strong>1. Text Processing: The Foundation of NLP</strong></h4><p>Before I can feed email text into a machine learning model, I need to preprocess it. Text preprocessing is a crucial step in any NLP project, as it ensures that the text is in a format that can be understood by traditional machine learning models. Here are the key steps I took:</p><p>· <strong>Lowercasing</strong><br> I converted all text to lowercase to ensure that the model treats words like “Urgent” and “urgent” as the same. This step helps in reducing the complexity of the text and ensures consistency.</p><p>· <strong>Tokenization</strong><br> Tokenization is the process of breaking down sentences into individual words or tokens. I used the<strong> NLTK library </strong>to tokenize the email text. This step is crucial because it breaks down the text into units that can be processed by the model. For example, the sentence “Please review the report ASAP” would be tokenized into `[“please”, “review”, “the”, “report”, “asap”]`.</p><p>· <strong>Removing Stop Words</strong><br> Stop words are common words like “the,” “is,” “and,” and “in” that don’t add much meaning to the sentence. I removed these words to ensure that the model focuses on the most important words in the text. This step also reduces the size of the dataset, making it easier for the model to learn meaningful patterns.</p><p>· <strong>Lemmatization</strong><br> Lemmatization is the process of reducing words to their base or root form. For example, “running” and “ran” are both mapped to “run.” I used lemmatization instead of stemming because lemmatization is more accurate. Stemming, which is rule-based, can sometimes lead to errors (e.g., “studies” might be reduced to “studi”). Lemmatization, on the other hand, uses a dictionary to ensure that words are reduced to their correct base forms.</p><h4><strong>2. Feature Extraction: Turning Text into Numbers</strong></h4><p>Once the text is preprocessed, the next step is to convert it into a format that machine learning models can understand. This is where feature extraction comes in. In the project, I used two main types of features:</p><p>· <strong>TF-IDF Vectorization</strong><br> TF-IDF stands for <strong>Term Frequency-Inverse Document Frequency</strong>. It’s a statistical measure that evaluates how important a word is to a document in a collection of documents. Words that are common across many documents (like “the” or “is”) are assigned a lower importance, while words that are unique to a specific document (like “urgent” or “ASAP”) are assigned a higher importance. I used the <strong>TF-IDF vectorizer</strong> from the <em>sklearn</em> library to convert the email text into numerical features.</p><p>· <strong>Metadata Features</strong><br> In addition to the text content, I also extracted metadata features from the emails, such as:<br> — <strong>Subject length</strong>: The number of characters in the email subject.<br> <strong>— Message length</strong>: The number of characters in the email body.<br> — <strong>Sender hierarchy</strong>: Whether the sender is an executive (e.g., CEO, CFO, VP).<br> — <strong>Presence of a date</strong>: Whether the email contains a date in the header.</p><p>These metadata features provide additional context that can help the model make better predictions. For example, an email from a CEO might be more likely to be high priority, regardless of its content.</p><h4><strong>3. Model Training: Random Forest Classifier</strong></h4><p>With the features extracted, I trained a Random Forest Classifier to classify the emails as high priority or normal priority. Random Forest is a traditional machine learning model that works well with structured data, making it a good choice for this project.</p><p>I split the dataset into training and testing sets, extracted the features using my preprocessing pipeline, and trained the model. The model achieved a good performance, with a high accuracy rate in classifying emails based on their importance.</p><h4><strong>4. Testing the Model: Real-World Predictions</strong></h4><p>To test the model, I created a set of test emails, ranging from urgent messages from executives to casual team updates. I preprocessed these emails using the same pipeline, extracted the features, and fed them into the model for prediction. The model successfully classified the emails based on their content and metadata, demonstrating the effectiveness of the NLP pipeline.</p><h3><strong>Key Takeaways from the Project</strong></h3><p>This project highlights the power of NLP in transforming raw, unstructured text into meaningful features that can be used by traditional machine learning models. Here are some key takeaways:</p><p>1. <strong>Text Preprocessing is Crucial</strong>: Lowercasing, tokenization, stop word removal, and lemmatization are essential steps in preparing text data for machine learning. These steps ensure that the text is clean and consistent, making it easier for the model to learn patterns.</p><p>2. <strong>Combine Text and Metadata Features</strong>: While text content is important, metadata features like sender hierarchy, subject length, and message length can provide additional context that improves the model’s performance.</p><p>3. <strong>Feature Engineering is Key</strong>: Feature extraction techniques like TF-IDF vectorization are essential for converting text into numerical features that machine learning models can understand.</p><p>4. <strong>Domain Knowledge Matters</strong>: Understanding the domain (in this case, email communication) is crucial for designing effective NLP pipelines. For example, knowing that emails from executives are more likely to be high priority helped us create better features.</p><p>5. <strong>Model Interpretability</strong>: It’s important to understand why the model makes certain predictions. In my case, I could trace the model’s decisions back to the presence of certain keywords or metadata features.</p><h3><strong>Conclusion: NLP as the Bridge Between Human Communication and Machine Understanding</strong></h3><p>Natural Language Processing is more than just a set of techniques — it’s the bridge between human communication and machine understanding. In this project, we’ve seen how raw email text can be transformed into meaningful patterns that machines can learn from. The journey from unstructured email content to structured features involves careful consideration at each step: from basic preprocessing like tokenization and lemmatization to more sophisticated feature extraction using TF-IDF and metadata analysis.</p><p>What makes NLP particularly fascinating is its ability to capture the nuances of human communication. While my example focused on email classification, these same techniques form the foundation for everything from sentiment analysis to chatbots and language translation. The key lies not just in processing the text, but in understanding how to preserve and extract meaningful information at each step.</p><p>By combining NLP techniques with domain knowledge, we can build powerful machine learning models that can understand and interpret human language, opening up a world of possibilities for automation and decision-making.</p><p>· <strong>Key Takeaways</strong>:<br> — Start with thorough text preprocessing — it’s the foundation of any successful NLP project.<br> — Combine multiple types of features when possible (text content, metadata, etc.).<br> — Understand your domain and adapt your NLP pipeline accordingly.<br> — Keep an eye on model interpretability — understand why your model makes certain decisions.<br> — Stay curious and keep learning.</p><p>Here’s the link to my project repository: <a href="https://github.com/Kibet-Rotich/Data-analysis-ML-AI/blob/master/Enron_Email_dataset.ipynb">click here</a>. You can also check out my other projects on data analysis and machine learning <a href="https://github.com/Kibet-Rotich/Data-analysis-ML-AI">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cceb9df8eea5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Practical ML Classification Pipeline]]></title>
            <link>https://medium.com/@ndovu7730/a-practical-ml-classification-pipeline-f6c15698d4ea?source=rss-f7fb12e32d7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f6c15698d4ea</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[random-forest-classifiers]]></category>
            <dc:creator><![CDATA[Rotich Kibet]]></dc:creator>
            <pubDate>Fri, 31 Jan 2025 19:36:24 GMT</pubDate>
            <atom:updated>2025-01-31T20:07:17.566Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2sJ1XgLNDmtTNg1a-lgsgQ.png" /></figure><p>Hey everyone! AI is a hot topic right now, so I decided to learn more about it. It turns out that AI is a fascinating field. Machine Learning (ML) is a subset of AI, and I once heard a creator say, “All ML is AI, but not all AI is ML.” Essentially, ML allows a computer (machine) to learn from data in order to make future predictions.</p><p>ML is subdivided into two main categories: classification and regression. Classification involves predicting outcomes from a finite set of options, while regression predicts outcomes from an infinite set of values. For example, classification might classify input into discrete labels, like 1/0 or spam/not spam, whereas regression predicts a continuous value, such as a person’s credit score.</p><p>I’m going to guide you through a practical ML classification pipeline. We will train and use a model to predict whether an email is urgent or not. The steps involved are: collecting data, preprocessing it for the model, extracting features, training the model, saving the model, and then using it.</p><p>In this case, we will build a model that classifies emails as either urgent or not urgent. This use case can be helpful for sorting emails in your inbox into important and less important categories. Emails can be classified based on various features, such as the number of CC’d individuals, the number of recipients, the presence of exclamation marks, links, the sender, and the use of words like “ASAP,” among many others. For this example, we will focus solely on the message body.</p><h3>DATA COLLECTION</h3><p>For this particular case, I chose the SMS Spam Collection dataset because it is already classified into spam and ham (not spam). This means I won’t need to do much preprocessing. Additionally, the dataset is publicly available, and is easy to convert into a priority use case.</p><pre># Download dataset<br>!wget https://archive.ics.uci.edu/ml/machine-learning-databases/00228/smsspamcollection.zip<br>!unzip smsspamcollection.zip<br><br># Import libraries<br>import pandas as pd<br>import numpy as np<br>from sklearn.model_selection import train_test_split<br>from sklearn.feature_extraction.text import TfidfVectorizer<br>from sklearn.preprocessing import LabelEncoder<br><br># Load dataset<br>df = pd.read_csv(&#39;SMSSpamCollection&#39;, sep=&#39;\t&#39;, header=None, names=[&#39;label&#39;, &#39;text&#39;])<br>df.head() #A peek of the data just to understand it</pre><pre># Convert spam/ham to priority levels<br>def convert_to_priority(label):<br>    if label == &#39;spam&#39;:<br>    return &#39;Urgent&#39;<br>    else:<br>return &#39;Regular&#39;<br><br>df[&#39;priority&#39;] = df[&#39;label&#39;].apply(convert_to_priority)<br><br># Basic preprocessing<br>def clean_text(text):<br>    # Convert to lowercase<br>    text = text.lower()<br>    # Remove special characters<br>    text = &#39;&#39;.join([char for char in text if char.isalnum() or char.isspace()])<br>return text<br><br>df[&#39;cleaned_text&#39;] = df[&#39;text&#39;].apply(clean_text)<br><br># Display dataset info<br>print(&quot;Dataset Overview:&quot;)<br>print(df[&#39;priority&#39;].value_counts())<br>print(&quot;\nSample Data:&quot;)<br>print(df.head())<br># Save processed dataset<br>df.to_csv(&#39;processed_sms_data.csv&#39;, index=False)</pre><h3>Feature extraction</h3><p>Since text isn’t in a format that can be directly processed by a model, we need to extract features from our texts. Features are essentially the metrics used by the machine for classification. In this case, I utilized the TF-IDF feature extraction technique to convert the text into numerical values that the machine can understand. This method assigns higher importance to uncommon words, such as “technique,” and less importance to common words, like “is.” To understand exactly how TF-IDF works, you can refer to this link: <a href="https://www.geeksforgeeks.org/understanding-tf-idf-term-frequency-inverse-document-frequency/">TF-IDF</a>.</p><pre># Feature extraction using TF-IDF<br>vectorizer = TfidfVectorizer(max_features=5000)<br>X = vectorizer.fit_transform(df[&#39;cleaned_text&#39;])</pre><h3>Model Training</h3><p>For the model, I used a random forest classifier. A random forest classifier is a machine learning method that combines multiple decision trees to create a more accurate and robust model. For more information on random forests, please <a href="https://www.geeksforgeeks.org/random-forest-algorithm-in-machine-learning/">use this link</a>.</p><pre># Split the data<br>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<br><br># Train Random Forest Classifier<br>rf_classifier = RandomForestClassifier(n_estimators=100, random_state=42)<br>rf_classifier.fit(X_train, y_train)<br><br># Predictions and evaluation<br>y_pred = rf_classifier.predict(X_test)<br><br># Print classification report<br>print(&quot;Classification Report:&quot;)<br>print(classification_report(y_test, y_pred, target_names=le.classes_))</pre><h4>Save the model</h4><pre>import joblib<br>joblib.dump(rf_classifier, &#39;priority_classifier.joblib&#39;)<br>joblib.dump(vectorizer, &#39;tfidf_vectorizer.joblib&#39;)</pre><h4>Example use</h4><pre># Load model<br>rf_classifier = joblib.load(&#39;priority_classifier.joblib&#39;)<br>vectorizer = joblib.load(&#39;tfidf_vectorizer.joblib&#39;)<br><br>def predict_email_priority(email_text):<br>    cleaned_text = clean_text(email_text)<br>    vectorized_text = vectorizer.transform([cleaned_text])<br>    prediction = rf_classifier.predict(vectorized_text)<br>    return le.inverse_transform(prediction)[0]<br><br><br>predict_email_priority(&quot;Urgent meeting today, please respond ASAP&quot;)<br>#OUTPUT:Regular</pre><h3>Analysis of model</h3><p>If you followed this article closely, you might have noticed that this model functions similarly to a spam detector, but with the class labels changed from spam/ham to regular/urgent. I made this adjustment because that was the data I could easily obtain. This means that you cannot use it to sort your emails. However, since this is intended to be a guide, I assumed it would be sufficient. The model’s performance is good, as the random forest classifier is quite robust. Here is the <a href="https://github.com/Kibet-Rotich/Data-analysis-ML-AI/blob/master/Email_Priority_classifier.ipynb">Jupyter notebook</a>.</p><h3>Conclusion</h3><p>This is the basic process for machine learning classification. I plan to work on more complex projects in the future, and I’m considering using the Enron email dataset to build a model that will likely perform well on unseen data. The Enron email dataset contains additional features that will help with this. Thank you for following along!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f6c15698d4ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>