saifhmb
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# importing libraries
|
| 2 |
+
!pip install huggingface_hub
|
| 3 |
+
!pip install transformers
|
| 4 |
+
!pip install transformers[torch]
|
| 5 |
+
!pip install datasets
|
| 6 |
+
!pip install skops
|
| 7 |
+
!pip install streamlit
|
| 8 |
+
from datasets import load_dataset, load_dataset_builder
|
| 9 |
+
import numpy as np
|
| 10 |
+
import matplotlib.pyplot as plt
|
| 11 |
+
import pandas as pd
|
| 12 |
+
import sklearn
|
| 13 |
+
from sklearn.model_selection import train_test_split
|
| 14 |
+
from sklearn.preprocessing import StandardScaler
|
| 15 |
+
from sklearn.linear_model import LogisticRegression
|
| 16 |
+
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay, accuracy_score, precision_score, recall_score, classification_report
|
| 17 |
+
from transformers import Trainer, TrainingArguments
|
| 18 |
+
from skops import hub_utils
|
| 19 |
+
import pickle
|
| 20 |
+
from skops.card import Card, metadata_from_config
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
from tempfile import mkdtemp, mkstemp
|
| 23 |
+
import streamlit as st
|
| 24 |
+
from PIL import Image
|
| 25 |
+
|
| 26 |
+
# Loading the dataset
|
| 27 |
+
dataset_name = "saifhmb/social-network-ads"
|
| 28 |
+
dataset = load_dataset(dataset_name, split = 'train')
|
| 29 |
+
dataset = pd.DataFrame(dataset)
|
| 30 |
+
X = dataset.iloc[:, :-1].values
|
| 31 |
+
y = dataset.iloc[:, -1].values
|
| 32 |
+
|
| 33 |
+
# Spliting the datset into Training and Test set
|
| 34 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
|
| 35 |
+
|
| 36 |
+
# Feature Scaling
|
| 37 |
+
sc = StandardScaler()
|
| 38 |
+
X_train = sc.fit_transform(X_train)
|
| 39 |
+
X_test = sc.transform(X_test)
|
| 40 |
+
|
| 41 |
+
# Training Logit Reg Model using the Training set
|
| 42 |
+
model = LogisticRegression()
|
| 43 |
+
model.fit(X_train, y_train)
|
| 44 |
+
|
| 45 |
+
# Predicting the Test result
|
| 46 |
+
y_pred = model.predict(X_test)
|
| 47 |
+
|
| 48 |
+
# Making the Confusion Matrix and evaluating performance
|
| 49 |
+
cm = confusion_matrix(y_pred, y_test, labels=model.classes_)
|
| 50 |
+
disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=model.classes_)
|
| 51 |
+
disp.plot()
|
| 52 |
+
plt.show()
|
| 53 |
+
acc = accuracy_score(y_test, y_pred)
|
| 54 |
+
ps = precision_score(y_test, y_pred)
|
| 55 |
+
rs = recall_score(y_test, y_pred)
|
| 56 |
+
|
| 57 |
+
# Pickling the model
|
| 58 |
+
pickle_out = open("model.pkl", "wb")
|
| 59 |
+
pickle.dump(model, pickle_out)
|
| 60 |
+
pickle_out.close()
|
| 61 |
+
|
| 62 |
+
# Loading the model to predict on the data
|
| 63 |
+
pickle_in = open('model.pkl', 'rb')
|
| 64 |
+
model = pickle.load(pickle_in)
|
| 65 |
+
|
| 66 |
+
def welcome():
|
| 67 |
+
return 'welcome all'
|
| 68 |
+
|
| 69 |
+
# defining the function which will make the prediction using the data which the user inputs
|
| 70 |
+
def prediction(Age, EstimatedSalary):
|
| 71 |
+
prediction = model.predict.sc.transform([[Age, EstimatedSalary]])
|
| 72 |
+
print(prediction)
|
| 73 |
+
return prediction
|
| 74 |
+
|
| 75 |
+
# this is the main function in which we define our webpage
|
| 76 |
+
def main():
|
| 77 |
+
# giving the webpage a title
|
| 78 |
+
st.title("Customer Vehicle Purchase Prediction")
|
| 79 |
+
|
| 80 |
+
Age = st.text_input("Age", "Type Here")
|
| 81 |
+
EstimatedSalary = st.text_input("EstimatedSalary", "Type Here")
|
| 82 |
+
result = ""
|
| 83 |
+
if st.button("Predict"):
|
| 84 |
+
result = prediction(Age, EstimatedSalary)
|
| 85 |
+
|
| 86 |
+
st.success('The output is {}'.format(result))
|
| 87 |
+
|
| 88 |
+
if __name__=='__main__':
|
| 89 |
+
main()
|