-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLogistic_Regression_2.py
More file actions
87 lines (62 loc) · 2.17 KB
/
Logistic_Regression_2.py
File metadata and controls
87 lines (62 loc) · 2.17 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Logistic Regression
import numpy as np
import pandas as pd
import matplotlib.pylab as plt
import seaborn as sns
import sklearn
# data = pd.read_csv('/home/m-fayzi/Desktop/machin_learning/Datasets/iris.csv')
# print(data)
# print(data.head())
# print(data.info())
# sns.pairplot(data, hue='variety')
# plt.show()
# print(data.shape)
# df = data.drop(['variety'], axis=1)
# corr = df.corr()
# print(corr)
# plt.figure(figsize=(12,10))
# sns.heatmap(corr, cmap='coolwarm', annot=True)
# plt.show()
# from sklearn.linear_model import LogisticRegression
# from sklearn.model_selection import train_test_split
# from sklearn import metrics
# X = data.drop(['variety'], axis=1)
# y = data['variety']
# print(X.shape)
# print(y.shape)
# X_train, X_test, y_train, y_test = train_test_split(X,y , test_size=0.2, random_state=5)
# print(X_train.shape)
# print(X_test.shape)
# print(y_train.shape)
# print(y_test.shape)
# logReg = LogisticRegression()
# logReg.fit(X_train, y_train)
# y_pred = logReg.predict(X_test)
# print(y_pred)
# print('Accurecy Score:',metrics.accuracy_score(y_test, y_pred))
#Accurecy Score from test_Size 0.4 = 0.983333
#Accurecy Score from test_Size 0.2 = 0.966667
data = {
'Actual': [1, 0, 1, 0, 0, 1, 1, 0, 1, 0],
'Predicted': [1, 1, 1, 0, 0, 1, 0, 0, 0, 0]
}
# print(data)
df = pd.DataFrame(data, columns=['Actual', 'Predicted'])
# print(df)
# confusion_matrix = pd.crosstab(df['Predicted'], df['Actual'], rownames=['Predict'], colnames=['Actual'])
# print(confusion_matrix)
# sns.heatmap(confusion_matrix, cmap='coolwarm', annot=True)
# plt.show()
# from sklearn.metrics import confusion_matrix
# cf = confusion_matrix(df['Actual'], df['Predicted'])
# # print(cf)
# from sklearn.metrics import accuracy_score
# print(accuracy_score(df['Actual'], df['Predicted']))
# from sklearn.metrics import recall_score
# print(recall_score(df['Actual'], df['Predicted']))
# from sklearn.metrics import precision_score
# print(precision_score(df['Actual'], df['Predicted']))
# from sklearn.metrics import f1_score
# print(f1_score(df['Actual'], df['Predicted']))
from sklearn.metrics import classification_report
print(classification_report(df['Actual'], df['Predicted']))