import streamlit as st import pandas as pd import pickle import numpy as np import pandas as pd import seaborn as sns from sklearn.pipeline import Pipeline from sklearn.pipeline import make_pipeline from sklearn.model_selection import GridSearchCV from sklearn.model_selection import train_test_split from sklearn.model_selection import GridSearchCV from sklearn.model_selection import StratifiedKFold from sklearn.model_selection import cross_val_score from sklearn.metrics import classification_report from sklearn.metrics import accuracy_score from sklearn.base import BaseEstimator, TransformerMixin from sklearn.preprocessing import StandardScaler from sklearn.preprocessing import MinMaxScaler from sklearn.neighbors import KNeighborsClassifier from sklearn.linear_model import LogisticRegression from sklearn.ensemble import RandomForestClassifier from sklearn.ensemble import IsolationForest from sklearn.tree import DecisionTreeClassifier from fs import FeatureSelection from xgboost import XGBClassifier import warnings warnings.filterwarnings('ignore') from sklearn import set_config set_config(display="diagram") with open('mejor_modelo_tp4.pkl', 'rb') as f: modelo = pickle.load(f) # Define una función para hacer predicciones con el modelo def predecir(features): # Procesa los valores de features y hace predicciones con el modelo predicciones = modelo.predict(features) return predicciones # 'Unnamed: 0', 'acc_max', 'gyro_max', 'acc_kurtosis', 'gyro_kurtosis', # 'label', 'lin_max', 'acc_skewness', 'gyro_skewness', 'post_gyro_max', # 'post_lin_max', 'fall'] # Crea la aplicación Streamlit def app(): st.title('Ingrese los valores de las features') col1, col2, col3 = st.columns(3) with col1: feature1 = st.text_input('Unnamed: 0', value = 61) with col2: feature2 = st.text_input('acc_max', value = 26.310655) with col3: feature3 = st.text_input('gyro_max', value = 5.192876) col4, col5, col6 = st.columns(3) with col4: feature4 = st.text_input('acc_kurtosis', value = 17.569042) with col5: feature5 = st.text_input('gyro_kurtosis', value = 9.776727) with col6: feature6 = st.text_input('label', value = 'FOL') col7, col8, col9 = st.columns(3) with col7: feature7 = st.text_input('lin_max', value = 11.584056) with col8: feature8 = st.text_input('acc_skewness', value = 3.587634) with col9: feature9 = st.text_input('gyro_skewness', value = 2.848477) col10, col11, col12 = st.columns(3) with col10: feature10 = st.text_input('post_gyro_max', value = 4.691588) with col11: feature11 = st.text_input('post_lin_max', value = 10.684285) # with col12: # feature12 = st.text_input('3') # # # Crea los campos de entrada de texto para las features # feature1 = st.text_input('Unnamed: 0') # feature2 = st.text_input('acc_max') # feature3 = st.text_input('gyro_max') # feature4 = st.text_input('acc_kurtosis') # feature5 = st.text_input('gyro_kurtosis') # feature6 = st.text_input('label') # feature7 = st.text_input('lin_max') # feature8 = st.text_input('acc_skewness') # feature9 = st.text_input('gyro_skewness') # feature10 = st.text_input('post_gyro_max') # feature11 = st.text_input('post_lin_max') # Crea un botón para hacer predicciones con el modelo if st.button('Predecir'): # Convierte los valores de features en un DataFrame de Pandas features = pd.DataFrame({ 'Unnamed: 0': [feature1], 'acc_max': [feature2], 'gyro_max': [feature3], 'acc_kurtosis': [feature4], 'gyro_kurtosis': [feature5], 'label': [feature6], 'lin_max': [feature7], 'acc_skewness': [feature8], 'gyro_skewness': [feature9], 'post_gyro_max': [feature10], 'post_lin_max': [feature11], }) # if predecir(features) == 0: # predicciones = 'NO ' # else: # predicciones = '' if predecir(features) == [0]: respuesta = ' NO ' else: respuesta = ' SI ' st.write(f'Estos datos {respuesta}son compatibles con una caída') if st.button('Modelo'): st.write(modelo.named_steps) # Ejecuta la aplicación Streamlit if __name__ == '__main__': app()