Spaces:
Sleeping
Sleeping
Upload prediction.py
Browse files- prediction.py +18 -0
prediction.py
CHANGED
|
@@ -74,6 +74,14 @@ def run():
|
|
| 74 |
# y_cluster = []
|
| 75 |
#for rd in range(0, len(df_churn)): y_cluster.append(random.randint(0, 2)) # Random Generator for testing
|
| 76 |
df_churn['cluster'] = y_cluster
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
# Split Data into 3 Cluster DataFrames
|
| 79 |
df_cluster_0 = df_churn[df_churn['cluster'] == 0]
|
|
@@ -156,8 +164,18 @@ def run():
|
|
| 156 |
ax.set_ylabel(f'Average {column}')
|
| 157 |
ax.bar_label(ax.containers[0])
|
| 158 |
|
|
|
|
| 159 |
plt.tight_layout()
|
| 160 |
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
def tenureMonthToYear():
|
| 163 |
year = st.session_state.tenurem % 12
|
|
|
|
| 74 |
# y_cluster = []
|
| 75 |
#for rd in range(0, len(df_churn)): y_cluster.append(random.randint(0, 2)) # Random Generator for testing
|
| 76 |
df_churn['cluster'] = y_cluster
|
| 77 |
+
|
| 78 |
+
temp_cols = df_churn.columns.tolist()
|
| 79 |
+
new_cols = temp_cols[0:1] + temp_cols[-2:] + temp_cols[1:-2]
|
| 80 |
+
df_churn = df_churn[new_cols]
|
| 81 |
+
df_churn = df_churn.sort_values(by=['cluster'], ascending=True)
|
| 82 |
+
|
| 83 |
+
# Saving Result to Excel
|
| 84 |
+
df_churn.to_excel('model_result.xlsx', index=False)
|
| 85 |
|
| 86 |
# Split Data into 3 Cluster DataFrames
|
| 87 |
df_cluster_0 = df_churn[df_churn['cluster'] == 0]
|
|
|
|
| 164 |
ax.set_ylabel(f'Average {column}')
|
| 165 |
ax.bar_label(ax.containers[0])
|
| 166 |
|
| 167 |
+
# plt.style.use('dark_background')
|
| 168 |
plt.tight_layout()
|
| 169 |
st.pyplot(fig)
|
| 170 |
+
# plt.style.use('default')
|
| 171 |
+
|
| 172 |
+
with open('model_result.xlsx', 'rb') as file:
|
| 173 |
+
st.download_button(
|
| 174 |
+
label='💾 Download Prediction Result',
|
| 175 |
+
data=file,
|
| 176 |
+
file_name='model_result.xlsx',
|
| 177 |
+
mime='application/vnd.ms-excel'
|
| 178 |
+
)
|
| 179 |
|
| 180 |
def tenureMonthToYear():
|
| 181 |
year = st.session_state.tenurem % 12
|