marcossalinas commited on
Commit
a3da7d0
1 Parent(s): f51e1f8

Primer commit

Browse files
Files changed (2) hide show
  1. appMamamIA.py +141 -0
  2. lr_final.pkl +0 -0
appMamamIA.py ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from numpy import dtype
2
+ import streamlit as st
3
+ import pandas as pd
4
+ from sklearn.preprocessing import StandardScaler
5
+ import numpy as np
6
+ import joblib as jl
7
+
8
+
9
+ # VALORES POR DEFECTO QUE INDICAN CELULAS NO CANCEROSAS
10
+ # radius_mean 14.12
11
+ # texture_mean 19.28
12
+ # perimeter_mean 91.96
13
+ # area_mean 551,17
14
+ # compactness_mean 0.0092
15
+ # concavity_mean 0.061
16
+ # concave_points_mean 0.033
17
+ # area_se 24.5
18
+ # radius_worst 14.97
19
+ # texture_worst 25.41
20
+ # perimeter_worst 97.6
21
+ # area_worst 686.5
22
+ # smoothness_worst 0.1313
23
+ # compactness_worst 0.20
24
+ # concavity_worst 0.22
25
+ # concave points_worst 0.09
26
+
27
+
28
+ col=['radius_mean', 'texture_mean', 'perimeter_mean',
29
+ 'area_mean', 'compactness_mean', 'concavity_mean',
30
+ 'concave points_mean', 'area_se', 'radius_worst', 'texture_worst',
31
+ 'perimeter_worst', 'area_worst', 'smoothness_worst',
32
+ 'compactness_worst', 'concavity_worst', 'concave points_worst']
33
+
34
+
35
+ modnames=['mlp_final.pkl','svm_final.pkl','lr_final.pkl']
36
+
37
+ #@st.cache
38
+ def getScaler():
39
+ # Cargo el dataset para poder normalizar los valores recogidos en el formulario
40
+ print ("cargando dataset")
41
+ data=pd.read_csv('https://raw.githubusercontent.com/gitmecalvon/mamamIA/main/resources/data/cleaned/train_web.csv',sep=';')
42
+ print("dataset cargado")
43
+ scaler = StandardScaler()
44
+ scaler.fit(data)
45
+ return scaler
46
+
47
+
48
+ # cargandolos para poder usarlos desde un sidebar si da tiempo
49
+ def cargaModelos (indice):
50
+ print('Preparando el guardado de Modelos ' )
51
+ modelo=jl.load(modnames[indice])
52
+ return modelo
53
+
54
+ def interpreta (prediccion):
55
+ respuesta ="Los datos introducidos pronostican que son células de tipo "
56
+ if prediccion ==1:
57
+ respuesta= respuesta + "Maligno"
58
+ else:
59
+ respuesta= respuesta + "BENIGNO"
60
+ return respuesta
61
+
62
+
63
+ def contruyeFormulario():
64
+
65
+ # st.set_page_config(layout="wide")
66
+
67
+ st.title("Mama mIA")
68
+ st.markdown('<style>body{background-color: Black;}</style>',unsafe_allow_html=True)
69
+ html_temp = """ <div style ="background-color:Pink;padding:13px">
70
+ <h1 style ="color:black;text-align:center;">Algoritmo de ayuda a la predicción diagnóstica del Cáncer de mama</h1>
71
+ </div>"""
72
+ st.markdown(html_temp, unsafe_allow_html = True)
73
+
74
+ st.subheader("Por favor introduzca las medidas de la muestra")
75
+ form = st.form(key="formulario")
76
+ # col1, col2 = form.columns(2) # intento de dos columnas sin recurrir a html
77
+ # with col1:
78
+ radius_mean = form.number_input( label="Radio Promedio", min_value=0.00000, max_value=20.0,value=13.54, step=0.0001,format="%4f")
79
+ texture_mean = form.number_input(label="Textura Promedio", min_value=0.00000, max_value=36.0,value=14.36, step=0.0001,format="%4f")
80
+ perimeter_mean = form.number_input(label="Perímertro Promedio", min_value=0.00000, max_value=150.0,value=87.46, step=0.0001,format="%4f")
81
+ area_mean = form.number_input(label="Área Promedio", min_value=0.00000, max_value=1600.0,value=566.3, step=0.0001,format="%4f")
82
+ compactness_mean = form.number_input(label="Promedio de Compactabilidad", min_value=0.00000, max_value=1.0,value=0.08129, step=0.0001,format="%5f")
83
+ concavity_mean = form.number_input(label="Promedio de Concavidad", min_value=0.00000, max_value=1.0,value=0.06664, step=0.0001,format="%5f")
84
+ concave_points_mean = form.number_input(label="Puntos Cóncavos promedio", min_value=0.00000, max_value=1.0,value=0.04781, step=0.0001,format="%4f")
85
+ area_se = form.number_input(label="Area Error Estandar", min_value=0.00000, max_value=150.0,value=23.56, step=0.0001,format="%4f")
86
+ # with col2:
87
+ radius_worst = form.number_input(label="Radio worst ", min_value=0.00000, max_value=30.0,value=15.11, step=0.0001,format="%4f")
88
+ texture_worst= form.number_input(label="Textura worsk", min_value=0.00000, max_value=70.0,value=19.26, step=0.0001,format="%4f")
89
+ perimeter_worst = form.number_input(label="Perimetro worst", min_value=0.00000, max_value=99.70,value=0.0092, step=0.0001,format="%4f")
90
+ area_worst = form.number_input(label="Area ", min_value=0.00000, max_value=800.0,value=711.2, step=0.0001,format="%4f")
91
+ smoothness_worst = form.number_input(label="Suavidad worst", min_value=0.00000, max_value=1.0,value=0.144, step=0.0001,format="%4f")
92
+ compactness_worst = form.number_input(label="Compactabilidad worst", min_value=0.00000, max_value=2.0,value=0.1773, step=0.0001,format="%4f")
93
+ concavity_worst = form.number_input(label="Concavidad worst", min_value=0.00000, max_value=2.0,value=0.2390, step=0.0001,format="%4f")
94
+ concavepoints_worst = form.number_input(label="Puntos cóncavos worst", min_value=0.00000, max_value=2.0,value=0.1288, step=0.0001,format="%4f")
95
+
96
+ submit = form.form_submit_button(label="Predicción")
97
+
98
+ if submit:
99
+ # Escalamos los datos del formulario
100
+ scaler=getScaler()
101
+ nbnormaliz=scaler.transform ([[radius_mean, texture_mean, perimeter_mean ,area_mean , compactness_mean , concavity_mean ,
102
+ concave_points_mean , area_se , radius_worst , texture_worst ,perimeter_worst , area_worst , smoothness_worst ,
103
+ compactness_worst , concavity_worst , concavepoints_worst ]])
104
+
105
+ # Recuperamos el modelo
106
+ print ("cargando modelo")
107
+ print (modnames[2])
108
+ algoritmo=cargaModelos(2)
109
+
110
+ # Realizamos la prediccion
111
+
112
+ print ("Preparando la prediccion...")
113
+ prediccion=algoritmo.predict (nbnormaliz)
114
+ print (prediccion)
115
+ st.write ("")
116
+ st.write (interpreta (prediccion))
117
+
118
+
119
+ def main():
120
+
121
+ contruyeFormulario()
122
+
123
+ if __name__ == '__main__':
124
+ main()
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+
lr_final.pkl ADDED
Binary file (1.53 kB). View file