# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
import tensorflow as tf
import math
job_data = pd.read_csv("dataset/train_data.csv")
job_data.head()

job_data.tail()

job_data.isnull().sum()

from sklearn.preprocessing import LabelEncoder

job_data['workex'] = LabelEncoder().fit_transform(job_data['workex'])
job_data['status'] = LabelEncoder().fit_transform(job_data['status'])

job_data.head()

features = ['ssc_p','hsc_p','degree_p','workex','etest_p']
X = job_data[features]
y = job_data["status"]

data = job_data.drop(['sl_no','gender','ssc_b','hsc_b','hsc_s','degree_t','specialisation','mba_p','salary'], axis=1)
data

sns.catplot(x="gender",y="etest_p",hue="status",kind="bar",data=job_data)

sns.relplot(x="degree_p",y="etest_p",hue="status",data=job_data)

sns.pairplot(data, hue='status', diag_kind="kde")

y.shape

from sklearn.model_selection import train_test_split

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.3,random_state=1)

X_test.shape

from keras.models import Sequential
from keras.layers import Dense

a = tf.keras.models.Sequential()

a.add(tf.keras.layers.Dense(11,kernel_initializer='random_uniform',activation='relu'))

a.add(tf.keras.layers.Dense(22,kernel_initializer='random_uniform',activation='relu'))

a.add(tf.keras.layers.Dense(1,kernel_initializer='random_uniform',activation='sigmoid'))

a.compile(optimizer='adam',loss='binary_crossentropy',metrics=["accuracy"])

a.fit(X_train,y_train,epochs=50,batch_size=32)

a.save('custom_model'+".h5")

converter = tf.lite.TFLiteConverter.from_keras_model(a)
converter.target_spec.supported_ops = [
  tf.lite.OpsSet.TFLITE_BUILTINS, # enable TensorFlow Lite ops.
  tf.lite.OpsSet.SELECT_TF_OPS # enable TensorFlow ops.
]

tflite_model = converter.convert()

with open('model.tflite', 'wb') as f:
  f.write(tflite_model)

y_pred = a.predict(X_test)

y_pred = y_pred[y_pred>0.5]

y_pred

# +
data=pd.DataFrame([90,90,75,1,85]).transpose()
print(data)
data.columns=['ssc_p','hsc_p','degree_p','workex','etest_p']
print(data)

new_pred = a.predict(data)
# -

type(new_pred)

ano_pred = a.predict([[20,30,50,0,2]])
int(ano_pred[0][0]*100)

data = [[90,80,70,1,56]]


type(data)

res = a.predict(data)
res[0][0]

from sklearn.preprocessing import MinMaxScaler

scaler = MinMaxScaler()

import joblib
joblib.dump(scaler,'predict_scaler.pkl')

data

scaler.fit(X_train)

ndata = scaler.transform([[90,80,70,1,56]])

a.predict(ndata)

from tensorflow.keras.models import load_model

predict_model = load_model('model/custom_model.h5')

place_scaler = joblib.load('predict_scaler.pkl')

predict_example = {"ssc_p":90,
                  "hsc_p":85,
                  "degree_p":75,
                  "workex":1,
                  "etest_p":80}


def return_prediction(model,sample_json):
    
    s_percent = sample_json["ssc_p"]
    h_percent = sample_json["hsc_p"]
    d_percent = sample_json["degree_p"]
    w_experience = sample_json["workex"]
    e_percent = sample_json["etest_p"]
    
    data = [[s_percent,h_percent,d_percent,w_experience,e_percent]]
    print(type(data))
    
    class_ind = model.predict(data)
    
    return int(class_ind[0][0]*100)


return_prediction(predict_model,predict_example)

# CODE FOR DEPLOYMENT
#

# from tensorflow.keras.models import load_model
#
# predict_model = load_model('model/custom_model.h5')
#
# def return_prediction(model,sample_json):
#     
#     s_percent = sample_json["ssc_p"]
#     h_percent = sample_json["hsc_p"]
#     d_percent = sample_json["degree_p"]
#     w_experience = sample_json["workex"]
#     e_percent = sample_json["etest_p"]
#     
#     data = [[s_percent,h_percent,d_percent,w_experience,e_percent]]
#     
#     class_ind = model.predict(data)
#     
#     return int(class_ind[0][0]*100)

StarcoderdataJupyterScriptsDedupFiltered