Django Club

Diamond Price Prediction

Using Lasso Regression Model

After submitting the form, wait at least 10 seconds for the model to calculate and show the result.
Also, all entered float numbers must have at most 2 decimal points, like: 1.23

Model Description:

Regression is a supervised machine learning method for understanding the relationship between independent variables or features and a dependent variable or outcome. One of the algorithms used for regression is the “Lasso Regression”.
Here, we use the diamonds.csv dataset for regression purposes and you can download the dataset from the link on top of this page. This dataset has 9 features:
carat”, “cut”, “color”, “clarity”, “depth”, “table”, “x”, “y” and “z
And the prediction variable is: “Diamond Price”.
In the above form, you enter the values of 9 features and the model returns the Diamond Price in a pop-up form. As the diamond prices in dataset are from 326$ to 18823$, when you enter features values in form, there is a possibility for small negative numbers returned by lasso model like: -50$. Therefore, we converted all small negative prices to 0.
Also, 3 features of our dataset are Categorical and 6 of them are Numerical. Hence, for using Lasso Regression for this mixed dataset, we need to convert categorical features to numerical labels and then we could use the Lasso Regression method.
Notice that the values and ranges of each feature are as below:

Carat: weight of the diamond
0.2 < Carat < 5.01
Cut: quality of the cut
0 → Fair , 1 → Good, 2 → Ideal, 3 → Premium, 4 → Very Good
Color: diamond color
0 → D (Best Color) , 1 → E, 2 → F, 3 → G, 4 → H, 5 → I, 6 → J (Worst Color)
Clarity: a measurement of how clear the diamond is →
I1 (worst), SI2, SI1, VS2, VS1, VVS2, VVS1, IF (best)
X: length in mm
0 < X < 10.74
Y: width in mm
0 < Y < 58.9
Z: depth in mm
0 < Z < 31.8
Depth: total depth percentage = z / mean(x, y) = 2 * z / (x + y)
43 < Depth < 79
Table: width of top of diamond relative to widest point
43 < Table < 95

The sample code used to train a “Lasso Regression” model, is provided in the link on top of this page. Each time you run this form and predictions happen, the values will store in the database, and with the link “result” on top of this page, you will see the previous results of the model prediction. Your recent run will be added to the end of this list.