Python - Regression - Logistic


Employees when they sent job applicant (40 rows)


How to predict the probability of someone will accepted from given gpa, gmat & work_experience

Library used:

  • Pandas
  • Matplotlib
  • Seaborn
  • Scikit


import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
import seaborn as sn
import matplotlib.pyplot as plt

url = ''
vlog119 = pd.read_csv(url)

X = vlog119[['gpa', 'gmat','work_experience']]
y = vlog119['admitted']
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)

logistic_regression= LogisticRegression(),y_train)

confusion_matrix = pd.crosstab(y_test, y_pred, rownames=['Actual'], colnames=['Predicted'])
sn.heatmap(confusion_matrix, annot=True)

from sklearn import metrics
print('Accuracy: ',metrics.accuracy_score(y_test, y_pred))

print (X_test) #test dataset
print (y_pred) #predicted values

new_candidates = {'gpa': [2,3.7,3.3,2.3,3],
                  'gmat': [590,740,680,610,710],
                  'work_experience': [3,4,6,1,5]

df2 = pd.DataFrame(new_candidates,columns= ['gpa','gmat','work_experience'])

print (df2)
print (y_pred)

I wrapped the scenario in a Youtube video below.

Click this link (, if you want to check out for other algorithms. Thank you for for visiting this blog & subs my channel.

Labels: ,

PS: If you've benefit from this blog,
you can support it by making a small contribution.

Enter your email address to receive feed update from this blog:

Post a Comment


Post a Comment

Leave comments here...