Metinhsimi commited on
Commit
f5055f6
·
verified ·
1 Parent(s): f931e35

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +86 -0
  2. cars.xls +0 -0
app.py ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ from sklearn.model_selection import train_test_split as tts
3
+ from sklearn.linear_model import LinearRegression
4
+ from sklearn.metrics import mean_squared_error, r2_score
5
+ from sklearn.pipeline import Pipeline
6
+ from sklearn.compose import ColumnTransformer
7
+ from sklearn.preprocessing import OneHotEncoder, StandardScaler
8
+ import streamlit as st
9
+
10
+ # Verileri yükleyin
11
+ df = pd.read_excel('cars.xls')
12
+
13
+ # Bağımlı ve bağımsız değişkenleri ayırın
14
+ x = df.drop('Price', axis=1)
15
+ y = df[['Price']]
16
+
17
+ # Eğitim ve test verilerine bölün
18
+ x1, x2, y1, y2 = tts(x, y, random_state=42, test_size=0.30)
19
+
20
+ # Veri ön işleme adımları
21
+ preprocessor = ColumnTransformer(
22
+ transformers=[
23
+ ('num', StandardScaler(), ['Mileage', 'Cylinder', 'Liter', 'Doors']),
24
+ ('cat', OneHotEncoder(handle_unknown='ignore'), ['Make', 'Model', 'Trim', 'Type'])
25
+ ]
26
+ )
27
+
28
+ # Pipeline oluşturma
29
+ model = LinearRegression()
30
+ pipeline = Pipeline(steps=[('preprocessor', preprocessor), ('regressor', model)])
31
+
32
+ # Modeli eğitme
33
+ pipeline.fit(x1, y1)
34
+
35
+ # Tahmin yapma
36
+ predictions = pipeline.predict(x2)
37
+
38
+ # Performans metrikleri hesaplama
39
+ rmse = mean_squared_error(y2, predictions, squared=False)
40
+ r2 = r2_score(y2, predictions)
41
+
42
+ print(f'RMSE: {rmse}')
43
+ print(f'R^2: {r2}')
44
+
45
+ def price_pred(make, model, trim, mileage, type, cylinder, liter, doors, cruise, sound, leather):
46
+ # Girdi verilerini bir DataFrame'e dönüştür
47
+ input_data = pd.DataFrame({
48
+ 'Make': [make],
49
+ 'Model': [model],
50
+ 'Trim': [trim],
51
+ 'Mileage': [mileage],
52
+ 'Type': [type],
53
+ 'Cylinder': [cylinder],
54
+ 'Liter': [liter],
55
+ 'Doors': [doors],
56
+ 'Cruise': [cruise],
57
+ 'Sound': [sound],
58
+ 'Leather': [leather]
59
+ })
60
+
61
+ # Tahmin yapın
62
+ prediction = pipeline.predict(input_data)[0]
63
+
64
+ return prediction
65
+
66
+ # Streamlit arayüzü
67
+ st.title("ML OPS Car Price Prediction :red_car:")
68
+ st.write("Enter Car Details to predict the price")
69
+
70
+ # Kullanıcı girdi alanları
71
+ make = st.selectbox("Mrka ", df['Make'].unique())
72
+ model = st.selectbox("Model ", df['Model'].unique())
73
+ trim = st.selectbox("Döşeme ", df['Trim'].unique())
74
+ mileage = st.number_input("Mil ",200,60000)
75
+ type = st.selectbox("Tip ", df['Type'].unique())
76
+ cylinder = st.number_input("Silindir ", min_value=0)
77
+ liter = st.number_input("Litre ", min_value=1,step=1, max_value=8)
78
+ doors = st.number_input("Kapı ", min_value=2, max_value=5)
79
+ cruise = st.selectbox("Cruise", [0, 1])
80
+ sound = st.selectbox("Sound", [0, 1])
81
+ leather = st.selectbox("Leather", [0, 1])
82
+
83
+ # Tahmin butonu
84
+ if st.button('Predict'):
85
+ price = price_pred(make, model, trim, mileage, type, cylinder, liter, doors, cruise, sound, leather)
86
+ st.success(f'Predicted Price: ${price}')
cars.xls ADDED
Binary file (142 kB). View file