<?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 Manar Alharbi on Medium]]></title>
        <description><![CDATA[Stories by Manar Alharbi on Medium]]></description>
        <link>https://medium.com/@manar.qalharbi?source=rss-6292d1e539a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*7qfitB2j2TWMOCw-cQXbvg.png</url>
            <title>Stories by Manar Alharbi on Medium</title>
            <link>https://medium.com/@manar.qalharbi?source=rss-6292d1e539a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 04:01:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@manar.qalharbi/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[Write an Algorithm for a Dog Identification App]]></title>
            <link>https://medium.com/@manar.qalharbi/write-an-algorithm-for-a-dog-identification-app-cc453d2c63b1?source=rss-6292d1e539a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc453d2c63b1</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[image-classification]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Manar Alharbi]]></dc:creator>
            <pubDate>Tue, 03 Sep 2019 20:30:52 GMT</pubDate>
            <atom:updated>2019-09-03T20:30:52.804Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*B4Q-dizzeUxIA34JefyDxQ.jpeg" /></figure><h3>Project Definition</h3><h4>Project Overview</h4><p>This article is about a dog breed classifier model. For this purpose, I built an image classification model with convolutional neural network (CNN). The model could be used as part of a mobile or web app. It accepts any user-supplied image as input. If a dog is detected in the image, it will provide an estimate of the dog’s breed. If a human is detected, it will provide an estimate of the dog breed that is most resembling.</p><p>The image below displays potential sample output of your finished project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/227/1*UpMwXKyNeEM0vcGdcxlM2w.png" /><figcaption>Figure 1: sample output.</figcaption></figure><h4>Problem Statement</h4><p>To classify different dog breeds, I created an algorithm to combine three functions, human face images detection, dog images detection, and CNN model to infers dog breeds.</p><h4>Metrics</h4><p>I needed to measure the performance of model in two cases:</p><p><em>Case 1:</em> The model’s ability to distinguish if the input image is for dog, human, or others. This can be calculated with the equation below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/393/1*B3mPj-jklb32QvSBN73TuA.png" /><figcaption>Figure 2: accuracy equation.</figcaption></figure><p><em>Case 2:</em> The model’s ability to predict the correct dog breed. I used the CNN to test how well it identifies breed within our test dataset of dog images.</p><h3>Analysis</h3><h4>Data Exploration</h4><p>In order to develop the algorithm, I needed dog and human face images datasets. The dog dataset has<strong> </strong>133 total dog categories and 8351 total dog images that are divided into 6680 training data, 835 validation data, and 836 test data. While, the human faces dataset has 13233 images.</p><h4>Data Visualization</h4><p>The distribution of dog breeds images in train data (see image below). Most of dog breeds have about 50 images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*43g7GfY25ckVD4yDQwzaIg.png" /><figcaption>Figure 3: The distribution of dog breeds images in train data.</figcaption></figure><p>The distribution of dog breeds images in test data (see image below). Most of dog breeds have about 40 images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*ZoNSSy-37cEmptImvZ1dQw.png" /><figcaption>Figure 4: The distribution of dog breeds images in test data.</figcaption></figure><p>The distribution of dog breeds images in valid data (see image below). Most of dog breeds have about 40 images.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*SDyJAnwipn3JuhOucK26VA.png" /><figcaption>Figure 5: The distribution of dog breeds images in valid data.</figcaption></figure><h3>Methodology</h3><h4>Data Preprocessing</h4><p><strong><em>For human images,</em></strong> before using any of the face detectors, it is standard procedure to convert the images to grayscale.<strong> </strong>To do so, I used <a href="https://docs.opencv.org/2.4/modules/objdetect/doc/cascade_classification.html">detectMultiScale </a>function, that executes <a href="https://docs.opencv.org/3.4/db/d28/tutorial_cascade_classifier.html">the Haar cascade classifier</a> stored in face_cascade and takes the grayscale image as a parameter.</p><p><strong><em>For dog images,</em></strong><em> </em>the images were converted to 4D tensor and then applied <a href="https://github.com/keras-team/keras/blob/master/keras/applications/imagenet_utils.py">preprocess_input</a> to get the 4D tensor ready for any pre-trained model in Keras.</p><h4>Implementation</h4><p><strong>Step 1: Detect Human faces</strong></p><p>I used OpenCV’s implementation of <a href="https://docs.opencv.org/trunk/db/d28/tutorial_cascade_classifier.html">Haar feature-based cascade classifiers</a> to detect human faces in images. OpenCV provides many pre-trained face detectors, stored as XML files on <a href="https://github.com/opencv/opencv/tree/master/data/haarcascades">github</a>. I have downloaded one of these detectors and stored it in the haarcascades directory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*_uOHlcSGORVJ6TwimUG8EQ.png" /><figcaption>Figure 6: <em>face_detector</em> procedure code.</figcaption></figure><p>The <em>face_detector</em> procedure works as following:</p><ol><li>Take a string-valued file path to an image as input.</li></ol><p>2. Load color (BGR) image.</p><p>3. Convert image to grayscale.</p><p>4. Use pre-trained face detector to find a human face.</p><p>5. Return True if a human face is detected in an image and False otherwise.</p><p><strong>Step 2: Detect Dogs</strong></p><p>I used a pre-trained <a href="https://keras.io/applications/#resnet">ResNet-50 model</a>. The model is for image classification with weights trained on ImageNet. Given an image, this pre-trained ResNet-50 model returns a prediction (derived from the available categories in ImageNet) for the object that is contained in the image.</p><p>The dog detector procedure works as following:</p><ol><li>Import RestNet50 model.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/1*no2f4lEqqXZsfPw45hc4DA.png" /><figcaption>Figure 7: import RestNet50 model.</figcaption></figure><p>2. Convert image to 4D tensor,</p><ul><li>Load RGB image as PIL.Image.Image type,</li><li>Convert PIL.Image.Image type to 3D tensor with shape (224, 224, 3),</li><li>Convert 3D tensor to 4D tensor with shape (1, 224, 224, 3) and return 4D tensor.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*W_-2EzbM1wgcahsGYYzr8w.png" /><figcaption>Figure 8: convert image to 4D tensor procedure.</figcaption></figure><p>3. Prepare 4D tensor for ResNet-50 using (preprocess_input function).</p><p>4. Use pre-trained ResNet-50 model to return a prediction by,</p><ul><li>Take the argmax of the predicted probability vector,</li><li>Obtain an integer corresponding to the model’s predicted object class, using this <a href="https://gist.github.com/yrevar/942d3a0ac09ec9e5eb3a">dictionary</a>,</li><li>Check if the predicted value is between 151 and 268 (inclusive).</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/608/1*b98tU1YeWss3lNDOoskzLQ.png" /><figcaption>Figure 9: Use pre-trained ResNet-50 model returns a prediction.</figcaption></figure><p>5. Return True if a dog is detected in an image (and False if not)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*jzj6XusaBgJ7QpKTTMVI2A.png" /><figcaption>Figure 10: dog detector function.</figcaption></figure><p><strong>Step 3: Create a CNN to Classify Dog Breeds (from Scratch)</strong></p><p>I created a CNN that classifies dog breeds, from scratch (without use of transfer learning). Model Architecture can be found below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*s89whA9LpFiJNg8WldDbjQ.png" /><figcaption>Figure 11: CNN Model Architecture (from scratch).</figcaption></figure><p>I added three 2D convolution layers, three Max Pooling layers, a global average pooling layer, and a dense layer activated with SoftMax.</p><p>In this CNN architecture, I used 2D convolution layer, because it deals with 4D tensor<a href="https://keras.io/layers/convolutional/">[1]</a>. In addition, I used Max Pooling, that reduces the number of parameters within the model <a href="https://computersciencewiki.org/index.php/Max-pooling_/_Pooling">[2]</a>. Also, I used the Global Average Pooling, that minimize overfitting by reducing the total number of parameters in the model<a href="https://alexisbcook.github.io/2017/global-average-pooling-layers-for-object-localization/">[3]</a>. Complications of this CNN are that, it takes long training time and it has very low accuracy.</p><h4>Refinement</h4><p><strong>Create a CNN to Classify Dog Breeds (using Transfer Learning)</strong></p><p>To increase the model accuracy, I created a CNN using ResNet-50 bottleneck features. Model Architecture can be found below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/508/1*LVyy_sRYa04XmZ-ARic6Kw.png" /><figcaption>Figure 12: CNN Model Architecture (using Transfer Learning).</figcaption></figure><p>I added a global average pooling layer and a dense layer activated with SoftMax. I used the Global Average Pooling to reduce the total number of parameters in the model<a href="https://alexisbcook.github.io/2017/global-average-pooling-layers-for-object-localization/">[3]</a>. I used SoftMax function, because it’s suitable for multi-classification mode, as it calculates the probabilities of each class and selects class with the highest probability<a href="https://dataaspirant.com/2017/03/07/difference-between-softmax-function-and-sigmoid-function/">[4]</a>.</p><p><strong>Write my own dog breed classifier Algorithm</strong></p><p>This algorithm takes an image path as input, then determines whether the image contains a human, dog, or neither.</p><ul><li>If a dog is detected, return the predicted breed.</li><li>If a human is detected, return the resembling dog breed.</li><li>If neither is detected, provide output that indicates an error.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/421/1*aucGYUZRC6lQruumVip9YA.png" /><figcaption>Figure 13: show_img function.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/1*mfe_zRtu3qQvKzgrhMEgbQ.png" /><figcaption>Figure 14: my dog breed classifier algorithm.</figcaption></figure><h3>Results</h3><h4>Model Evaluation and Validation</h4><p>To test the performance of my algorithm, I calculated the accuracy of human face and dog image detection, both of them gave me a good result. Then, I tried out my model on the test dataset of dog images, the test accuracy was about 82%, which I consider as good.</p><h4>Justification</h4><p>I applied the model on 6 samples, 2 dogs, 2 human, and 2 others. The model was able to determine whether the image contains a human, dog, or neither. It predicted the correct dog breed for both dogs.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*3JE4yTx2JFDqu3vT_sUdKw.png" /><figcaption>Figure 15: Beagle dog sample.</figcaption></figure><p>When I entered Sandra Bullock face, it resembled her with Maltese dog breed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/241/1*X1_2goWMGczltkL_vLAdUg.png" /><figcaption>Figure 16: Human sample.</figcaption></figure><p>When I entered a flower image, it didn’t recognize it as a dog or a human.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/187/1*g_lqBUrCmIm6-kK5bIPQIQ.png" /><figcaption>Figure 17: flower image sample.</figcaption></figure><p>The model output is good, but it can be improved by using data augmentation, trying different model architectures, or simply adding more training data.</p><h3>Conclusion</h3><h4>Reflection</h4><p>In summary, the steps performed to build a CNN image classification model, that predicts dog breeds are:</p><ol><li>Create a human face detection function.</li><li>Create a dog detection function.</li><li>Create a CNN model based on pretrained model.</li><li>Train, validate, and test the model.</li><li>Finally, write a function, that takes an image path as input, and return the predicted dog breed.</li></ol><p>What I found exhausting is choosing the right model and the model’s long training time. But, what I found interesting is that if supplied an image of a human, the model will identify the resembling dog breed.</p><h4>Improvement</h4><p>As I discussed earlier, my model can be improved by data augmentation, choosing a different model architecture, or add more data to training data. Although, these changes might affect the model’s training speed, but they will help increasing the model’s accuracy. Also, One of the drawbacks of face detection algorithm, is that it only accepts human images with a clear view of a face. To solve it, a convolution kernel can be used instead, since it’s able to recognize partially covered faces with high quality training data <a href="https://towardsdatascience.com/whats-the-difference-between-haar-feature-classifiers-and-convolutional-neural-networks-ce6828343aeb">[5]</a>.</p><h3>References</h3><ol><li><a href="https://keras.io/layers/convolutional/">https://keras.io/layers/convolutional/</a></li><li><a href="https://computersciencewiki.org/index.php/Max-pooling_/_Pooling">https://computersciencewiki.org/index.php/Max-pooling_/_Pooling</a></li><li><a href="https://alexisbcook.github.io/2017/global-average-pooling-layers-for-object-localization/">https://alexisbcook.github.io/2017/global-average-pooling-layers-for-object-localization/</a></li><li><a href="https://dataaspirant.com/2017/03/07/difference-between-softmax-function-and-sigmoid-function/">https://dataaspirant.com/2017/03/07/difference-between-softmax-function-and-sigmoid-function/</a></li><li><a href="https://towardsdatascience.com/whats-the-difference-between-haar-feature-classifiers-and-convolutional-neural-networks-ce6828343aeb">https://towardsdatascience.com/whats-the-difference-between-haar-feature-classifiers-and-convolutional-neural-networks-ce6828343aeb</a></li></ol><p>To explore more about this project, see the link to my Github available <a href="https://github.com/ManarAlharbi/DSND-Teram2-Dog_Breeds_Classifier.git">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc453d2c63b1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Are accommodation expensive in Seattle?]]></title>
            <link>https://medium.com/@manar.qalharbi/are-accommodation-expensive-in-seattle-3406a38e84e2?source=rss-6292d1e539a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/3406a38e84e2</guid>
            <category><![CDATA[pricing]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[airbnb]]></category>
            <category><![CDATA[data-analysis]]></category>
            <dc:creator><![CDATA[Manar Alharbi]]></dc:creator>
            <pubDate>Sat, 31 Aug 2019 18:32:28 GMT</pubDate>
            <atom:updated>2019-08-31T18:32:28.536Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*X3SQrCE_TmFhq74Lw_TFxg.jpeg" /><figcaption>Seattle Airbnb homes</figcaption></figure><h3>Introduction</h3><p>Many guests and hosts use Airbnb for accommodation services. So, if you’re a host looking for information about the price of nearly accommodation places, or when usually people visit Seattle. Also, If you’re a traveler wondering when to visit Seattle, or which neighborhoods to choose. Then this article might be helpful for you.</p><h4>I analyzed Seattle Airbnb Open Data, to answer the following questions:</h4><ol><li>What are the busiest times of the year to visit Seattle? By how much do prices spike?</li><li>Which neighborhoods are more crowded and expensive?</li><li>Which features help in predicting price?</li></ol><h3>Part 1: What are the busiest times of the year to visit Seattle? By how much do prices spike?</h3><p>To answer this question, I used calendar dataset.</p><p>For the first part of the question, <em>“What are the busiest times of the year to visit Seattle?”</em>, I counted the average day availability for each month. As a result, I found out that, Seattle is fairly active most of the year, but mostly in these three months, December, March, and October. On the other hand, January, February and July are less active.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*Z71VIFGG_bNaivgvNyUg5Q.png" /><figcaption>Figure 1: Which months are active?</figcaption></figure><p>Then, I investigated more to know what are the busiest days for active months, it turned out that, the end of each month is where most people visit Seattle, even for inactive months.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*OqSgGfpUd70sJCbCzaqIcw.png" /><figcaption>Figure 2: Available days for active months</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/1*7_XnX75er-ooH-McUXYX0Q.png" /><figcaption>Figure 3: Available days for inactive months</figcaption></figure><p>For the second part of the question, <em>“By how much do prices spike?”</em>, I took the average price for each month. Overall, prices increase in summer season, mostly in June, July and August. Conversely, they decrease in winter season in January, February, and March.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/1*u83X_hqZcRWKNpaBRxJTtA.png" /><figcaption>Figure 4: Price variance among months</figcaption></figure><p>So, as a piece of advice, visit Seattle in January or February, since these months are less crowded and cheaper.</p><h3>Part 2: Which neighborhoods are more crowded and expensive?</h3><p>To answer this question, I used listings dataset, which includes full descriptions and average review score. I only considered the listings ID, neighborhood groups, and price features for the analysis.</p><p>To determine which neighborhoods are expensive, I calculated the average price for each neighborhood group. As a result, I found out that, Magnolia, Queen Anne, Downtown, and Cascade are more expensive. While Delridge, Northgate, Rainier Valley, and Lake City are cheaper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*prsa9wJI-ploRbTSx_YBoA.png" /><figcaption>Figure 5: Which neighborhoods are more expensive?</figcaption></figure><p>To determine which neighborhoods are crowded, I counted the average number of listings in each neighborhood.</p><p>I found out that Capitol Hill, Downtown, and Central Area are more crowded. On the hand, Interbay, Seward Park, Magnolia, and Lake City are less crowded.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*LPkEEymYctdkvvwoufr6Xw.png" /><figcaption>Figure 6: Which neighborhoods are more crowded?</figcaption></figure><p>So, If you are looking for a cheap place and less crowded, then Lake City is the best option. If you’re fine with high prices, but you want a calm place with fewer accommodation places, then go to Magnolia. Unless you want a place with many places, then you should definitely visit the Downtown.</p><h3>Part 3: Which features help in predicting price?</h3><p>I used listings dataset after removing unnecessary features and cleaning data. I divided data into training and testing sets.</p><p><strong>Then I trained four models:</strong></p><ol><li>linear regression model</li><li>linear regression model with lasso regularization</li><li>linear regression model with ElasticNet regularization</li><li>Random Forest Regression model</li></ol><p>After calculating the Root Mean Square Error (RMSE), I chose the model with the lowest value, which was the Random Forest Regression model. Then, I improved the model by choosing the optimal parameters. After that, I calculated the feature importance and picked the top 10 features.</p><h4>These Features are:</h4><ol><li><strong>bedrooms:</strong> The number of bedrooms</li><li><strong>weekly_price: </strong>The weekly cost of the room</li><li><strong>bathrooms:</strong> The number of bathrooms</li><li><strong>room_type_Entire home/apt:</strong> Airbnb hosts can list entire homes/apartments, private or shared rooms</li><li><strong>cleaning_fee: </strong>The cost of cleaning service</li><li><strong>calendar_updated_13 months ago:</strong> The last time, the room was reserved</li><li><strong>accommodates:</strong> The number of people to be accommodated</li><li><strong>security_deposit:</strong> The security deposit amount</li><li><strong>reviews_per_month:</strong> The number of monthly reviews</li><li><strong>availability_365:</strong> Number of available days listed</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E72SN9xWdqJAR5wYSecbuA.png" /><figcaption>Figure 7: What features help in predicting price?</figcaption></figure><h3>Conclusion</h3><p>In this article, we took a look at Seattle Airbnb Open Data to extract useful information, that might help travelers and hosts in making better decisions.</p><h4>The main findings are:</h4><ul><li>December, March, and October are the busiest months of the year, while January, February and July are the least.</li><li>prices increase in summer season and decrease in winter season.</li><li>Magnolia, Queen Anne, Downtown, and Cascade are more expensive.</li><li>Delridge, Northgate, Rainier Valley, and Lake City are cheaper</li><li>Capitol Hill, Downtown, and Central Area are more crowded.</li><li>Interbay, Seward Park, Magnolia, and Lake City are less crowded.</li><li>The number of bedrooms and bathrooms, the weekly cost of the listing, and the cost of cleaning service are the most important factor in determine listings price.</li></ul><p>To see more about this analysis, see the link to my Github available <a href="https://github.com/ManarAlharbi/DSND-Teram2-Seattle_Airbnb_Data_Analysis">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3406a38e84e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>