Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- pages/__init__.py +0 -0
- pages/metrics.py +52 -0
pages/__init__.py
ADDED
File without changes
|
pages/metrics.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from sklearn.metrics import mean_absolute_error, mean_squared_error, r2_score
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
import pickle
|
6 |
+
|
7 |
+
# Загрузка данных и модели с использованием кэша
|
8 |
+
@st.cache(allow_output_mutation=True)
|
9 |
+
def load_data_and_model():
|
10 |
+
df = pd.read_csv('Dataset/car_data.txt', sep=',')
|
11 |
+
final_model = CatBoostRegressor()
|
12 |
+
final_model.load_model('Model/best_model.cbm')
|
13 |
+
return df, final_model
|
14 |
+
|
15 |
+
# Загрузка данных и модели
|
16 |
+
df, final_model = load_data_and_model()
|
17 |
+
|
18 |
+
# Загрузка данных
|
19 |
+
with open('X_test_trimmed.pkl', 'rb') as f:
|
20 |
+
X_test_trimmed_loaded = pickle.load(f)
|
21 |
+
|
22 |
+
with open('y_test_trimmed.pkl', 'rb') as f:
|
23 |
+
y_test_trimmed_loaded = pickle.load(f)
|
24 |
+
|
25 |
+
# Заголовок страницы
|
26 |
+
st.title("Метрики модели")
|
27 |
+
|
28 |
+
# Построение гистограммы цен
|
29 |
+
plt.figure(figsize=(10, 6))
|
30 |
+
plt.hist(y_test_trimmed_loaded, bins=50, color='red', alpha=0.7, label='Цены на тестовой выборке')
|
31 |
+
plt.title('Распределение цен на автомобили')
|
32 |
+
plt.xlabel('Цена')
|
33 |
+
plt.ylabel('Количество автомобилей')
|
34 |
+
plt.legend()
|
35 |
+
st.pyplot()
|
36 |
+
|
37 |
+
# Предсказание на тестовых данных
|
38 |
+
y_pred_final = final_model.predict(X_test_trimmed_loaded)
|
39 |
+
|
40 |
+
# Вычисляем MAE, RMSE и R^2
|
41 |
+
mae_final = mean_absolute_error(y_test_trimmed_loaded, y_pred_final)
|
42 |
+
rmse_final = mean_squared_error(y_test_trimmed_loaded, y_pred_final, squared=False) # RMSE
|
43 |
+
r2_final = r2_score(y_test_trimmed_loaded, y_pred_final)
|
44 |
+
|
45 |
+
# Вывод метрик
|
46 |
+
st.write(f"Final Mean Absolute Error (MAE): {mae_final}")
|
47 |
+
st.write(f"Final Root Mean Squared Error (RMSE): {rmse_final}")
|
48 |
+
st.write(f"Final R^2 Score: {r2_final}")
|
49 |
+
|
50 |
+
# Возвращение на первую страницу
|
51 |
+
st.markdown("---")
|
52 |
+
st.markdown("[Вернуться к вводу данных](#main)")
|