<?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 Saeed Abdul Rahim on Medium]]></title>
        <description><![CDATA[Stories by Saeed Abdul Rahim on Medium]]></description>
        <link>https://medium.com/@saeedAR?source=rss-eb42e1784d0b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kvGhfCpyDKb93ouETWyeHQ.jpeg</url>
            <title>Stories by Saeed Abdul Rahim on Medium</title>
            <link>https://medium.com/@saeedAR?source=rss-eb42e1784d0b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 14:25:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saeedAR/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[Automate WhatsApp Messages (Random Media) by using Python + Tasker + SKEDit on Android]]></title>
            <link>https://medium.com/@saeedAR/automate-whatsapp-messages-random-media-by-using-python-tasker-skedit-on-android-bcf8034f91fe?source=rss-eb42e1784d0b------2</link>
            <guid isPermaLink="false">https://medium.com/p/bcf8034f91fe</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tasker]]></category>
            <category><![CDATA[skedit]]></category>
            <dc:creator><![CDATA[Saeed Abdul Rahim]]></dc:creator>
            <pubDate>Thu, 18 Apr 2019 20:23:13 GMT</pubDate>
            <atom:updated>2019-04-18T20:23:13.523Z</atom:updated>
            <content:encoded><![CDATA[<p>Ever wanted to send <strong>random</strong> motivational images / videos everyday to your contacts? Here is a way to do it.</p><p>Firstly though, we will have to talk about disadvantages of using this method:</p><p>· <strong>No screen lock should be provided for your phone</strong></p><p>· Tasker (App requires money)</p><p>· QPython plugin for Tasker (App requires money)</p><p>Okay then, let’s start.</p><p><strong>Problem Statement:</strong></p><p>You want to send random motivational images to WhatsApp Groups / Contacts at a specified time.</p><p><strong>Tools for the mission:</strong></p><ol><li><strong>SKEDit — Message Scheduling App</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*-DAwS_0mesnmY3-TbWZlNg.jpeg" /></figure><p>I would only need this app, if I were not sending messages randomly / as per my logic.</p><p>It can only select one image with a specific name.</p><p>You can add WhatsApp Groups or contacts.</p><p>Here I’ve selected message1.jpg from auto_message folder to be sent everyday.</p><p>Now that I’ve set “message1.jpg” to be sent daily at “00:01”. This sends the same “message1.jpg” every day. But I want to randomize this.</p><p>So, before the message is sent — I want to randomly <strong>name one of the images “message1.jpg”</strong></p><p>So, I would require an automation before SKEDit runs. Here I would need a python script and script scheduler.</p><p>Here goes the logic:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2E-b4rkmFKiPoy5dCdhnVg.png" /></figure><p><strong>2. QPython — Write Python Code</strong></p><p>Here I wrote a simple logic where all images get a new random name, and then chooses a random image, and it gets renamed to “message1.jpg”.</p><p>Saved the code in scripts folder with the filename “rename.py”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*x8LqCzMSFf_gkqQ53q40Uw.png" /><figcaption><a href="https://github.com/saeed-abdul-rahim/tutorials/blob/master/random_msg/rename.py">https://github.com/saeed-abdul-rahim/tutorials/blob/master/random_msg/rename.py</a></figcaption></figure><p>I’ve attached the github link for the code.</p><p><a href="https://github.com/saeed-abdul-rahim/tutorials/blob/master/random_msg/rename.py">saeed-abdul-rahim/tutorials</a></p><p>Finally, you need:</p><p><strong>3. Tasker &amp; QPython Plugin for Tasker:</strong></p><p>This is required for opening Qpython and running the script before SKEDit gets active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*4c6SAR-enIoT4slCmJUO9w.jpeg" /></figure><p>Go to Tasks tab &gt; Click “+” button &gt; Write new name of your task &gt; Select Plugin &gt; Select QPython &gt; Select your script.</p><p>(In this case “rename.py”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*n_XreoMGXyDVnNHXSXO5rA.jpeg" /></figure><p>Go to Profiles tab &gt; Click + button &gt; Select Time (before SKEDit’s time) &gt; Select your recently created task.</p><blockquote>That’s all. Your phone is ready to send messages automatically!</blockquote><blockquote>This method can be done for any kind of attachments for WhatsApp.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bcf8034f91fe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SMOTE AND NEAR MISS IN PYTHON: MACHINE LEARNING IN IMBALANCED DATASETS]]></title>
            <link>https://medium.com/@saeedAR/smote-and-near-miss-in-python-machine-learning-in-imbalanced-datasets-b7976d9a7a79?source=rss-eb42e1784d0b------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7976d9a7a79</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Saeed Abdul Rahim]]></dc:creator>
            <pubDate>Mon, 04 Jun 2018 10:57:09 GMT</pubDate>
            <atom:updated>2018-06-04T11:05:34.041Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mQFgB4hQtbHwMiaD6JPSoA.png" /></figure><h3><strong>What is an Imbalanced Dataset?</strong></h3><p>Imagine, you have two categories in your dataset to predict — Category-A and Category-B. When Category-A is higher than Category-B or vice versa, you have a problem of imbalanced dataset.</p><p>So how is this a problem?</p><p>Imagine in a dataset of 100 rows, Category-A is containing 90 records and Category-B is containing 10 records. You run a machine learning model and end up with 90% accuracy. You were excited until you checked the confusion matrix.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mHRoCv6kr9JvPiXF44vaKg.png" /><figcaption>Confusion Matrix</figcaption></figure><p>Here, Category-B is completely classified as Category-A and the model got away with an accuracy of 90%.</p><p>How do we fix this problem?</p><p>We will be discussing 2 of the common and simple ways to deal with this problem.</p><h3><strong>SMOTE (Synthetic Minority Over-sampling Technique)</strong></h3><p>SMOTE is an over-sampling method. What it does is, it creates synthetic (not duplicate) samples of the minority class. Hence making the minority class equal to the majority class. SMOTE does this by selecting similar records and altering that record one column at a time by a random amount within the difference to the neighbouring records.</p><p>We will be diving into python to see how this works. If you want to read more on SMOTE, here is an original research paper titled: “<a href="https://jair.org/index.php/jair/article/view/10302">SMOTE: Synthetic Minority Over-sampling Technique</a>” written in 2002.</p><h3><strong>NearMiss</strong></h3><p>NearMiss is an under-sampling technique. Instead of resampling the Minority class, using a distance, this will make the majority class equal to minority class.</p><p>Let’s see these practically:</p><h3><strong>Dataset</strong></h3><p>I’ll be using <a href="https://archive.ics.uci.edu/ml/datasets/bank+marketing">Bank Marketing</a> dataset from UCI. Here the column for prediction is “y” which says either yes or no for client subscription to term deposit. The full code is available on <a href="https://github.com/saeed-abdul-rahim/tutorials/blob/master/imblearn/SMOTENearMiss.py">GitHub</a>.</p><p>I have put the data in a variable called “bank”. And for the sake of simplicity, I’ve removed “poutcome” and “contact” column and dropped the NAs.</p><p>So, from 45,211 records, we are left with 43,193 records. For the next step, I’ve mapped yes and no to “1” and “0” respectively.</p><p>Now to the main part:</p><p>If we check:</p><pre>bank.y.value_counts()</pre><p>We get:</p><pre>0 38172<br>1 5021<br>Name: y, dtype: int64</pre><p>The dataset contains 38172 records of clients without term deposit subscription and only 5021 records of clients with term deposit subscription. Clearly an imbalanced dataset.</p><p>If we split the dataset and fit a Logistic Regression and check the accuracy score:</p><pre>lr = LogisticRegression()</pre><pre>lr.fit(X_train, y_train)<br>y_pred = lr.predict(X_test)</pre><pre>accuracy_score(y_test, y_pred)</pre><pre>Out[1]: 0.8930456523752199</pre><p>Great 89%! Now let us check the confusion matrix:</p><pre>confusion_matrix(y_test, y_pred)</pre><pre>array([[9371,  173],<br>       [ 982,  273]], dtype=int64)</pre><p>We can clearly see, this is a <strong>bad</strong> model. This model is not able to classify clients who have subscription for term deposits. Let’s check the recall score:</p><pre>recall_score(y_test, y_pred)<br>Out[1]: 0.21752988047808766</pre><p>Clearly bad. This is expected, since the one category has more records than the other.</p><h3><strong>Applying SMOTE:</strong></h3><p>You might need to install <em>imblearn </em>package from your prompt / Terminal.</p><pre>pip install imblearn</pre><p>Now:</p><pre>from imblearn.over_sampling import SMOTE</pre><p>Before fitting SMOTE, let us check the y_train values:</p><pre>y_train.value_counts()</pre><pre>0    28628<br>1     3766<br>Name: y, dtype: int64</pre><p>Let us fit SMOTE: (You can check out all the parameters from <a href="http://contrib.scikit-learn.org/imbalanced-learn/stable/generated/imblearn.over_sampling.SMOTE.html">here</a>)</p><pre>smt = SMOTE()<br>X_train, y_train = smt.fit_sample(X_train, y_train)</pre><p>Now let us check the amount of records in each category:</p><pre>np.bincount(y_train)</pre><pre>Out[48]: array([28628, 28628], dtype=int64)</pre><p>Both categories have equal amount of records. More specifically, the minority class has been increased to the total number of majority class.</p><p>Now fitting the classifier again and testing we get an accuracy score of:</p><pre>accuracy_score(y_test, y_pred)</pre><pre>Out[1]: 0.8025743124363367</pre><p>Whoa! We have reduced the accuracy. But let us check the confusion matrix anyway:</p><pre>confusion_matrix(y_test, y_pred)</pre><pre>array([[7652, 1892],<br>       [ 240, 1015]], dtype=int64)</pre><p>This is a good model compared to the previous one. Recall is great.</p><pre>recall_score(y_test, y_pred)</pre><pre>Out[1]: 0.8087649402390438</pre><p>I would go ahead with this model than using the previous model. Now let us check what happens if we use NearMiss.</p><h3><strong>Applying NearMiss:</strong></h3><p>Import NearMiss:</p><pre>from imblearn.under_sampling import NearMiss</pre><p>Fit NearMiss: (You can check all the parameters from <a href="http://contrib.scikit-learn.org/imbalanced-learn/stable/generated/imblearn.under_sampling.NearMiss.html">here</a>)</p><pre>nr = NearMiss()<br>X_train, y_train = nr.fit_sample(X_train, y_train)</pre><p>Now let us check the amount of records in each category:</p><pre>np.bincount(y_train)</pre><pre>array([3766, 3766], dtype=int64)</pre><p>Here, the majority class has been reduced to the total number of minority class, so that both classes will have equal number of records.</p><p>Now let us fit the classifier again and test the model:</p><pre>confusion_matrix(y_test, y_pred)<br>array([[5102, 4442],<br>       [ 162, 1093]], dtype=int64)</pre><pre>accuracy_score(y_test, y_pred)<br>Out[1]: 0.573664228169275</pre><pre>recall_score(y_test, y_pred)<br>Out[1]: 0.8709163346613545</pre><p>This model is better than the first model because it classifies better. But since in this case, SMOTE is giving me a great accuracy and recall, I’ll go ahead and use that model! :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7976d9a7a79" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>