AttiqAhmadAfsarLab11
AttiqAhmadAfsarLab11
AttiqAhmadAfsarLab11
ipynb - Colab
Load the dataset. Identify numerical and categorical variables. Handle missing values. Visualize
data distributions and relationships. Feature Engineering
Encode categorical variables. Scale the numerical features. Model Training & Evaluation
Train K-NN and Gaussian Naive Bayes models. Evaluate performance using metrics like ROC-AUC
and cross-validation. Full Code with Explanations:
https://colab.research.google.com/drive/1RCyYhwjNGf2dyN-YMS7oxIk3Z8DRR30K#scrollTo=uBRduAQcXOxk&printMode=true 1/6
11/23/24, 11:58 PM Untitled16.ipynb - Colab
encoder = LabelEncoder()
for col in categorical_cols:
data[col] = encoder.fit_transform(data[col])
# Make predictions
y_pred_knn = knn_model.predict(X_test)
# Make predictions
y_pred_gnb = gnb_model.predict(X_test)
plt.figure(figsize=(10, 6))
plt.plot(fpr_knn, tpr_knn, color='blue', label=f'K-NN ROC (AUC = {roc_auc_knn:.4f})')
plt.plot(fpr_gnb, tpr_gnb, color='red', label=f'GNB ROC (AUC = {roc_auc_gnb:.4f})')
plt.plot([0, 1], [0, 1], color='black', linestyle='--')
https://colab.research.google.com/drive/1RCyYhwjNGf2dyN-YMS7oxIk3Z8DRR30K#scrollTo=uBRduAQcXOxk&printMode=true 2/6
11/23/24, 11:58 PM Untitled16.ipynb - Colab
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('ROC Curve Comparison')
plt.legend(loc='lower right')
plt.show()
https://colab.research.google.com/drive/1RCyYhwjNGf2dyN-YMS7oxIk3Z8DRR30K#scrollTo=uBRduAQcXOxk&printMode=true 3/6
11/23/24, 11:58 PM Untitled16.ipynb - Colab
https://colab.research.google.com/drive/1RCyYhwjNGf2dyN-YMS7oxIk3Z8DRR30K#scrollTo=uBRduAQcXOxk&printMode=true 4/6
11/23/24, 11:58 PM Untitled16.ipynb - Colab
https://colab.research.google.com/drive/1RCyYhwjNGf2dyN-YMS7oxIk3Z8DRR30K#scrollTo=uBRduAQcXOxk&printMode=true 5/6
11/23/24, 11:58 PM Untitled16.ipynb - Colab
pd.read csv() loads the dataset into a Pandas DataFrame. Exploratory Data Analysis (EDA):
https://colab.research.google.com/drive/1RCyYhwjNGf2dyN-YMS7oxIk3Z8DRR30K#scrollTo=uBRduAQcXOxk&printMode=true 6/6