-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogistic.py
More file actions
50 lines (37 loc) · 1.2 KB
/
Copy pathlogistic.py
File metadata and controls
50 lines (37 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import confusion_matrix , classification_report, roc_curve
import matplotlib.pyplot as plt
# =============================================================
# data preprocesseing
df = pd.read_csv("Social_Network_Ads.csv")
df.info()
X = df[['Age','EstimatedSalary']]
y = df['Purchased']
X,x,Y,y = train_test_split(X,y,test_size=0.4,random_state=42)
# ================================================================
# model
lr = LogisticRegression()
lr.fit(X,Y)
y_pred = lr.predict(x)
# ===============================
# performance
cm = confusion_matrix(y,y_pred)
cr = classification_report(y,y_pred)
print(cm)
print(cr)
y_pred_proba = lr.predict_proba(x)[:,0]
y_pred_proba2 = lr.predict_proba(x)[:,1]
fpr, tpr, threshold = roc_curve(y,y_pred_proba)
fpr2, tpr2, threshold2 = roc_curve(y,y_pred_proba2)
# ====================================================
# PLOT ROC CURVE
plt.plot([0,1],[0,1],'k--')
plt.plot(fpr,tpr)
plt.plot(fpr2,tpr2,'g')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC curve')
plt.show()