File size: 2,509 Bytes
0d7c039
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# Actualizado por: José Carlos Machicao, Fecha de actualización: 2024_07_08, Lima
# Esta vinculado a los PKL de https://sites.google.com/continental.edu.pe/edusights/inicio

# Importacion de librerias
import torch
import torch.nn as nn
import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler, MinMaxScaler
from sklearn.model_selection import train_test_split
from torch.utils.data import DataLoader, TensorDataset
import plotly.express as px
import streamlit as st
from es_class_nn import SimplePlusNN2
version_name = 'CON_31'

c1, c2 = st.columns([6,6])
with c2:
    st.image('logo_vidad.png', width=300, caption='https://www.continental.edu.pe/')

st.title("Predicción de Abandono o Permanencia")
st.write("Cargue el archivo PKL para visualizar el análisis de su contenido.")

uploaded_file = st.file_uploader("Cargar archivo: ", type='xlsx')

cat_sel = pd.read_excel('df_cat_prior.xlsx')
df_categ = pd.read_excel('lista_categorias.xlsx')
df_muestra = pd.read_excel('df_muestra_carga.xlsx')

if uploaded_file is not None:
    
    # Lectura del archivo de predicción    
    df_test = pd.read_excel(uploaded_file)
    verif = df_test.columns == df_muestra.columns
    st.write(verif.sum())
    df_scaled = pd.concat([df_muestra, df_test], axis=0, ignore_index=True)
    df_scaled = df_scaled.fillna(0)
    df = df_scaled.tail(len(df_test)).reset_index(drop=True)
    st.write(df)
    X = df.values
    X_test_tensor = torch.tensor(X.astype(np.float32), dtype=torch.float32)
    
    # Carga de Modelo Entrenado
    input_size = X_test_tensor.shape[1]
    num_classes = 2
    model = SimplePlusNN2(input_size, num_classes)
    data_path = ''
    dict_name = f'edusights_20240702_state_dict_{version_name}.pth'
    model.load_state_dict(torch.load(data_path+dict_name))
    model.eval()

    # Predicciones
    inputs = X_test_tensor
    outputs = model(inputs)
    outputs_show = outputs.detach().numpy().flatten()
    outputs_show[outputs_show > 0.60] = 1.0
    outputs_show[outputs_show < 0.40] = 0.0
    filtered_arr = outputs_show[(outputs_show == 0.0) | (outputs_show == 1.0)]
    df['Pred'] = filtered_arr
    st.write(df['Pred'])
    
    csv_out = df.to_csv(encoding='iso-8859-1')

    st.download_button(
        label="Descargar CSV",
        data=csv_out,
        file_name='predicciones_carga.csv',
        mime='text/csv'
    )
        
c3, c4 = st.columns([6,6])
with c3:
    st.image('gdmklogo.png', width=100, caption='Powered by GestioDinámica 2024')