{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "dffa60e8", "metadata": {}, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "id": "3340eabf", "metadata": { "cell_marker": "\"\"\"" }, "source": [ "Inclass-Lab\n", "\n", "Automatically generated by Colab.\n", "\n", "Original file is located at\n", " https://colab.research.google.com/drive/13N7lQHvv4_LxKgcerumJ-18e5GfdBggm" ] }, { "cell_type": "code", "execution_count": null, "id": "34271feb", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "markdown", "id": "9491847c", "metadata": { "cell_marker": "\"\"\"" }, "source": [ "In-Class Lab: Comparing Classification Models (Breast Cancer Dataset)\n", "\n", "Learning Objectives\n", "\n", "---\n", "\n", "\n", "By the end of this lab, you should be able to:\n", "\n", "\n", "\n", "* Train multiple models (KNN, Logistic Regression, Decision Tree)\n", "* Compare performance across various scenarios\n", "* Understand the effect of scaling and evaluation methods\n", "* Interpret confusion matrix & classification report\n", "\n", "\n", "\n", "\n", "\n" ] }, { "cell_type": "markdown", "id": "cceb43dc", "metadata": { "cell_marker": "####################################", "lines_to_next_cell": 0 }, "source": [ "BLOCK 1:" ] }, { "cell_type": "markdown", "id": "818bfdad", "metadata": { "cell_marker": "'''", "lines_to_next_cell": 0 }, "source": [ "Load dataset\n", "Explain features/target\n", "Do train_test_split" ] }, { "cell_type": "markdown", "id": "6de94b5d", "metadata": { "cell_marker": "####################################", "lines_to_next_cell": 0 }, "source": [] }, { "cell_type": "code", "execution_count": 1, "id": "a8899ca0", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['malignant' 'benign']\n", "(569, 30)\n" ] } ], "source": [ "from sklearn.datasets import load_breast_cancer\n", "data = load_breast_cancer()\n", "X = data.data\n", "y = data.target\n", "\n", "print(data.target_names)\n", "print(X.shape)\n", "#0 - malignant\n", "#1 - benigh" ] }, { "cell_type": "markdown", "id": "ae1b0d61", "metadata": { "cell_marker": "###############################", "lines_to_next_cell": 0 }, "source": [ "BLOCK 2: IMPORT LIBRARIES FOR CLASSIFIERS\n", "##############################" ] }, { "cell_type": "code", "execution_count": 9, "id": "8db6dfd6", "metadata": { "lines_to_next_cell": 0 }, "outputs": [], "source": [ "from sklearn.neighbors import KNeighborsClassifier\n", "from sklearn.linear_model import LogisticRegression\n", "from sklearn.tree import DecisionTreeClassifier\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "a2301b40", "metadata": { "cell_marker": "#########################################", "lines_to_next_cell": 0 }, "source": [ "BLOCK 3: IMPORT MODUL FOR DATA SPLIT\n", "########################################" ] }, { "cell_type": "code", "execution_count": 10, "id": "75fe2532", "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "markdown", "id": "fb69921d", "metadata": { "cell_marker": "####################################", "lines_to_next_cell": 0 }, "source": [ "BLOCK 4: SPLIT THE DATASET\n", "###################################" ] }, { "cell_type": "code", "execution_count": 11, "id": "6eb66fc0", "metadata": {}, "outputs": [], "source": [ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)" ] }, { "cell_type": "markdown", "id": "b182e930", "metadata": { "cell_marker": "####################################", "lines_to_next_cell": 0 }, "source": [ "BLOCK 5\n", "TASK 1: Train 3 models (no scaling)\n", "###################################" ] }, { "cell_type": "code", "execution_count": 12, "id": "f31f0262", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
DecisionTreeClassifier()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.