#pr1 

import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler, LabelEncoder

data = pd.read_csv("Heart.csv")
print(" Data loaded successfully!")
print(data)



data = data.drop_duplicates()
print("\nMissing values before cleaning:\n", data.isnull().sum())



data['Ca'] = data['Ca'].fillna(data['Ca'].mean())
data['Thal'] = data['Thal'].fillna(data['Thal'].mode()[0])
data.isnull().sum()



for col in data.columns:
    if data[col].dtype == 'object':
        le = LabelEncoder()
        data[col] = le.fit_transform(data[col])
print(data)




numeric_cols = ['Age', 'RestBP', 'Chol', 'MaxHR', 'Oldpeak']
scaler = StandardScaler()
data[numeric_cols] = scaler.fit_transform(data[numeric_cols])
print(data)


X = data.drop('AHD', axis=1)
y = data['AHD']



X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.25, random_state=1)
print("Training set size:", X_train.shape)
print("Testing set size:", X_test.shape)