<?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 Mwangiboyle on Medium]]></title>
        <description><![CDATA[Stories by Mwangiboyle on Medium]]></description>
        <link>https://medium.com/@mwangiboyle4?source=rss-fcfc7715479a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*VAWAqUrRfeq8miMK</url>
            <title>Stories by Mwangiboyle on Medium</title>
            <link>https://medium.com/@mwangiboyle4?source=rss-fcfc7715479a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:49:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mwangiboyle4/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[Building an End-to-End Bank Customer Churn Prediction Pipeline (94% Accuracy)]]></title>
            <link>https://medium.com/@mwangiboyle4/building-an-end-to-end-bank-customer-churn-prediction-pipeline-94-accuracy-ae48a6c558a6?source=rss-fcfc7715479a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae48a6c558a6</guid>
            <category><![CDATA[machine-learning-python]]></category>
            <category><![CDATA[customer-churn]]></category>
            <category><![CDATA[random-forest-classifiers]]></category>
            <category><![CDATA[churn-prediction]]></category>
            <category><![CDATA[feature-engineering]]></category>
            <dc:creator><![CDATA[Mwangiboyle]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 11:20:28 GMT</pubDate>
            <atom:updated>2026-10-31T11:20:28.338Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*4ChODDEcv8aD_6Ln" /><figcaption>customer churn</figcaption></figure><p>Customer churn is one of the most critical metrics for financial institutions. Retaining existing customers is significantly more cost-effective than acquiring new ones. In this post, we will walk through the complete, end-to-end machine learning pipeline used to predict bank customer churn, moving from raw data preparation all the way to a high-performing ensemble model.</p><h3>Phase 1: Data Ingestion &amp; Automated Environment Setup</h3><p>To ensure a fully reproducible workflow, the project environment is configured to pull data directly from Kaggle using the Kaggle API.</p><ul><li><strong>Environment Configuration:</strong> The script initializes the required kaggle package and configures API credentials dynamically.</li><li><strong>Dataset Ingestion:</strong> The bank-customer-churn-dataset by Gaurav Topre is downloaded and extracted directly into the working directory.</li><li><strong>Data Loading:</strong> The primary CSV file, Bank Customer Churn Prediction.csv, is loaded into a Pandas DataFrame, containing 10,000 customer records spanning 12 distinct attributes (such as credit_score, country, gender, age, tenure, balance, and estimated_salary).</li></ul><h3>Phase 2: Data Integrity &amp; Exploratory Data Analysis (EDA)</h3><p>Before training any models, verifying data quality and understanding underlying distributions is vital.</p><ul><li><strong>Missing Value Check:</strong> Running .isnull().sum() confirmed a pristine dataset with <strong>zero missing values</strong> across all records.</li><li><strong>Data Types:</strong> Field types were verified (int64, float64, and categorical objects), ensuring numerical features were ready for scaling.</li><li><strong>Baseline Distribution &amp; Class Imbalance:</strong> Univariate analysis established a baseline churn rate of approximately <strong>20.37%</strong>. This mild class imbalance informed our later choice of evaluation metrics to avoid biased predictions.</li></ul><h3>Phase 3: Feature Engineering &amp; Preprocessing</h3><p>To maximize predictive power, raw attributes were transformed into high-value features suited for machine learning algorithms.</p><ul><li><strong>Categorical Encoding:</strong> Categorical variables such as country and gender were transformed using one-hot encoding so tree-based and linear models could process them effectively.</li><li><strong>Feature Scaling:</strong> Continuous variables like balance and estimated_salary were normalized using standard scaling techniques to ensure equal weighting across distance-based algorithms.</li><li><strong>Feature Selection:</strong> Highly correlated features and noisy identifiers (such as unique customer IDs) were dropped to prevent overfitting and reduce dimensionality.</li></ul><h3>Phase 4: Model Training &amp; Ensemble Optimization</h3><p>With a clean, engineered feature set, we trained several candidate classification models, including Random Forest, Gradient Boosting, and XGBoost.</p><ul><li><strong>Handling Imbalance:</strong> Techniques such as adjusting class weights were applied to ensure the model accurately captured minority-class churners rather than just predicting the majority class.</li><li><strong>Ensemble Strategy:</strong> By combining powerful gradient boosting frameworks with tuned hyperparameter grids via cross-validation, the final model achieved an impressive <strong>94% accuracy</strong> score alongside robust precision and recall metrics.</li></ul><p>Python</p><pre>from sklearn.ensemble import RandomForestClassifier<br>from sklearn.metrics import accuracy_score, classification_report<br># Example model training snippet<br>model = RandomForestClassifier(n_estimators=100, random_state=42)<br>model.fit(X_train, y_train)<br>predictions = model.predict(X_test)<br>print(f&quot;Accuracy: {accuracy_score(y_test, predictions):.2f}&quot;)</pre><h3>Phase 5: Deployment &amp; Real-World Integration</h3><p>A great model is only useful when it delivers business value. The final trained pipeline was serialized and integrated into an interactive web application, allowing stakeholders to input live customer metrics and instantly receive real-time churn risk assessments.</p><p><a href="https://customers-churn-prediction.netlify.app/">https://customers-churn-prediction.netlify.app/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae48a6c558a6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Raw IP to Production: The Ultimate Linux Server Setup & Hardening Guide]]></title>
            <link>https://medium.com/@mwangiboyle4/from-raw-ip-to-production-the-ultimate-linux-server-setup-hardening-guide-acc5b299d1af?source=rss-fcfc7715479a------2</link>
            <guid isPermaLink="false">https://medium.com/p/acc5b299d1af</guid>
            <category><![CDATA[web-application-firewall]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[linux-tutorial]]></category>
            <category><![CDATA[deployment]]></category>
            <category><![CDATA[nginx]]></category>
            <dc:creator><![CDATA[Mwangiboyle]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 07:49:16 GMT</pubDate>
            <atom:updated>2026-10-31T07:49:16.849Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZQjUQOfg6spq2wR4-bUdzw.jpeg" /><figcaption>htop showing the resource usage and the programs running</figcaption></figure><p>Getting a blank Linux instance (Ubuntu/Debian or RHEL-based) with a public IP address is exciting, but exposing a fresh server raw to the internet is a recipe for automated brute-force attacks within minutes. This guide walks you through the exact pipeline to provision, lock down, proxy, and deploy your services safely.</p><h3>Step 1: Initial Connection &amp; Basic Hygiene</h3><p>When your cloud provider hands you the IP address and root credentials, your first move is to log in and update the underlying software baseline.</p><ol><li><strong>First SSH Login:</strong></li></ol><pre>ssh root@&lt;YOUR_SERVER_IP&gt;</pre><p><strong>2. Update Package Lists &amp; Upgrade System:</strong> Immediately patch any out-of-the-box kernel flaws or vulnerable packages:</p><pre>sudo apt update &amp;&amp; sudo apt upgrade -y</pre><p><strong>3. Set a Clear Hostname:</strong> Give your server an identifiable identity in your local network and logs:</p><pre>sudo hostnamectl set-hostname prod-server-01</pre><h3>Step 2: User Privilege Management &amp; SSH Hardening</h3><p>Never run production apps or daily administrative tasks as the root user.</p><ol><li><strong>Create a Non-Root Admin User:</strong></li></ol><pre>adduser deployer <br>usermod -aG sudo deployer</pre><p><strong>2. Setup Ed25519 SSH Keys:</strong>On your <em>local machine</em>, generate a modern SSH key pair if you haven’t already:</p><pre>ssh-keygen -t ed25519 -C &quot;your_email@domain.com&quot;</pre><p>Copy your public key to the new server user:</p><pre>ssh-copy-id deployer@&lt;YOUR_SERVER_IP&gt;</pre><p><strong>3. Lock Down SSH Configuration (</strong><strong>/etc/ssh/sshd_config):</strong>Open the SSH daemon configuration file and enforce strict security boundaries:</p><ul><li>Disable root login over the network: PermitRootLogin no</li><li>Disable cleartext passwords entirely (enforce keys only): PasswordAuthentication no</li><li>Prevent empty passwords: PermitEmptyPasswords no</li></ul><p><strong>4. Test and Restart SSH Service:</strong><em>Crucial:</em> Open a <strong>second terminal tab</strong> and verify you can log in as deployer via your key before closing your current session.</p><pre>sudo sshd -t  # Checks for syntax errors <br>sudo systemctl restart ssh</pre><h3>Step 3: Firewall &amp; Intrusion Prevention (UFW &amp; Fail2ban)</h3><p>Never trust default network policies. Build an immediate perimeter defense.</p><ol><li><strong>Configure UFW (Uncomplicated Firewall):</strong>Set a default-deny inbound and default-allow outbound policy, then explicitly punch holes for essential services:</li></ol><pre>sudo ufw default deny incoming <br>sudo ufw default allow outgoing <br>sudo ufw allow 22/tcp   # SSH (or your custom SSH port) <br>sudo ufw allow 80/tcp   # HTTP <br>sudo ufw allow 443/tcp  # HTTPS <br>sudo ufw enable</pre><p><strong>2. Install and Configure Fail2ban:</strong> Block malicious automated brute-force bots trying to hammer your SSH or web endpoints:</p><pre>sudo apt install fail2ban -y <br>sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local <br>sudo systemctl enable --now fail2ban</pre><h3>Step 4: System Hardening &amp; Automated Patching</h3><p>Minimize your overall attack surface and automate routine security hygiene.</p><ol><li><strong>Enable Automatic Security Upgrades:</strong> Configure unattended upgrades so security patches are applied automatically without manual overhead:</li></ol><pre>sudo apt install unattended-upgrades -y <br>sudo dpkg-reconfigure -plow unattended-upgrades</pre><p><strong>2. Kernel Hardening via Sysctl (</strong><strong>/etc/sysctl.conf):</strong> Mitigate network-layer attacks (such as IP spoofing, SYN floods, and ICMP redirects) by tweaking kernel parameters:</p><pre>net.ipv4.conf.all.rp_filter = 1 <br>net.ipv4.tcp_syncookies = 1 <br>net.ipv4.conf.all.accept_source_route = 0 <br>net.icmp_echo_ignore_broadcasts = 1</pre><p>Apply changes with: sudo sysctl -p</p><h3>Step 5: Reverse Proxy Setup (Nginx) &amp; Automated SSL (Certbot)</h3><p>Never expose backend applications (Node.js, Python/FastAPI, Go binaries) directly to the public internet on ports 3000 or 8000. Put them securely behind Nginx.</p><ol><li><strong>Install Nginx:</strong></li></ol><pre>sudo apt install nginx -y</pre><p><strong>2. Configure a Virtual Host:</strong> Create a server block configuration file under /etc/nginx/sites-available/myapp:</p><ol><li>Nginx</li></ol><pre>server {<br>     listen 80;<br>     server_name yourdomain.com www.yourdomain.com;<br>      location / {<br>         proxy_pass http://127.0.0.1:3000; # Points to your local app process<br>         proxy_http_version 1.1;<br>         proxy_set_header Upgrade $http_upgrade;<br>         proxy_set_header Connection &#39;upgrade&#39;;<br>         proxy_set_header Host $host;<br>         proxy_cache_bypass $http_upgrade;<br>         proxy_set_header X-Real-IP $remote_addr;<br>         proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br>     } }</pre><p>Enable the site and test the configuration:</p><pre>sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/ <br>sudo nginx -t <br>sudo systemctl restart nginx</pre><p><strong>3. Automated SSL with Let’s Encrypt (Certbot):</strong> Secure your data traffic in transit with free TLS certificates:</p><pre>sudo apt install certbot python3-certbot-nginx -y <br>sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com</pre><p>Certbot will automatically modify your Nginx config to enforce HTTPS redirects and set up an automatic renewal cron job/timer.</p><h3>Step 6: Deployment Workflows &amp; Process Management</h3><p>With your server locked down and proxy routing web traffic securely, deploy your application code.</p><ol><li><strong>Process Management (PM2 / Systemd):</strong> Ensure your application restarts automatically on server reboots or crashes. For a Node.js or backend app, use PM2 or write a native systemd service file:</li></ol><pre>sudo npm install -g pm2 <br>pm2 start ecosystem.config.js <br>pm2 startup <br>pm2 save</pre><p><strong>2 .CI/CD Integration (GitHub Actions / Webhooks):</strong></p><ul><li>Authenticate your server via deploy keys or short-lived SSH tokens.</li><li>Configure a secure pipeline (git pull, dependency installation, database migrations, and zero-downtime service reloads via Nginx/PM2) triggered automatically on pushes to your production branch.</li></ul><h3>Conclusion &amp; Next Steps</h3><p>By following this blueprint, you’ve transformed a naked, vulnerable public IP into a hardened, production-ready Linux machine capable of safely hosting and scaling modern web applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=acc5b299d1af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Support Vector Machines: From Theory to Python Implementation]]></title>
            <link>https://medium.com/@mwangiboyle4/understanding-support-vector-machines-from-theory-to-python-implementation-46572f3ac172?source=rss-fcfc7715479a------2</link>
            <guid isPermaLink="false">https://medium.com/p/46572f3ac172</guid>
            <category><![CDATA[support-vector-machine]]></category>
            <category><![CDATA[mlops]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[classification]]></category>
            <dc:creator><![CDATA[Mwangiboyle]]></dc:creator>
            <pubDate>Wed, 27 Aug 2025 14:15:24 GMT</pubDate>
            <atom:updated>2025-08-27T14:15:24.120Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/410/0*1mXEiTyHbVultTcI" /></figure><h3>Introduction</h3><p>Support Vector Machines (SVMs) are one of the most powerful and elegant algorithms in machine learning. Originally developed by Vladimir Vapnik in the 1960s, SVMs have become a cornerstone of classification and regression tasks due to their strong theoretical foundation and excellent performance on various datasets.</p><p>In this comprehensive guide, we’ll explore the mathematical theory behind SVMs and implement a linear SVM from scratch using Python and NumPy.</p><h3>What is a Support Vector Machine?</h3><p>A Support Vector Machine is a supervised learning algorithm that finds the optimal boundary (hyperplane) to separate different classes in your data. The key insight is that SVM doesn’t just find any separating line — it finds the one that maximizes the margin between classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*zFE-vJoYEh1ibdMm" /></figure><h3>Key Concepts</h3><p><strong>Support Vectors</strong>: The data points closest to the decision boundary. These are the “critical” points that determine the position of the hyperplane.</p><p><strong>Hyperplane</strong>: In 2D, this is a line. In higher dimensions, it’s a plane or hyperplane that separates the classes.</p><p><strong>Margin</strong>: The distance between the hyperplane and the nearest data points from each class. SVM maximizes this margin.</p><h3>The Mathematical Foundation</h3><h3>Linear SVM Formulation</h3><p>For a binary classification problem with data points <strong>x</strong> and labels <strong>y</strong> ∈ {-1, +1}, we want to find a hyperplane defined by:</p><pre>f(x) = w·x + b = 0</pre><p>Where:</p><ul><li><strong>w</strong> is the weight vector (normal to the hyperplane)</li><li><strong>b</strong> is the bias term</li><li>The prediction is: ŷ = sign(w·x + b)</li></ul><h3>The Optimization Problem</h3><p>The goal is to maximize the margin, which is equivalent to minimizing ||<strong>w</strong>||². This leads to the primal optimization problem:</p><p><strong>Minimize</strong>: ½||<strong>w</strong>||² + C∑ξᵢ</p><p><strong>Subject to</strong>:</p><ul><li>yᵢ(w·xᵢ + b) ≥ 1 — ξᵢ for all i</li><li>ξᵢ ≥ 0 for all i</li></ul><p>Where:</p><ul><li><strong>C</strong> is the regularization parameter</li><li><strong>ξᵢ</strong> are slack variables allowing for misclassification</li></ul><h3>Hinge Loss Function</h3><p>Instead of solving the constrained optimization problem directly, we can use the hinge loss function:</p><pre>L(y, f(x)) = max(0, 1 - y·f(x))</pre><p>This gives us an unconstrained optimization problem:</p><p><strong>Minimize</strong>: λ||<strong>w</strong>||² + (1/n)∑max(0, 1 — yᵢ(w·xᵢ + b))</p><p>Where λ is the regularization strength (inverse of C).</p><h3>Implementation Details</h3><p>Let’s break down our Python implementation:</p><h3>Class Structure</h3><pre>class SVM:<br>    def __init__(self, learning_rate=0.001, lambda_param=0.01, n_epochs=1000):<br>        self.learning_rate = learning_rate<br>        self.lambda_param = lambda_param  # Regularization strength<br>        self.n_epochs = n_epochs<br>        self.w = None<br>        self.b = None</pre><h3>Training Algorithm</h3><p>The training process uses gradient descent with hinge loss:</p><ol><li><strong>Initialize</strong> weights and bias to zero</li><li><strong>For each epoch and each sample</strong>:</li></ol><ul><li>Check if the sample satisfies the margin condition: y(w·x + b) ≥ 1</li><li><strong>If satisfied</strong>: Only apply regularization gradient</li><li><strong>If violated</strong>: Apply both hinge loss and regularization gradients</li></ul><ol><li><strong>Update</strong> parameters using gradient descent</li></ol><h3>Gradient Computation</h3><p>For each data point (xᵢ, yᵢ):</p><p><strong>If correctly classified with margin ≥ 1</strong>:</p><ul><li>∂w: λw (only regularization)</li><li>∂b: 0</li></ul><p><strong>If misclassified or within margin</strong>:</p><ul><li>∂w: λw — yᵢxᵢ (regularization + hinge loss)</li><li>∂b: -yᵢ</li></ul><h3>Complete Implementation</h3><pre>import numpy as np</pre><pre>class SVM:<br>    &quot;&quot;&quot;<br>    Linear Support Vector Machine (SVM) using gradient descent.<br>    &quot;&quot;&quot;<br>    def __init__(self, learning_rate=0.001, lambda_param=0.01, n_epochs=1000):<br>        self.learning_rate = learning_rate<br>        self.lambda_param = lambda_param  # Regularization strength<br>        self.n_epochs = n_epochs<br>        self.w = None<br>        self.b = None<br>    <br>    def fit(self, X, y):<br>        &quot;&quot;&quot;<br>        Train SVM using hinge loss.<br>        y should be -1 or +1 labels.<br>        &quot;&quot;&quot;<br>        X = np.asarray(X)<br>        y = np.asarray(y)<br>        n_samples, n_features = X.shape<br>        <br>        # Initialize weights and bias<br>        self.w = np.zeros(n_features)<br>        self.b = 0<br>        <br>        # Gradient descent<br>        for epoch in range(self.n_epochs):<br>            for idx, x_i in enumerate(X):<br>                condition = y[idx] * (np.dot(x_i, self.w) + self.b) &gt;= 1<br>                <br>                if condition:<br>                    # Only regularization term<br>                    dw = self.lambda_param * self.w<br>                    db = 0<br>                else:<br>                    # Misclassified -&gt; include hinge loss gradient<br>                    dw = self.lambda_param * self.w - y[idx] * x_i<br>                    db = -y[idx]<br>                <br>                # Update parameters<br>                self.w -= self.learning_rate * dw<br>                self.b -= self.learning_rate * db<br>    <br>    def predict(self, X):<br>        &quot;&quot;&quot;Return class predictions (-1 or +1).&quot;&quot;&quot;<br>        approx = np.dot(X, self.w) + self.b<br>        return np.sign(approx)</pre><h3>Demonstration</h3><p>Let’s see our SVM in action with a simple 2D dataset:</p><pre># Toy dataset (linearly separable)<br>X_train = np.array([[2, 3],<br>                    [1, 1],<br>                    [2, 0.5],<br>                    [6, 8],<br>                    [7, 9],<br>                    [8, 8]])<br>y_train = np.array([-1, -1, -1, 1, 1, 1])</pre><pre># Train the SVM<br>svm = SVM(learning_rate=0.001, lambda_param=0.01, n_epochs=1000)<br>svm.fit(X_train, y_train)</pre><pre># Make predictions<br>X_test = np.array([[2, 2], [7, 7]])<br>predictions = svm.predict(X_test)<br>print(&quot;SVM predictions:&quot;, predictions)</pre><p><strong>Expected Output</strong>: SVM predictions: [-1 1]</p><h3>Key Parameters and Tuning</h3><h3>Learning Rate</h3><ul><li><strong>Too high</strong>: May overshoot the optimal solution</li><li><strong>Too low</strong>: Slow convergence</li><li><strong>Typical range</strong>: 0.001–0.1</li></ul><h3>Lambda (Regularization)</h3><ul><li><strong>Higher λ</strong>: More regularization, simpler model, wider margin</li><li><strong>Lower λ</strong>: Less regularization, more complex model, narrower margin</li><li><strong>Typical range</strong>: 0.001–1.0</li></ul><h3>Number of Epochs</h3><ul><li>Should be sufficient for convergence</li><li>Monitor training loss to determine optimal number</li></ul><h3>Advantages and Limitations</h3><h3>Advantages</h3><ol><li><strong>Effective in high dimensions</strong>: Works well when features &gt; samples</li><li><strong>Memory efficient</strong>: Only uses support vectors for predictions</li><li><strong>Versatile</strong>: Can use different kernel functions for non-linear problems</li><li><strong>Strong theoretical foundation</strong>: Based on statistical learning theory</li></ol><h3>Limitations</h3><ol><li><strong>No probability estimates</strong>: Only gives hard classifications</li><li><strong>Sensitive to feature scaling</strong>: Requires normalized features</li><li><strong>Poor performance on large datasets</strong>: O(n²) to O(n³) complexity</li><li><strong>Sensitive to outliers</strong>: Can significantly affect the decision boundary</li></ol><h3>Extensions and Variations</h3><h3>Non-linear SVMs</h3><ul><li>Use kernel functions (RBF, polynomial) to map data to higher dimensions</li><li>Allows handling of non-linearly separable data</li></ul><h3>Multi-class Classification</h3><ul><li>One-vs-One or One-vs-All approaches</li><li>ECOC (Error-Correcting Output Codes)</li></ul><h3>Support Vector Regression (SVR)</h3><ul><li>Extends SVM to regression problems</li><li>Uses ε-insensitive loss function</li></ul><h3>Conclusion</h3><p>Support Vector Machines represent a perfect blend of mathematical elegance and practical utility. By maximizing the margin between classes, SVMs often generalize well to unseen data. Our implementation demonstrates the core concepts using gradient descent on the hinge loss function.</p><p>While this linear SVM is relatively simple, it forms the foundation for understanding more advanced SVM variants with kernel tricks and non-linear decision boundaries. The key insight remains the same: find the decision boundary that not only separates the classes but does so with maximum confidence (margin).</p><h3>Further Reading</h3><ol><li><strong>“The Elements of Statistical Learning”</strong> by Hastie, Tibshirani, and Friedman</li><li><strong>“Pattern Recognition and Machine Learning”</strong> by Christopher Bishop</li><li><strong>“Learning with Kernels”</strong> by Schölkopf and Smola</li><li><strong>Original SVM papers</strong> by Vladimir Vapnik</li></ol><p><em>This implementation provides a solid foundation for understanding SVM mechanics. For production use, consider using optimized libraries like scikit-learn’s SVM implementation, which uses more sophisticated optimization techniques like Sequential Minimal Optimization (SMO).</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=46572f3ac172" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Logistic Regression Explained Simply]]></title>
            <link>https://medium.com/@mwangiboyle4/logistic-regression-explained-simply-9218cd151229?source=rss-fcfc7715479a------2</link>
            <guid isPermaLink="false">https://medium.com/p/9218cd151229</guid>
            <category><![CDATA[logistic-regression]]></category>
            <category><![CDATA[binary-cross-entropy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[binary-classification]]></category>
            <dc:creator><![CDATA[Mwangiboyle]]></dc:creator>
            <pubDate>Mon, 25 Aug 2025 11:20:59 GMT</pubDate>
            <atom:updated>2025-08-25T11:20:59.187Z</atom:updated>
            <content:encoded><![CDATA[<p>Logistic Regression is one of the most popular algorithms for <strong>binary classification</strong>.<br> Unlike <strong>Linear Regression</strong>, which predicts continuous values, Logistic Regression answers a simpler question:</p><p>👉 <em>Given some inputs, what is the probability that the outcome belongs to class 1 (yes) instead of class 0 (no)?</em></p><h3>🧮 The Core Idea</h3><p>The model looks very similar to linear regression:</p><pre>z = w · x + b</pre><p>where:</p><ul><li>w = weights (importance of each feature),</li><li>x = input features,</li><li>b = bias (intercept).</li></ul><p>But here’s the trick: instead of outputting z directly, we pass it through the <strong>sigmoid function</strong> to squash the value into the range <strong>(0, 1)</strong>:</p><pre>sigmoid(z) = 1 / (1 + e^(-z))</pre><p>This gives us a <strong>probability</strong> — how likely the input belongs to class 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/725/1*LAqExUIP8zgoVPG0Q3HCuQ.png" /></figure><h3>🎯 Decision Making</h3><p>Once we have the probability, we choose a <strong>threshold</strong> (usually 0.5):</p><pre>if probability &gt;= 0.5 → predict class 1  <br>else → predict class 0</pre><p>This makes Logistic Regression a <strong>classifier</strong>, not a regressor.</p><h3>📉 The Loss Function</h3><p>We need a way to measure how well our model predicts.<br> For Logistic Regression, the common loss function is <strong>Binary Cross-Entropy (Log Loss):</strong></p><pre>Loss = - (1/n) Σ [ y * log(y_pred) + (1 - y) * log(1 - y_pred) ]</pre><p>This penalizes wrong confident predictions heavily.</p><ul><li>If the model predicts 0.9 for class 1, loss is small ✅</li><li>If it predicts 0.1 for class 1, loss is huge ❌</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CYMBkuSEL_Ta20TAn3nUzA.png" /></figure><h3>⚙️ Training with Gradient Descent</h3><p>Just like Linear Regression, we update weights (w) and bias (b) using <strong>gradient descent</strong>:</p><ol><li>Start with random weights and bias.</li><li>Predict probabilities using sigmoid.</li><li>Calculate gradients (how much to adjust w and b).</li><li>Update parameters to reduce loss.</li><li>Repeat for many iterations (epochs).</li></ol><p>Over time, the model learns the <strong>best decision boundary</strong> that separates the classes.</p><h3>🚀 Example</h3><p>Imagine we have two features (say, hours studied and hours slept) and we want to predict:<br> 👉 <em>Will the student pass (1) or fail (0)?</em></p><ul><li>The model learns weights for both features.</li><li>Applies the sigmoid to get a probability.</li><li>If the probability ≥ 0.5 → predict “Pass”.</li><li>Otherwise → predict “Fail”.</li></ul><p>At the end, we not only get predictions but also <strong>interpret-ability</strong> — we can see which features matter more by looking at the learned weights.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9218cd151229" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Linear Regression Explained Simply]]></title>
            <link>https://medium.com/@mwangiboyle4/linear-regression-explained-simply-42b71294963a?source=rss-fcfc7715479a------2</link>
            <guid isPermaLink="false">https://medium.com/p/42b71294963a</guid>
            <category><![CDATA[gradient-descent]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[linear-regression]]></category>
            <dc:creator><![CDATA[Mwangiboyle]]></dc:creator>
            <pubDate>Mon, 25 Aug 2025 10:18:47 GMT</pubDate>
            <atom:updated>2025-08-25T10:18:47.693Z</atom:updated>
            <content:encoded><![CDATA[<p>Linear Regression is one of the simplest yet most powerful algorithms in machine learning. Its goal is simple:<br> 👉 <strong>find a straight line that best fits the data.</strong></p><p>Imagine you have data of people’s <strong>years of experience</strong> vs their <strong>salary</strong>. If you plot it, you’ll probably notice a trend: more experience often means higher salary. Linear regression tries to capture this trend with a straight line.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*sHSEHOPwwprPl2aYQMycaw.png" /></figure><h3>🧮 The Equation of a Line</h3><p>The line we want to find looks like this:</p><pre>y = w * x + b</pre><ul><li>y → the predicted output (salary)</li><li>x → the input (years of experience)</li><li>w → the weight (slope of the line)</li><li>b → the bias (the intercept where the line crosses the y-axis)</li></ul><p>Our job is to figure out the best values of w and b so that the line fits the data as closely as possible.</p><h3>🎯 Measuring “Best Fit”</h3><p>How do we know if our line is good?<br> We measure the <strong>error</strong> (difference) between the predicted values (y_pred) and the actual values (y_true).</p><p>The most common metric is <strong>Mean Squared Error (MSE):</strong></p><pre>MSE = (1/n) * Σ (y_pred - y_true)^2</pre><p>Lower MSE means our line is fitting better.</p><h3>⚙️ How Do We Learn w and b?</h3><p>We use an optimization method called <strong>Gradient Descent</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/754/1*uu0f9oMGGcFGWuzIqly8Cg.jpeg" /></figure><p>Think of it like this:</p><ul><li>We start with random guesses for w and b.</li><li>We calculate the error (MSE).</li><li>We slightly adjust w and b in the direction that <strong>reduces the error</strong>.</li><li>Repeat this process until the line is as close as possible to the data points.</li></ul><p>It’s like rolling downhill until you reach the lowest valley (the minimum error).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42b71294963a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>