Python - Regression - Logistic
Data:
Employees when they sent job applicant (40 rows)
Mission:
How to predict the probability of someone will accepted from given gpa, gmat & work_experience
Library used:
- Pandas
- Matplotlib
- Seaborn
- Scikit
Code:
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 = 'https://raw.githubusercontent.com/kokocamp/vlog119/main/vlog119.csv'
vlog119 = pd.read_csv(url)
vlog119.describe()
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()
logistic_regression.fit(X_train,y_train)
y_pred=logistic_regression.predict(X_test)
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))
plt.show()
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'])
y_pred=logistic_regression.predict(df2)
print (df2)
print (y_pred)
I wrapped the scenario in a Youtube video below.
Click this link (http://paparadit.blogspot.com/2020/11/the-algorithms-of-machine-learning.html), if you want to check out for other algorithms. Thank you for for visiting this blog & subs my channel.
Labels: Programming, Python
PS: If you've benefit from this blog, you can support it by making a small contribution. |
Post a Comment
Leave comments here...