Senasu commited on
Commit
8b08791
·
verified ·
1 Parent(s): 3d8d2a2

Uploaded main files

Browse files
Files changed (4) hide show
  1. app.py +75 -0
  2. best_model.pkl +3 -0
  3. diamonds.csv +0 -0
  4. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sklearn.pipeline import Pipeline
2
+ from sklearn.compose import ColumnTransformer
3
+ from sklearn.preprocessing import StandardScaler, OneHotEncoder
4
+ import streamlit as st
5
+ import pandas as pd
6
+ import joblib
7
+
8
+ # Load the data
9
+ df = pd.read_csv("diamonds.csv")
10
+ df["size"] = df["x"] * df["y"] * df["z"]
11
+
12
+ # Load the trained model
13
+ model = joblib.load('best_model.pkl')
14
+
15
+ # Define the preprocessor and pipeline
16
+ preprocessor = ColumnTransformer(
17
+ transformers=[
18
+ ("num", StandardScaler(), ["size", "carat"]),
19
+ ("cat", OneHotEncoder(), ["color", "clarity", "cut"])
20
+ ]
21
+ )
22
+ pipeline = Pipeline(steps=[("preprocessor", preprocessor), ("regressor", model)])
23
+
24
+ # Fit the pipeline on the data (optional, if you want to refit with the data)
25
+ pipeline.fit(df[["size", "carat", "cut", "color", "clarity"]], df["price"])
26
+
27
+ def price_prediction(size, carat, cut, color, clarity):
28
+ input_data = pd.DataFrame({
29
+ "size": [size],
30
+ "carat": [carat],
31
+ "cut": [cut],
32
+ "color": [color],
33
+ "clarity": [clarity]
34
+ })
35
+ prediction = pipeline.predict(input_data)[0]
36
+ return prediction
37
+
38
+ # Main function to render the Streamlit app
39
+ def main():
40
+ st.set_page_config(page_title="Diamond Price Prediction", layout="centered")
41
+
42
+ # App title and description
43
+ st.title("💎 Diamond Price Prediction 💎")
44
+ st.write("""
45
+ Enter the diamond features to predict its price.
46
+ Adjust the inputs to see how different characteristics affect the price.
47
+ """)
48
+
49
+ # Layout with columns for better organization
50
+ col1, col2 = st.columns([1, 1])
51
+
52
+ with col1:
53
+ size = st.number_input("Size (volume in mm³)", int(df["size"].min()), int(df["size"].max()))
54
+ carat = st.number_input("Carat Weight", float(df["carat"].min()), float(df["carat"].max()), step=0.01)
55
+
56
+ with col2:
57
+ cut = st.selectbox("Cut", df["cut"].unique())
58
+ color = st.selectbox("Color", df["color"].unique())
59
+
60
+ clarity = st.selectbox("Clarity", df["clarity"].unique(), key="clarity", index=0)
61
+
62
+ # Prediction button
63
+ if st.button("Predict Price"):
64
+ price = price_prediction(size, carat, cut, color, clarity)
65
+ price = float(price)
66
+
67
+ # Display the result with enhanced visualization
68
+ st.markdown(f"### Predicted Price: 💲 **${price:,.2f}**")
69
+ st.write("""
70
+ This is the estimated price based on the characteristics you provided.
71
+ Please note that the actual market price may vary.
72
+ """)
73
+
74
+ if __name__ == "__main__":
75
+ main()
best_model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ff9ff93cd6a119ced87b37aeacecdcd0f47483fa96bbeabd043c62951296e835
3
+ size 450464
diamonds.csv ADDED
The diff for this file is too large to render. See raw diff
 
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ streamlit
2
+ scikit-learn
3
+ joblib