Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
Busy building PyCaret

Moez Ali moezali1

🚀
Busy building PyCaret
View GitHub Profile
View timeseries_training_loop.py
from tqdm import tqdm
from pycaret.regression import *
all_ts = data['time_series'].unique()
all_results = []
final_model = {}
for i in tqdm(all_ts):
View gradio_step1.py
# 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'),
View gradio_step2.py
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()
View fastapi_tutorial.py
# 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
View fastapi_tutorial2.py
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 = requests.post(url)
print(x.text)
View churn.py
import plotly.express 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 $'})
fig.show()