Assignment 1
Assignment 1
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 accuracy_score, confusion_matrix
# Data Aggregation: Calculate average age and tenure for churned vs.
non-churned customers
average_stats = df.groupby('churn').agg(
average_age=('age', 'mean'),
average_tenure=('tenure', 'mean')
).reset_index()
# Splitting the dataset into training (80%) and testing (20%) sets
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2, random_state=42)
3. Data Splitting: Define features (X) and the target variable (y). Then, split the data
into training and testing sets using train_test_split, with 80% of the data for training
and 20% for testing.
5. Model Evaluation: Calculate the accuracy of the model's predictions and output the
confusion matrix for a more detailed performance analysis.