Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -69,45 +69,64 @@ st.write("Predictions have been logged. Check your logs for details.")
|
|
69 |
"""
|
70 |
import streamlit as st
|
71 |
import pandas as pd
|
72 |
-
from transformers import pipeline
|
73 |
-
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, confusion_matrix
|
74 |
import seaborn as sns
|
75 |
import matplotlib.pyplot as plt
|
|
|
|
|
76 |
|
77 |
# Load data
|
78 |
data = pd.read_excel("ResponseOpenPredicted.xlsx")
|
79 |
st.title("Resume-based Personality Prediction by Serikov Ayanbek")
|
80 |
|
81 |
-
#
|
82 |
def calculate_metrics(true_labels, predicted_labels):
|
83 |
accuracy = accuracy_score(true_labels, predicted_labels)
|
84 |
precision, recall, f1_score, _ = precision_recall_fscore_support(true_labels, predicted_labels, average='weighted')
|
85 |
return accuracy, precision, recall, f1_score
|
86 |
|
|
|
87 |
accuracy_f, precision_f, recall_f, f1_score_f = calculate_metrics(data['True_label'], data['Predicted_F'])
|
88 |
accuracy_m, precision_m, recall_m, f1_score_m = calculate_metrics(data['True_label'], data['Predicted_M'])
|
89 |
|
90 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
conf_matrix_f = confusion_matrix(data['True_label'], data['Predicted_F'])
|
92 |
conf_matrix_m = confusion_matrix(data['True_label'], data['Predicted_M'])
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
fig, ax = plt.subplots(1, 2, figsize=(12, 6))
|
102 |
-
data['Predicted_F'].value_counts().plot(kind='bar', ax=ax[0], color='blue')
|
103 |
-
ax[0].set_title('Distribution of Predictions for Female Inputs')
|
104 |
-
ax[0].set_xlabel('Predicted Labels')
|
105 |
-
ax[0].set_ylabel('Frequency')
|
106 |
-
|
107 |
-
data['Predicted_M'].value_counts().plot(kind='bar', ax=ax[1], color='purple')
|
108 |
-
ax[1].set_title('Distribution of Predictions for Male Inputs')
|
109 |
-
ax[1].set_xlabel('Predicted Labels')
|
110 |
-
ax[1].set_ylabel('Frequency')
|
111 |
-
|
112 |
-
plt.tight_layout()
|
113 |
-
plt.show()
|
|
|
69 |
"""
|
70 |
import streamlit as st
|
71 |
import pandas as pd
|
|
|
|
|
72 |
import seaborn as sns
|
73 |
import matplotlib.pyplot as plt
|
74 |
+
from sklearn.metrics import accuracy_score, precision_recall_fscore_support, confusion_matrix
|
75 |
+
|
76 |
|
77 |
# Load data
|
78 |
data = pd.read_excel("ResponseOpenPredicted.xlsx")
|
79 |
st.title("Resume-based Personality Prediction by Serikov Ayanbek")
|
80 |
|
81 |
+
# Function to calculate metrics
|
82 |
def calculate_metrics(true_labels, predicted_labels):
|
83 |
accuracy = accuracy_score(true_labels, predicted_labels)
|
84 |
precision, recall, f1_score, _ = precision_recall_fscore_support(true_labels, predicted_labels, average='weighted')
|
85 |
return accuracy, precision, recall, f1_score
|
86 |
|
87 |
+
# Metrics Calculation
|
88 |
accuracy_f, precision_f, recall_f, f1_score_f = calculate_metrics(data['True_label'], data['Predicted_F'])
|
89 |
accuracy_m, precision_m, recall_m, f1_score_m = calculate_metrics(data['True_label'], data['Predicted_M'])
|
90 |
|
91 |
+
# Plotting function for confusion matrices
|
92 |
+
def plot_confusion_matrix(conf_matrix, title):
|
93 |
+
fig, ax = plt.subplots()
|
94 |
+
sns.heatmap(conf_matrix, annot=True, fmt="d", cmap="Blues", ax=ax)
|
95 |
+
plt.title(title)
|
96 |
+
plt.xlabel('Predicted Labels')
|
97 |
+
plt.ylabel('True Labels')
|
98 |
+
st.pyplot(fig)
|
99 |
+
|
100 |
+
# Plotting function for distribution of predictions
|
101 |
+
def plot_predictions_distribution(data, column, title):
|
102 |
+
fig, ax = plt.subplots()
|
103 |
+
sns.countplot(x=column, data=data, palette="viridis")
|
104 |
+
plt.title(title)
|
105 |
+
plt.xlabel('Predicted Labels')
|
106 |
+
plt.ylabel('Count')
|
107 |
+
st.pyplot(fig)
|
108 |
+
|
109 |
+
# Streamlit app structure
|
110 |
+
st.title('Model Performance Evaluation')
|
111 |
+
|
112 |
+
st.subheader('Performance Metrics')
|
113 |
+
st.write(f"Accuracy for Predicted_F: {accuracy_f:.2%}")
|
114 |
+
st.write(f"Precision for Predicted_F: {precision_f:.2%}")
|
115 |
+
st.write(f"Recall for Predicted_F: {recall_f:.2%}")
|
116 |
+
st.write(f"F1-Score for Predicted_F: {f1_score_f:.2%}")
|
117 |
+
st.write(f"Accuracy for Predicted_M: {accuracy_m:.2%}")
|
118 |
+
st.write(f"Precision for Predicted_M: {precision_m:.2%}")
|
119 |
+
st.write(f"Recall for Predicted_M: {recall_m:.2%}")
|
120 |
+
st.write(f"F1-Score for Predicted_M: {f1_score_m:.2%}")
|
121 |
+
|
122 |
+
st.subheader('Confusion Matrices')
|
123 |
conf_matrix_f = confusion_matrix(data['True_label'], data['Predicted_F'])
|
124 |
conf_matrix_m = confusion_matrix(data['True_label'], data['Predicted_M'])
|
125 |
+
plot_confusion_matrix(conf_matrix_f, 'Confusion Matrix for Predicted_F')
|
126 |
+
plot_confusion_matrix(conf_matrix_m, 'Confusion Matrix for Predicted_M')
|
127 |
+
|
128 |
+
st.subheader('Distribution of Prediction Results')
|
129 |
+
st.write("Distribution for Predicted_F")
|
130 |
+
plot_predictions_distribution(data, 'Predicted_F', 'Distribution of Predictions for Female Demographic')
|
131 |
+
st.write("Distribution for Predicted_M")
|
132 |
+
plot_predictions_distribution(data, 'Predicted_M', 'Distribution of Predictions for Male Demographic')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|