Spaces:
Build error
Build error
| import gradio as gr | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| df = pd.read_csv("diabetes.csv") | |
| df.info() | |
| fig, axs = plt.subplots(4, 2, figsize=(15, 12)) | |
| axs = axs.flatten() | |
| sns.distplot(df["Pregnancies"], rug=True, color="#38b000", ax=axs[0]) | |
| sns.distplot(df["Glucose"], rug=True, color="#FF9933", ax=axs[1]) | |
| sns.distplot(df["BloodPressure"], rug=True, color="#522500", ax=axs[2]) | |
| sns.distplot(df["SkinThickness"], rug=True, color="#66b3ff", ax=axs[3]) | |
| sns.distplot(df["Insulin"], rug=True, color="#FF6699", ax=axs[4]) | |
| sns.distplot(df["BMI"], color="#e76f51", rug=True, ax=axs[5]) | |
| sns.distplot(df["DiabetesPedigreeFunction"], color="#03045e", rug=True, ax=axs[6]) | |
| sns.distplot(df["Age"], rug=True, color="#333533", ax=axs[7]) | |
| plt.show() | |
| bmi_outliers = df[df["BMI"] > 40] | |
| bmi_outliers["BMI"].shape | |
| df["Diabetes"] = df["Outcome"].apply(lambda x: "Diabetic" if x == 1 else "Not_Diabetic") | |
| df["BMI"] = df["BMI"].apply(lambda x: df.BMI.mean() if x > 40 else x) | |
| from pycaret.classification import * | |
| print("Hello 1") | |
| #Diab = setup(data = df,target = 'Diabetes',normalize=True, session_id=1,fix_imbalance = True) | |
| print("2") | |
| Diab = setup(data=df,target="Diabetes",normalize=True,session_id=1,fix_imbalance=True,numeric_features=["Pregnancies"],log_experiment=True,experiment_name="diabetes",ignore_features=["Outcome"],silent=True) | |
| best = compare_models(n_select=15) | |
| compare_model_results = pull() | |
| rf = create_model("rf", fold=10) | |
| tuned_rf = tune_model(rf) | |
| # creating a predict function to be passed into gradio UI | |
| def predict( | |
| model, | |
| Pregnancies, | |
| Glucose, | |
| BloodPressure, | |
| BMI, | |
| SkinThickness, | |
| Insulin, | |
| Age, | |
| DiabetesPedigreeFunction | |
| ): | |
| df = pd.DataFrame.from_dict( | |
| { | |
| "Pregnancies": [Pregnancies], | |
| "Glucose": [Glucose], | |
| "BloodPressure": [BloodPressure], | |
| "BMI": [BMI], | |
| "SkinThickness": [SkinThickness], | |
| "Insulin": [Insulin], | |
| "Age": [Age], | |
| "DiabetesPedigreeFunction": [DiabetesPedigreeFunction] | |
| } | |
| ) | |
| model_index = list(compare_model_results["Model"]).index(model) | |
| model = best[model_index] | |
| pred = predict_model(model, df, raw_score=True) | |
| return { | |
| "Not Diabetic": pred["Score_Not_Diabetic"][0].astype("float64"), | |
| "Diabetic": pred["Score_Diabetic"][0].astype("float64") | |
| } | |
| import gradio as gr | |
| model = gr.inputs.Dropdown(list(compare_model_results["Model"]), label="Models") | |
| Pregnancies = gr.inputs.Slider( | |
| minimum=1, maximum=20,step=1, default=df["Pregnancies"].mean(), label="Pregnancies" | |
| ) | |
| Glucose = gr.inputs.Slider( | |
| minimum=0, maximum=200,step=1 ,default=df["Glucose"].mean(), label="Glucose" | |
| ) | |
| BloodPressure = gr.inputs.Slider( | |
| minimum=0, maximum=140,step=1 ,default=df["BloodPressure"].mean(), label="BloodPressure" | |
| ) | |
| BMI = gr.inputs.Slider(minimum=0, maximum=70, default=df["BMI"].mean(), label="BMI") | |
| SkinThickness = gr.inputs.Slider( | |
| minimum=0, maximum=100,step=1,default=df["SkinThickness"].mean(), label="SkinThickness" | |
| ) | |
| Insulin = gr.inputs.Slider( | |
| minimum=0, maximum=1000,step=1,default=df["Insulin"].mean(), label="Insulin" | |
| ) | |
| Age = gr.inputs.Slider(minimum=0,maximum=100,step=1,default=df["Age"].mean(), label="Age") | |
| DiabetesPedigreeFunction = gr.inputs.Slider( | |
| minimum=0, | |
| maximum=1, | |
| default=df["DiabetesPedigreeFunction"].mean(), | |
| label="DiabetesPedigreeFunction" | |
| ) | |
| gr.Interface( | |
| predict, | |
| [ | |
| model, | |
| Pregnancies, | |
| Glucose, | |
| BloodPressure, | |
| BMI, | |
| SkinThickness, | |
| Insulin, | |
| Age, | |
| DiabetesPedigreeFunction | |
| ], | |
| "label", | |
| live=True, | |
| ).launch() | |