<?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 Mohammed Ehsan Ur Rahman on Medium]]></title>
        <description><![CDATA[Stories by Mohammed Ehsan Ur Rahman on Medium]]></description>
        <link>https://medium.com/@ehsan81181?source=rss-1ade9a6646bf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Mohammed Ehsan Ur Rahman on Medium</title>
            <link>https://medium.com/@ehsan81181?source=rss-1ade9a6646bf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 10:11:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ehsan81181/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[Sparkify Project]]></title>
            <link>https://medium.com/@ehsan81181/sparkify-project-51c859556c73?source=rss-1ade9a6646bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/51c859556c73</guid>
            <category><![CDATA[data-modeling]]></category>
            <category><![CDATA[sparkml]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Mohammed Ehsan Ur Rahman]]></dc:creator>
            <pubDate>Fri, 07 Jan 2022 17:25:55 GMT</pubDate>
            <atom:updated>2022-01-12T02:31:22.196Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Project Overview</strong></h3><p>In this project, we are going to analyze and find the churn rate and reasons for churning by the customers of a music website using PySpark. Churn rate is the rate at which customers stop using products of a business entity. Generally, it’s the percentage of subscribers who discontinue their subscriptions within a given timeframe.</p><h3><strong>Problem statement</strong></h3><p>We are given user data such as gender, the number of artists the user listened to, the user’s subscription type, the number of songs he has listened to, the number of songs liked/disliked by the user, the number of advertisements the user was presented with, and so on. Using this information we need to predict whether a given user will cancel their subscription.</p><p>The way prediction is going to be performed is using a machine learning prediction model, such models take in the input data and give out the predicted result by modeling a large amount of training data. Here we will deal with logistic regression, random forests, and gradient-boosted trees.</p><p>These models will use information such as gender, the number of artists the user listened to, the user’s subscription type, the number of songs he has listened to, the number of songs liked/disliked by the user, the number of advertisements the user was presented with, and so on and predict whether a given user will churn or not.</p><h3><strong>Data</strong></h3><p>The subset dataset (128MB) was kindly supplied by Udacity in form of a JSON file. After creating a Spark Session and loading in the data we could finally start with every data scientist’s favorite job: cleaning. The data had some empty strings for users, so these were removed and we were left with 278,154 rows of our mini subset of data. The data was in the form of a customer’s interaction history with the Sparkify app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/268/1*1byz-mEB7vD6wXYJnuLVVQ.png" /></figure><h3><strong>Metrics</strong></h3><p>We will be using the F1 score and accuracy for evaluating the performance of the prediction model. Accuracy is the fraction of predictions the prediction model got right. F1 score can be defined as the Harmonic mean of precision and recall. Precision can be defined as the number of true positives divided by the total of true positives and false positives whereas recall can be defined as true positives divided by the total of true positives and false negatives.</p><p>The reason for using the F1 score and accuracy is because these are the most suggestive performance metrics for prediction and classification problems such as the problem of predicting churn.</p><p>The F1-score is generally used to evaluate binary classification/prediction problems such as the churn prediction problems, which classify examples into ‘positive’ (churn) or ‘negative’(no churn). Accuracy</p><p>Let us consider a simple question for this study. Will different models such as logistic regression, GBT, random forests, etc. give a very different performance on the same dataset and with the same parameters?</p><p>The data that was being modeled was stored in a JSON format and was read into a spark data frame, in common terms a dataset that can be easily used with spark functions.</p><h3><strong>Data Exploration</strong></h3><p>Every data science problem starts with exploring the data. We start with understanding what is the data type of each column, how many columns are in the dataset, we understand if there is any missing data and deal with it, and search for the column which we have to predict based on the other columns, and whether any formatting needs to be done on the columns to make them ready for the modeling step.</p><p>The dataset has 286500 rows and 18 columns. The average number of songs is listened to per user is 83.25, the average number of artists listened to by each user is 635, and there are more number of users without a subscription churning when compared as the percentage of total users churning.</p><p>Some outliers in the dataset are columns with missing values. The rows miss either a UserID or SessionId, I have removed all the rows which didn’t have a user ID or a session ID because they are useless for our computation.</p><p>Based on the page that was accessed by the user, the users were classified as to whether they churned or not. The user churned if he accessed the subscription cancellation page.</p><p>As the dataset has lots of columns I have identified some columns that can be good predictors of churn such as whether the user is using a paid subscription or not, the number of songs he has listened to, the number of songs liked/disliked by the user, number of advertisements he was presented with, number of different artists the user has listened to, and so on.</p><h3>Data Pre-processing</h3><p>In order to train the model, I had to perform some pre-processing steps such as converting the columns into vectors, scaling them using a standard scaler. More information about pre-processing data for model training can be found: <a href="https://machinelearningmastery.com/what-is-data-preparation-in-machine-learning/">https://machinelearningmastery.com/what-is-data-preparation-in-machine-learning/</a></p><p>The dataset was divided into three separate pieces for training, testing, and validation. I have used three models for training, logistic regression, random forests, and gradient-boosted trees.</p><h3>Implementation</h3><p><strong>Libraries were imported</strong></p><ol><li>pandas for dataframe manipulation</li><li>NumPy for numerical processing</li><li>matplotlib for plotting</li><li>seaborn for visualization</li><li>to use spark functions in Python</li><li>sys and time for housekeeping</li><li>pyspark for spark sessions and functions and machine learning functions</li></ol><p><strong>Spark session was created</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/520/1*EfFnrXvDqsjQGV_wJXeafA.png" /></figure><p><strong>Loading and cleaning the data</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/627/1*rqTmVgdAfrG55Itfaw0pHw.png" /></figure><p>Exploring dataset using spark dataframe functions such as df.describe, df.head, df.count, df.sample, df.columns, df.dtypes, etc.</p><p>Churning is defined using a lambda function if the page column has a cancellation confirmation page entry a 1 is put in that row, and 0 otherwise.</p><p>Exploring how churn is related to the number of songs, the subscription type, and the number of artists is done at this point.</p><h3>Data Visualization</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*18RG6WMXa3NIGmW4Z2GRkg.png" /></figure><p>Churn versus subscription type</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*blCN94M8kvzzGo64K9f9hQ.png" /></figure><p>Churn versus the number of songs</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*EIE1f8Navgar-TA2txASZw.png" /></figure><p>Churn versus number of artists listened to</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*GY2Ts4IG528SS5DvJxJF9w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*R49vRlBEB3E9EA50GwEPWQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/1*oi05cqpDWWO8aHpGOklLnw.png" /></figure><p><strong>Feature Engineering</strong></p><p>Using the features identified in the dataset that can be related to churn a dataset was made that seem most promising to train our model on.</p><p>The features incorporated into this dataset are:</p><ul><li>level</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*5dKm_Swc76GKxUEOK8GbCw.png" /></figure><ul><li>number of songs per session for a user</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*ki9Iz1dEwtu1cHg3_B0w_w.png" /></figure><ul><li>number of rollads actions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*Ut-MgYdZkI_jfNsesEtkOQ.png" /></figure><ul><li>number of thumb down actions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/852/1*dp2F0CnLerJ27SAsu5e13g.png" /></figure><ul><li>number of thumbs up actions</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/918/1*PmJBChwDSFFHLWK-5ApI8w.png" /></figure><ul><li>number of different artists listened to on Sparkify</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*j8h-Rv7OgQfWixra2ruuPw.png" /></figure><ul><li>lastly, the label to represent if the user churned or not</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/1*iwIKOiH5AKW_fAtY-KpzrQ.png" /></figure><p>We need to create these so that each feature is numerical. The features are joined together to create a features data frame where each row represents information pertaining to each individual user.</p><p>The dataset is then vectorized, and standardized, and fed into our different machine learning algorithms here: logistic regression, GBT, random forests</p><p>The detailed implementation can be found here: <a href="https://github.com/EhsanMohd/Capstone-Project-Sparkify-Udacity-Data-Scientist-Nanodegree">https://github.com/EhsanMohd/Capstone-Project-Sparkify-Udacity-Data-Scientist-Nanodegree</a></p><h3>Preprocessing</h3><p>We had to convert our features into a vector that could be put into a regular scaler first. This is crucial for our machine learning model because it prevents the highest-valued characteristics from dominating the output. The vectors are then standardized. The dataset is split into train, test and validation sets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*soSHpwgb7QkzgIBdzbzmxA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CGtQ4-KCsVgHFwMGhfgvEA.png" /></figure><h3>Data Modelling</h3><p>Different machine learning classification algorithms used for modeling are:</p><ul><li>Logistic Regression: Logistic regression is another technique borrowed by machine learning from the field of statistics. It is the go-to method for binary classification problems like churn prediction. Logistic regression uses an equation as the representation, very much like linear regression. More information can be found: <a href="https://machinelearningmastery.com/logistic-regression-for-machine-learning/">https://machinelearningmastery.com/logistic-regression-for-machine-learning/</a></li><li>Random Forest Classifier: Random forest is an ensemble machine learning algorithm. It is perhaps the most popular and widely used machine learning algorithm given its good or excellent performance across a wide range of classification and regression predictive modeling problems. More information can be found: <a href="https://machinelearningmastery.com/random-forest-ensemble-in-python/">https://machinelearningmastery.com/random-forest-ensemble-in-python/</a></li><li>Gradient-Boosted Tree Classifier: A gradient-boosted trees model is built in a stage-wise fashion as in other boosting methods, but it generalizes the other methods by allowing optimization of an arbitrary differentiable loss function. More information can be found: <a href="https://machinelearningmastery.com/gradient-boosting-with-scikit-learn-xgboost-lightgbm-and-catboost/">https://machinelearningmastery.com/gradient-boosting-with-scikit-learn-xgboost-lightgbm-and-catboost/</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*PhnarlgDpBm9zi7eaojYUA.png" /></figure><h3>Evaluation and Validation</h3><p>The validation took place using the validation dataset with an F1 score as the evaluation metric along with accuracy. The accuracy obtained for the three models is almost the same. See figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C691yDpCpEP-UFAOiRjBGw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*HNCQPz_E3dHRcjUV103F3A.png" /></figure><h3>Refinement</h3><p>I selected the best performing model i.e the gradient-boosted algorithm and increased the number of iterations from 20 to 30, and got better results, see the figure below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*Sn1YcT-v1d_-y0wo7e8ROA.png" /></figure><h3>Improvement</h3><p>I have tend to use only traditional machine learning algorithms for this project, and in future works I would be working with more advanced algorithms like multi-layer perception, neural networks, and use ANOVA and higher level of feature selection mechanisms.</p><h3>Justification</h3><p>Let’s now consider an answer for the question: Will different models such as logistic regression, GBT, random forests, etc. give a very different performance on the same dataset and with the same parameters?</p><p>As these models work with the data in a similar fashion, the performance is almost the same for all of them.</p><h3>Conclusion</h3><p>The project used a dataset of 128MB and contains helpful features to forecast churn after loading and cleaning it. The prediction model was constructed using a selected subset of the most promising features. The features were then preprocessed and employed with several machine learning methods like logistic regression and gradient-boosted trees.</p><p>Sparkify can now utilize this data to target customers who are prone to churn and offer them enticing incentives to stay, saving the company money while also giving the client a good bargain. We may target new clients with a great free trial of the premium service sans adverts since new customers are more likely to churn.</p><h3>The learning goals I had for this project were:</h3><p>1. Load large datasets into Spark (<a href="https://spark.apache.org/docs/latest/">https://spark.apache.org/docs/latest/ml-guide.html</a>) and manipulate them using Spark SQL and Spark Dataframes (<a href="https://spark.apache.org/docs/latest/sql-programming-guide.html">https://spark.apache.org/docs/latest/sql-programming-guide.html</a>)</p><p>2. Use the machine learning APIs within Spark ML (<a href="https://spark.apache.org/docs/latest/ml-guide.html">https://spark.apache.org/docs/latest/ml-guide.html</a>) to build and tune models</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51c859556c73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Semantic Image Segmentation for Autonomous Driving]]></title>
            <link>https://medium.com/@ehsan81181/semantic-image-segmentation-for-autonomous-driving-69dc6c11ea1a?source=rss-1ade9a6646bf------2</link>
            <guid isPermaLink="false">https://medium.com/p/69dc6c11ea1a</guid>
            <category><![CDATA[unet]]></category>
            <category><![CDATA[self-driving-cars]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[semantic-segmentation]]></category>
            <dc:creator><![CDATA[Mohammed Ehsan Ur Rahman]]></dc:creator>
            <pubDate>Sat, 01 Jan 2022 19:23:57 GMT</pubDate>
            <atom:updated>2022-01-05T16:38:22.417Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*d5dXXySfyDpdrxwoYgz2ZQ.png" /><figcaption>Self-driving … !!!</figcaption></figure><p>Have you ever pondered about how seamlessly we can drive a car, and why is it so difficult to get a computer to drive a car?</p><p>It’s because our minds are highly evolved and complex and embedding this complexity into a computer is challenging. And today we will cover a tiny fraction of our journey towards achieving self-driving cars.</p><p>The task I will be discussing in this post is called semantic segmentation. Segmentation as the name suggests is the act of dividing something into separate parts. Semantic means logical, so semantic segmentation is dividing something into parts using an underlying logic. Here is the task of image segmentation we are dividing the image and labeling the different sections using the logic of similar texture, shape, or size.</p><p>And I have associated three questions whose answers I will be trying to extract through my experiments with the dataset:</p><p>1. Can I improve the performance of the UNet segmentation model with a slight change in its structure?</p><p>2. How can semantic segmentation help in achieving self-driving capabilities?</p><p>3. What’s an optimal way to experiment faster and fetch proper insights for efficient use of resources of the organization and streamlining strategies?</p><p>4. What is the amount of performance improvement with this change?</p><p>5. Is the change worthy enough of the time and resources being spent on training the model?</p><p>We shall use the CityScapes dataset (<a href="https://www.kaggle.com/dansbecker/cityscapes-image-pairs">https://www.kaggle.com/dansbecker/cityscapes-image-pairs</a>) to demonstrate semantic segmentation. This task and dataset that we use are of high practical importance to businesses like Waymo and Uber who are in the race of self-driving cars. This data can also be used to make current surveillance systems more robust and to make accident alert systems more robust too.</p><p>Though there are many different approaches out there to tackle the challenge of semantic segmentation such as pix2pix, and other old computer vision approaches, the current systems in development use only neural networks and deep learning principles.</p><p>Eminent in them are the segmentation models that use convolutional layers, and the one we will be deploying in this tutorial is called the UNet model because of its U-shaped structure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/1*lDiN-y1BQdgujOfBiFg_NQ.png" /><figcaption>UNet Model</figcaption></figure><p>The figure is taken from <a href="https://arxiv.org/abs/1505.04597">https://arxiv.org/abs/1505.04597</a>.</p><p>Another Hybrid UNet model as shown in the figure below was also created, trained, and used for the task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*Q6z-HEHvy9v2jZRBq6gy4Q.png" /><figcaption>Hybrid UNet model</figcaption></figure><p>Your findings for those questions with a supporting statistic(s), table, or visual.</p><p>1. Can I improve the performance of the UNet segmentation model with a slight change in its structure?</p><p>Answer: The dice score co-efficient which is a measure of accuracy in the task of semantic segmentation shows improvement when we used the Hybrid model. The dice score of the plain UNet model was 0.4549 when compared with the Hybrid UNet model for which it is 0.4588. Comparing them with the benchmark (0.77) both the models have low values due to the smaller number of epochs and extremely small size of the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*etjnTY12ns_dFrteCVshAw.png" /><figcaption>Results from the UNet model</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mBQsQhB90yZLL8WLEoP6yQ.png" /><figcaption>Results from Hybrid UNet model</figcaption></figure><p>2. How can semantic segmentation help in achieving self-driving capabilities?</p><p>Answer: Semantic segmentation helps the self-driving vehicle understand where the pedestrians are, where are the traffic lights and signs, and so on. This helps in letting it focus on where the important information for efficient and safe driving. It can also be used with features such as recognizing the distance between the vehicle and objects, allowing the vehicle to construct a safe and efficient driving trajectory.</p><p>3. What’s an optimal way to experiment faster and fetch proper insights?</p><p>Answer: Findings suggest that the UNet model is rather weak if used as it is, if the customized and detailed model is created with more data and better training mechanism then there can be a huge improvement in the accuracy and other evaluation metrics.</p><p>4. What is the amount of performance improvement with this change?</p><p>Answer: The dice score of the plain UNet model was 0.4549 when compared with the Hybrid UNet model for which it is 0.4588. Comparing them with the benchmark (0.77) both the models have low values due to the smaller number of epochs and extremely small size of the dataset.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VgkynteKFz-Lb0PiSIlbKQ.png" /><figcaption>Comparison of Dice-coefficient scores</figcaption></figure><p>5. Is the change worthy enough of the time and resources being spent on training the model?</p><p>Investing more time, effort, and money in collecting data and searching for better training mechanisms is important for success in this task and in making self-driving cars safe, and reliable.</p><p>The addition of two layers has increased a lot of parameters, but there is no significant increase in the dice score, but this can’t be directly attributed to the change in architecture, it is more due to the small size of the dataset and the small number of epochs and the difference can become more profound in high-resolution images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*rYf0hUuat-mZUHADgxz2xQ.png" /><figcaption>The actual training for previous models(left) vs. our model(right)</figcaption></figure><p>There are various other questions of interest for businesses, such as how to strategize data collection, how to ensure privacy and integrity of the data collected, how to strategize and create ways of experimenting fruitfully, how to carry out effective and applicable research, and so on. We all have to come together to understand the ins and outs of research, people, finance, industry, investors, technology, and customers to build a unique, evolving, and flourishing ecosystem for self-driving vehicles.</p><p>Details of the implementation can be found in the GitHub repository: <a href="https://github.com/EhsanMohd/UNet-and-Hybrid-UNet-for-Semantic-Segmentation">https://github.com/EhsanMohd/UNet-and-Hybrid-UNet-for-Semantic-Segmentation</a></p><p>Thank you, please follow me for more posts!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69dc6c11ea1a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>