0% found this document useful (0 votes)
21 views2 pages

Binary Classification

Uploaded by

vs1438kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views2 pages

Binary Classification

Uploaded by

vs1438kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Untitled21 - Jupyter Notebook http://localhost:8888/notebooks/Untitled21.ipynb?

kernel_name=python3

In [1]: # Import necessary libraries


import pandas as pd
import numpy as np
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score, confusion_matrix, classification_report

# Load the dataset


data = load_breast_cancer()
X = data.data
y = data.target

# Convert to a DataFrame for better visualization (optional)


df = pd.DataFrame(X, columns=data.feature_names)
df['target'] = y

# Data Preprocessing: Standardize the data


scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# Split the data into training and testing sets


X_train, X_test, y_train, y_test = train_test_split(X_scaled, y, test_size=0.2

# Train a classification model (Logistic Regression)


model = LogisticRegression()
model.fit(X_train, y_train)

# Make predictions
y_pred = model.predict(X_test)

# Evaluate the model


accuracy = accuracy_score(y_test, y_pred)
conf_matrix = confusion_matrix(y_test, y_pred)
class_report = classification_report(y_test, y_pred)

# Print the evaluation results


print(f"Accuracy: {accuracy:.2f}")
print("Confusion Matrix:")
print(conf_matrix)
print("Classification Report:")
print(class_report)

1 of 2 9/30/2024, 10:01 AM
Untitled21 - Jupyter Notebook http://localhost:8888/notebooks/Untitled21.ipynb?kernel_name=python3

Accuracy: 0.97
Confusion Matrix:
[[41 2]
[ 1 70]]
Classification Report:
precision recall f1-score support

0 0.98 0.95 0.96 43


1 0.97 0.99 0.98 71

accuracy 0.97 114


macro avg 0.97 0.97 0.97 114
weighted avg 0.97 0.97 0.97 114

In [ ]:

2 of 2 9/30/2024, 10:01 AM

You might also like