Skip to content

Instantly share code, notes, and snippets.

Busy building PyCaret

Moez Ali moezali1

Busy building PyCaret
View GitHub Profile
from tqdm import tqdm
from pycaret.regression import *
all_ts = data['time_series'].unique()
all_results = []
final_model = {}
for i in tqdm(all_ts):
# creating a predict function to be passed into gradio UI
def predict(model, sepal_length, sepal_width, petal_length, petal_width):
df = pd.DataFrame.from_dict({'sepal_length': [sepal_length], 'sepal_width': [sepal_width],
'petal_length': [petal_length], 'petal_width': [petal_width]})
model_index = list(compare_model_results['Model']).index(model)
model = best[model_index]
pred = predict_model(model, df, raw_score=True)
return {'Iris-setosa': pred['Score_Iris-setosa'][0].astype('float64'),
import gradio as gr
model = gr.inputs.Dropdown(list(compare_model_results['Model']), label="Model")
sepal_length = gr.inputs.Slider(minimum=1, maximum=10, default=data['sepal_length'].mean(), label = 'sepal_length')
sepal_width = gr.inputs.Slider(minimum=1, maximum=10, default=data['sepal_width'].mean(), label = 'sepal_width')
petal_length = gr.inputs.Slider(minimum=1, maximum=10, default=data['petal_length'].mean(), label = 'petal_length')
petal_width = gr.inputs.Slider(minimum=1, maximum=10, default=data['petal_width'].mean(), label = 'petal_width')
gr.Interface(predict, [model,sepal_length,sepal_width,petal_length,petal_width], "label", live=True).launch()
# 1. Library imports
import pandas as pd
from pycaret.regression import load_model, predict_model
from fastapi import FastAPI
import uvicorn
# 2. Create the app object
app = FastAPI()
#. Load trained Pipeline
import requests
def get_predictions(carat_weight, cut, color, clarity, polish, symmetry, report):
url = 'http://localhost:8000/predict?carat_weight={carat_weight}&cut={cut}&color={color}&clarity={clarity}&polish={polish}&symmetry={symmetry}&report={report}'\
.format(carat_weight = carat_weight, cut = cut,\
color = color, clarity = clarity, polish = polish, symmetry = symmetry, report = report)
x =
import as px
fig = px.scatter(x=data['tenure'], y=data['TotalCharges'],
color = data['Churn'], template = 'presentation',
opacity = 0.5, facet_col = data['Contract'],
title = 'Customer Churn by Tenure, Charges, and Contract Type',
labels = {'x' : 'Customer Tenure', 'y' : 'Total Charges $'})