-
Notifications
You must be signed in to change notification settings - Fork 0
/
breast_cancer_logistic_regression.py
40 lines (26 loc) · 1.14 KB
/
breast_cancer_logistic_regression.py
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
# Logistic Regression
## Importing the libraries
"""
import pandas as pd
"""## Importing the dataset"""
dataset = pd.read_csv('breast_cancer.csv')
X = dataset.iloc[:, 1:-1].values
y = dataset.iloc[:, -1].values
"""## Splitting the dataset into the Training set and Test set"""
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)
"""## Training the Logistic Regression model on the Training set"""
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state = 0)
classifier.fit(X_train, y_train)
"""## Predicting the Test set results"""
y_pred = classifier.predict(X_test)
"""## Making the Confusion Matrix"""
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test, y_pred)
print(cm)
"""## Computing the accuracy with k-Fold Cross Validation"""
from sklearn.model_selection import cross_val_score
accuracies = cross_val_score(estimator = classifier, X = X_train, y = y_train, cv = 10)
print("Accuracy: {:.2f} %".format(accuracies.mean()*100))
print("Standard Deviation: {:.2f} %".format(accuracies.std()*100))