-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogistic_regression.py
More file actions
53 lines (43 loc) · 1.5 KB
/
Copy pathlogistic_regression.py
File metadata and controls
53 lines (43 loc) · 1.5 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
from sklearn.linear_model import LogisticRegression
import process_data as processor
import numpy as np
from sklearn.model_selection import GridSearchCV
from sklearnex import patch_sklearn
import matplotlib.pyplot as plt
from sklearn.metrics import confusion_matrix
import seaborn as sns
# get data from the dataset
processor.go()
patch_sklearn()
# load them into relevant variables
X_train = processor.X_train_sklearn
y_train = processor.y_train_sklearn
X_test = processor.X_test_sklearn
y_test = processor.y_test_sklearn
X = np.append(X_train, X_test, axis = 0)
y = np.append(y_train, y_test)
# set up a a grid for hyperparameter tuning
# param_grid = {
# 'C': np.logspace(-4, 4, 50)
# }
classifier = LogisticRegression(max_iter=500)
# make the classifier and fit the data in it
classifier.fit(X_train, y_train)
print(classifier.score(X_test, y_test))
y_pred = classifier.predict(X_test)
# tune hyperparameters using GridSearchCV and get the best hyperparameters
# grid_search = GridSearchCV(classifier, param_grid, cv=5, verbose = 1)
# grid_search.fit(X, y)
# print(grid_search.best_params_)
# print("score", grid_search.best_score_)
# mean_test_scores = grid_search.cv_results_['mean_test_score']
# plt.plot(param_grid['C'], mean_test_scores)
# plt.xlabel('C')
# plt.ylabel('Mean Test Score')
# plt.show()
# create a confusion matrix
# confusion_matrix = confusion_matrix(y_test, y_pred)
# sns.heatmap(confusion_matrix, annot=True, fmt='d')
# plt.xlabel('Predicted Class')
# plt.ylabel('True Class')
# plt.show()