CoolFace
Apppublic

mrjohn1134/Tips_Model_Predictor1

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
Tips_model40 linesDownload Raw Back to root
1import numpy as np
2import pandas as pd
3import matplotlib.pyplot as plt
4import seaborn as sns
5import sklearn
6import os
7import warnings
8warnings.filterwarnings('ignore')
9from sklearn.linear_model import LinearRegression
10from sklearn.preprocessing import OneHotEncoder
11from sklearn.compose import ColumnTransformer
12from sklearn.pipeline  import Pipeline
13import joblib
14
15#Load dataset
16
17df=sns.load_dataset('tips')
18X = df[['total_bill','sex','smoker','day','size','time']]
19y = df['tip']
20
21df
22
23categorical = ['sex','smoker','day','size','time']
24
25#preprocessing steps
26preprocessor = ColumnTransformer([
27    ('cat', OneHotEncoder(handle_unknown='ignore'),categorical)
28],remainder='passthrough')
29
30#Define the  pipeline
31pipeline = Pipeline([
32    ('preprocessor',preprocessor),
33    ('regressor',LinearRegression())
34]) 
35
36
37
38#Fit amd save the trained pipeline
39pipeline.fit(X, y)
40joblib.dump(pipeline, 'tipsmodel.pkl')