Spaces:
Runtime error
Runtime error
| import numpy as np | |
| import pandas as pd | |
| import gradio as gr | |
| url = 'https://raw.githubusercontent.com/MiguelJ125/creditcard_Jaramillo/main/Vehicle_policies_2020.csv' | |
| df = pd.read_csv(url) | |
| df = df.drop(["pol_number"], axis = 1) | |
| df = df.drop(["claim_office"], axis = 1) | |
| df = df.drop(["credit_score"], axis = 1) | |
| df = df.drop(["annual_premium"], axis = 1) | |
| df = df.drop(["agecat"], axis = 1) | |
| df=df.dropna() | |
| cleanup_nums = {"area": {"A": 1, "B": 2, "C": 3, "D": 4, "F": 5, "E": 6}} | |
| df = df.replace(cleanup_nums) | |
| from datetime import datetime | |
| datetime = pd.to_datetime(df["date_of_birth"]) | |
| df["date_of_birth"] = datetime | |
| df = df.copy() | |
| df['date_of_birth'].dt.year | |
| ahora = pd.Timestamp('now') | |
| df['Edad'] = (ahora - df['date_of_birth']).astype('<m8[Y]') | |
| df = df.drop(["date_of_birth"], axis = 1) | |
| df = df.drop(["pol_eff_dt"], axis = 1) | |
| df = pd.get_dummies(df, columns = ["gender"], drop_first = True) | |
| cleanup_nums = {"veh_body": {"SEDAN": 1, "HBACK": 2, "STNWG": 3, "UTE": 4, "TRUCK": 5, "HDTOP": 6, "COUPE": 7, "PANVN": 8, "MIBUS": 9, "MCARA": 10, "CONVT": 11, "BUS": 12, "RDSTR": 13}} | |
| df = df.replace(cleanup_nums) | |
| df=df.drop(columns = ['claimcst0']) | |
| X = df.drop(columns = ['numclaims']) | |
| y = df['numclaims'] | |
| from sklearn.preprocessing import StandardScaler | |
| scaler = StandardScaler() | |
| X = scaler.fit_transform(X) | |
| from sklearn.model_selection import train_test_split | |
| X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.10, random_state=1) | |
| from sklearn.tree import DecisionTreeClassifier | |
| tree = DecisionTreeClassifier(max_depth = None) | |
| tree.fit(X_train, y_train) | |
| def predict_siniestros(area, traf, vage, tipov, valorv, edad, Gen): | |
| df = pd.DataFrame.from_dict({'area': [area], 'traffic_indexe': [traf], 'veh_age': [vage], 'veh_body': [tipov], 'veh_value': [valorv], 'Edad': [edad], 'gender_M': [Gen]}) | |
| pred=tree.predict(df) | |
| return {'En un año es probable que reclames al seguro': int(pred[0])} | |
| area = gr.inputs.Radio(['1', '2', '3', '4', '5', '6'], label="Area: del 1 al 6") | |
| traf = gr.inputs.Slider(minimum=0, maximum=200, default=100, label="Indice de trafico") | |
| vage = gr.inputs.Slider(minimum=0, maximum=30, default=1, label="Cantidad de años del vehiculo") | |
| tipov = gr.inputs.Radio(['1', '2', '3', '4', '5'], label="Tipo de auto (Sedan=1 Hback=2 Family=3 Utilitario=4 Camioneta=5") | |
| valorv = gr.inputs.Slider(minimum=0, maximum=10, default=1, label="Valor del vehiculo (u$/10.000)") | |
| edad = gr.inputs.Slider(minimum=16, maximum=100, default=18, label="Edad") | |
| Gen = gr.inputs.Radio(['1', '0'], label="Genero (F=0 M=1)") | |
| gr.Interface(predict_siniestros, [area, traf, vage, tipov, valorv, edad, Gen], "textbox", live=False, thumbnail="https://raw.githubusercontent.com/gradio-app/hub-titanic/master/thumbnail.png", analytics_enabled=False, title="Cuantas veces es probable que tengas que reclamar al seguro en el transcurso de un año", description="Predice la cantidad de veces que por algun siniestro deberas acudir al seguro, con el fin de elegir un plan mas adecuado a cada persona").launch(); | |