<?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 Dhrumil Patel on Medium]]></title>
        <description><![CDATA[Stories by Dhrumil Patel on Medium]]></description>
        <link>https://medium.com/@dhrumilpatel02?source=rss-f2873a11509f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*0jcZI0NyMpOWL3aIMnsyEA.jpeg</url>
            <title>Stories by Dhrumil Patel on Medium</title>
            <link>https://medium.com/@dhrumilpatel02?source=rss-f2873a11509f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:28:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dhrumilpatel02/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[Predicting diamond prices using basic measurement metrics]]></title>
            <link>https://medium.com/data-science/predicting-diamond-prices-using-basic-measurement-metrics-bc8ba821c8f6?source=rss-f2873a11509f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc8ba821c8f6</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[analytics]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Dhrumil Patel]]></dc:creator>
            <pubDate>Wed, 13 May 2020 08:27:25 GMT</pubDate>
            <atom:updated>2020-05-16T03:26:18.094Z</atom:updated>
            <content:encoded><![CDATA[<h3>How machine learning can predict the price of the diamond you desire to buy</h3><h4>Predicting diamond prices using basic measurement metrics.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VQbogBPJUxpT32a-" /><figcaption>Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">chuttersnap</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>I want to buy my mother a diamond ring as soon as I have enough money. The other day I went on Google and searched up its prices, but I didn’t know what metrics drove those prices. Therefore, I decided to apply some machine learning techniques to figure out what drives the price of a flawless diamond ring!</p><h3>Objective</h3><p>To build a web application where users can look up a predicted price for their desired diamonds.</p><h3>Data</h3><p>For this project, I used a <a href="https://github.com/pycaret/pycaret/blob/master/datasets/diamond.csv">dataset</a> from pycaret’s dataset folder on GitHub, performed data preprocessing transformations, and built a regression model to predict the price ($326-$18,823) of the diamond using basic diamond measurement metrics. Each diamond in this dataset is given a price. The price of the diamond is determined by 7 input variables:</p><ol><li><strong>Carat Weight</strong>: 0.2Kg - 5.01Kg</li><li><strong>Cut</strong>: Fair, Good, Very Good, Premium, Ideal</li><li><strong>Color</strong>: from J (Worst) to D (Best)</li><li><strong>Clarity</strong>: I1 (Worst), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (Best)</li><li><strong>Polish</strong>: ID (Ideal), EX (Excellent), G (Good), VG (Very Good)</li><li><strong>Symmetry</strong>: ID (Ideal), EX (Excellent), G (Good), VG (Very Good)</li><li><strong>Report</strong>: AGSL (American Gem Society Laboratories), GIA (Gemological Institute of America)</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/456/1*R75fqXl3B500vg8nl_xyTA.jpeg" /></figure><h3>👉Tasks</h3><ol><li><strong>Model Training and Validation: </strong>Train, validate models, and develop a machine learning pipeline for deployment using Python (<a href="https://www.pycaret.org/">PyCaret</a>).</li><li><strong>Front End Web Application: </strong>Build a basic HTML front-end with an input form for independent variables (Carat Weight, Cut, Color, Clarity, Polish, Symmetry, Report).</li><li><strong>Back End Web Application:</strong> Using a <a href="https://flask.palletsprojects.com/en/1.1.x/">Flask</a><strong> </strong>Framework.</li><li><strong>Deployment of the web application:</strong> Using <a href="https://www.heroku.com/">Heroku</a>,<strong> </strong>once deployed, it will become publicly available and can be accessed via a Web URL.</li></ol><h3>💻 Project Workflow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*FjY7vxjIMooJNIomOFbglQ.png" /><figcaption>Machine Learning Workflow (from Training to Deployment on PaaS)</figcaption></figure><h3>Task 1 — Model Training and Validation</h3><p>Model Training and Validation is carried out in Python (Jupyter Notebooks) using PyCaret to develop a machine learning pipeline and train a regression model. I used the default preprocessing settings in PyCaret.</p><pre>from <strong>pycaret.regression import</strong> *</pre><pre>s2 = setup(data, target = &#39;Price&#39;, session_id = 123,<br>           normalize = <strong>True</strong>,<br>           polynomial_features = <strong>True</strong>, trigonometry_features = <strong>True</strong>, feature_interaction=<strong>True</strong>, <br>           bin_numeric_features= [&#39;Carat Weight&#39;]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*H4tGL_NWnPZFfwouYfFf7w.jpeg" /><figcaption>Comparison of the transformation in the dataset</figcaption></figure><p>This transformed the dataset and came down to 65 features for training as compared to only 8 features in the original dataset.</p><p>Model training and validation in PyCaret:</p><pre># Model Training and Validation <br>lr = <strong>create_model</strong>(&#39;lr&#39;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/431/1*FwCeBalylPwLsbmVOyV7Ig.jpeg" /><figcaption>10 Fold cross-validation of the Linear Regression Model</figcaption></figure><p>Here the Root Mean Square Error (<strong>RMSE</strong>) and Mean Absolute Percentage Error (<strong>MAPE</strong>) have been significantly impacted.</p><pre># plot the trained model<strong><br></strong>plot_model(lr)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/555/1*DYkg3lccdCl4BLPvHrD3_w.png" /><figcaption>Residual plot of the Linear Regression Model</figcaption></figure><p>After building the model, I saved it as a file that can be transferred to and consumed by other applications:</p><pre># save transformation pipeline and model <br>save_model(lr, &#39;deployment_28042020&#39;)</pre><p>Saving the model creates the entire transformation pipeline based on the configuration defined in the <strong>setup() </strong>function, inter-dependencies are taken care of too. The whole machine learning pipeline and the linear regression model is now saved in the <strong>save_model() </strong>function.</p><h3>Task 2 — <strong>Front End Web Application</strong></h3><p><strong>CSS Style Sheet<br></strong>CSS (Cascading Style Sheets) describes the presentation of a document written in HTML. It holds information such as color, font size, margins, etc. It is saved as a .css file that links to the HTML code.</p><pre>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;title&gt;Predict Diamond Price&lt;/title&gt;<br>  &lt;link href=&#39;<a href="https://fonts.googleapis.com/css?family=Pacifico&#39;">https://fonts.googleapis.com/css?family=Pacifico&#39;</a> rel=&#39;stylesheet&#39; type=&#39;text/css&#39;&gt;<br>&lt;link href=&#39;<a href="https://fonts.googleapis.com/css?family=Arimo&#39;">https://fonts.googleapis.com/css?family=Arimo&#39;</a> rel=&#39;stylesheet&#39; type=&#39;text/css&#39;&gt;<br>&lt;link href=&#39;<a href="https://fonts.googleapis.com/css?family=Hind:300&#39;">https://fonts.googleapis.com/css?family=Hind:300&#39;</a> rel=&#39;stylesheet&#39; type=&#39;text/css&#39;&gt;<br>&lt;link href=&#39;<a href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300&#39;">https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300&#39;</a> rel=&#39;stylesheet&#39; type=&#39;text/css&#39;&gt;<br>&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;{{ url_for(&#39;static&#39;, filename=&#39;./style.css&#39;) }}&quot;&gt;<br>  <br>&lt;/head&gt;</pre><p><strong>HTML<br></strong>For front-end web application I used a simple HTML template and a CSS style sheet for designing the input form. Here’s the HTML code snippet of the front-end page of our web application.</p><pre>&lt;body&gt;<br> &lt;div class=&quot;login&quot;&gt;<br> &lt;h1&gt;Predict Diamond Price&lt;/h1&gt;</pre><pre>&lt;!-- Form to enter new data for predictions  --&gt;<br>    &lt;form action=&quot;{{ url_for(&#39;predict&#39;)}}&quot;method=&quot;POST&quot;&gt;<br>      &lt;input type=&quot;text&quot; name=&quot;Carat Weight&quot; placeholder=&quot;Carat Weight&quot; required=&quot;required&quot; /&gt;&lt;br&gt;<br>     &lt;input type=&quot;text&quot; name=&quot;Cut&quot; placeholder=&quot;Cut&quot; required=&quot;required&quot; /&gt;&lt;br&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;Color&quot; placeholder=&quot;Color&quot; required=&quot;required&quot; /&gt;&lt;br&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;Clarity&quot; placeholder=&quot;Clarity&quot; required=&quot;required&quot; /&gt;&lt;br&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;Polish&quot; placeholder=&quot;Polish&quot; required=&quot;required&quot; /&gt;&lt;br&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;Symmetry&quot; placeholder=&quot;Symmetry&quot; required=&quot;required&quot; /&gt;&lt;br&gt;<br>        &lt;input type=&quot;text&quot; name=&quot;Report&quot; placeholder=&quot;Report&quot; required=&quot;required&quot; /&gt;&lt;br&gt;<br>        &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary btn-block btn-large&quot;&gt;Predict&lt;/button&gt;<br>    &lt;/form&gt;</pre><pre>&lt;br&gt;<br>   &lt;br&gt;<br> &lt;/div&gt;<br> {{pred}}</pre><pre>&lt;/body&gt;</pre><h3>Task 3— Back End Web Application</h3><p>I used the Flask framework to build the back-end web application. Here is the Flask code snippet for the back-end application.</p><pre>from flask import Flask,request, url_for, redirect, render_template, jsonify<br>from pycaret.regression import *<br>import pandas as pd<br>import pickle<br>import numpy as np</pre><pre>app = Flask(__name__)</pre><pre>model = load_model(&#39;deployment_28042020&#39;)<br>cols = [&#39;Carat Weight&#39;, &#39;Cut&#39;, &#39;Color&#39;, &#39;Clarity&#39;, &#39;Polish&#39;, &#39;Symmetry&#39;, &#39;Report&#39;]</pre><pre><a href="http://twitter.com/app">@app</a>.route(&#39;/&#39;)<br>def home():<br>    return render_template(&quot;home.html&quot;)</pre><pre><a href="http://twitter.com/app">@app</a>.route(&#39;/predict&#39;,methods=[&#39;POST&#39;])<br>def predict():<br>    int_features = [x for x in request.form.values()]<br>    final = np.array(int_features)<br>    data_unseen = pd.DataFrame([final], columns = cols)<br>    prediction = predict_model(model, data=data_unseen, round = 0)<br>    prediction = int(prediction.Label[0])<br>    return render_template(&#39;home.html&#39;,pred=&#39;Price of the Diamond is ${}&#39;.format(prediction))</pre><pre><a href="http://twitter.com/app">@app</a>.route(&#39;/predict_api&#39;,methods=[&#39;POST&#39;])<br>def predict_api():<br>    data = request.get_json(force=True)<br>    data_unseen = pd.DataFrame([data])<br>    prediction = predict_model(model, data=data_unseen)<br>    output = prediction.Label[0]<br>    return jsonify(output)</pre><pre>if __name__ == &#39;__main__&#39;:<br>    app.run(debug=True)</pre><h3>Task 4— <strong>Deployment of the Web Application</strong></h3><p>After training the model, building a machine learning pipeline, I deployed the web application on Heroku. I linked a GitHub repository to Heroku. The code for this project can be found on my GitHub repository <a href="http://github.com/dhrumilpatel02/diamond-price-prediction">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/993/1*niARTBE1C-YFsEL0_o0GdQ.jpeg" /><figcaption><a href="https://github.com/dhrumilpatel02/diamond-price-prediction">github.com/dhrumilpatel02/diamond-price-prediction</a></figcaption></figure><p>I deployed the web app on Heroku next, the app is published at URL:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/418/1*Iit66VbWpxkDG6V4RBpSTg.jpeg" /><figcaption><a href="https://diamond-price-prediction.herokuapp.com/">https://diamond-price-prediction.herokuapp.com/</a></figcaption></figure><p>I would like to thank the Founder and Principal Author of PyCaret, <a href="https://www.linkedin.com/in/profile-moez/">Moez Ali</a>. The project’s process inspiration came from his recent Medium <a href="https://towardsdatascience.com/build-and-deploy-your-first-machine-learning-web-app-e020db344a99">post</a>.</p><h3>Thanks for reading!</h3><p>You can reach me at:</p><ol><li>Follow/Connect with me on <strong>LinkedIn</strong> <a href="https://www.linkedin.com/in/dhrumilpatel02/">here</a>.</li><li>Follow me on <strong>GitHub</strong> <a href="https://github.com/dhrumilpatel02">here</a>.</li><li>Check out my <strong>website</strong> <a href="https://dhrumilpatel02.github.io/portfolio/">here</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc8ba821c8f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/predicting-diamond-prices-using-basic-measurement-metrics-bc8ba821c8f6">Predicting diamond prices using basic measurement metrics</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>