Mykes commited on
Commit
dfdcea4
·
verified ·
1 Parent(s): a3f9926

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -21,6 +21,7 @@ def load_model():
21
  model, scaler, data = load_model()
22
  feature_list = data['features']
23
  categorical_features = data['categorical_features']
 
24
  categorical_options = data['categorical_options']
25
  group_names = data['group_names']
26
 
@@ -33,7 +34,7 @@ def get_user_input():
33
  # Числовые признаки
34
  st.subheader('Числовые параметры')
35
  for feature in feature_list:
36
- if feature not in categorical_features:
37
  input_data[feature] = st.number_input(f'{feature}', value=0.0)
38
 
39
  # Категориальные признаки
@@ -55,18 +56,19 @@ if st.button('Выполнить классификацию'):
55
  # One-hot encoding для категориальных признаков
56
  input_df_encoded = pd.get_dummies(input_df, columns=categorical_features)
57
 
 
 
 
 
58
  # Убедитесь, что все необходимые столбцы присутствуют
59
  for col in feature_list:
60
  if col not in input_df_encoded.columns:
61
  input_df_encoded[col] = 0
62
 
63
- # Масштабирование числовых признаков
64
- numeric_cols = [col for col in feature_list if col not in categorical_features]
65
- input_df_encoded[numeric_cols] = scaler.transform(input_df_encoded[numeric_cols])
66
-
67
  # Получение предсказания
68
- prediction = model.predict(input_df_encoded[feature_list])
69
- probabilities = model.predict_proba(input_df_encoded[feature_list])[0]
 
70
 
71
  # Отображение результата
72
  st.success(f'Предсказанная группа: {group_names[str(prediction[0])]}')
@@ -74,4 +76,8 @@ if st.button('Выполнить классификацию'):
74
  # Вывод вероятностей
75
  st.write('Вероятности для каждой группы:')
76
  for i, prob in enumerate(probabilities):
77
- st.write(f'{group_names[str(i)]}: {prob:.2f}')
 
 
 
 
 
21
  model, scaler, data = load_model()
22
  feature_list = data['features']
23
  categorical_features = data['categorical_features']
24
+ numeric_features = data['numeric_features']
25
  categorical_options = data['categorical_options']
26
  group_names = data['group_names']
27
 
 
34
  # Числовые признаки
35
  st.subheader('Числовые параметры')
36
  for feature in feature_list:
37
+ if feature in numeric_features:
38
  input_data[feature] = st.number_input(f'{feature}', value=0.0)
39
 
40
  # Категориальные признаки
 
56
  # One-hot encoding для категориальных признаков
57
  input_df_encoded = pd.get_dummies(input_df, columns=categorical_features)
58
 
59
+ # Масштабирование числовых признаков
60
+ if numeric_features:
61
+ input_df_encoded[numeric_features] = scaler.transform(input_df_encoded[numeric_features])
62
+
63
  # Убедитесь, что все необходимые столбцы присутствуют
64
  for col in feature_list:
65
  if col not in input_df_encoded.columns:
66
  input_df_encoded[col] = 0
67
 
 
 
 
 
68
  # Получение предсказания
69
+ X_pred = input_df_encoded[feature_list]
70
+ prediction = model.predict(X_pred)
71
+ probabilities = model.predict_proba(X_pred)[0]
72
 
73
  # Отображение результата
74
  st.success(f'Предсказанная группа: {group_names[str(prediction[0])]}')
 
76
  # Вывод вероятностей
77
  st.write('Вероятности для каждой группы:')
78
  for i, prob in enumerate(probabilities):
79
+ st.write(f'{group_names[str(i)]}: {prob:.2f}')
80
+
81
+ # Добавим вывод введенных данных для проверки
82
+ st.write("\nВведенные данные:")
83
+ st.write(input_df)