{ "cells": [ { "cell_type": "markdown", "id": "8c30aedf-0d62-4b28-9e5f-b34d80846b8b", "metadata": {}, "source": [ "# Homework 12 - Chapter 17" ] }, { "cell_type": "markdown", "id": "53578bfd-2a4e-42e3-8da4-3dd1bdebc833", "metadata": {}, "source": [ "- Due Date: Thursday, May 1st no later than 11:59 p.m.\n", "- Partner Information: You must complete this assignment individually.\n", "- Submission Instructions: Upload your solution, entitled **YourFirstName-YourLastName-Homework12.ipynb** to the \n", "BrightSpace Homework 12 Dropbox.\n", "- Deadline Reminder: Once the submission deadline passes, BrightSpace will no longer accept your submission and you will no longer be able to earn credit. \n", "Thus, if you are not able to fully complete the assignment, submit whatever you have before the deadline so that partial credit can be earned." ] }, { "cell_type": "markdown", "id": "b3c19ddc", "metadata": {}, "source": [ "## Starting Code" ] }, { "cell_type": "code", "execution_count": null, "id": "fb72191f-5f87-41ae-87fc-55f2a740b764", "metadata": {}, "outputs": [], "source": [ "from datascience import *\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "f34e1b1a-962e-42ce-af63-728f201111f5", "metadata": {}, "source": [ "Download the train.csv and test.csv files into the same directory as this Jupyter notebook." ] }, { "cell_type": "code", "execution_count": null, "id": "df3eb465-3a37-4488-9b8e-b3ecc8eae06b", "metadata": {}, "outputs": [], "source": [ "train = Table().read_table(\"train.csv\")\n", "train.show(3)\n", "test = Table().read_table(\"test.csv\")\n", "test.show(3)" ] }, { "cell_type": "markdown", "id": "d2ffdadc-4e2b-40cb-add7-05b25dbc2a5c", "metadata": {}, "source": [ "## Part 1: 0 points" ] }, { "cell_type": "markdown", "id": "76c8b3a9-a84a-4d9c-8ec6-42e5e70d57df", "metadata": {}, "source": [ "Implement a k-nearest neighbors algorithm using **train.csv** as the training set and \n", "**test.csv** as the test set. The goal is to predict a student's **exam_score**\n", "based on the seven relevant attributes." ] }, { "cell_type": "markdown", "id": "8049a10d-a9a4-4d40-81c5-58a267d054d2", "metadata": {}, "source": [ "*Important Assumptions*: \n", "- Relevant attributes should be converted to standard units and weighted equally.\n", "- When there is more than one knn prediction, each prediction should be weighted equally." ] }, { "cell_type": "code", "execution_count": null, "id": "0e02f661-beba-4983-a716-ce17c8b82c00", "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] }, { "cell_type": "markdown", "id": "e423a75c-4de6-4640-aab0-08aaf19fba62", "metadata": {}, "source": [ "## Part 2: 5 points" ] }, { "cell_type": "markdown", "id": "7e9b6d26-125d-4cce-a143-1ae84e195a7b", "metadata": {}, "source": [ "Use the knn algorithm you implemented above to predict the exam score of\n", "a student with these characteristics [study_hours = 4.4, social_media = 4.3, netflix = 3.2,\n", "attendance = 76, sleep = 5.4, exercise = 4, mental_health = 8] using\n", "- k = 1\n", "- k = 3\n", "- k = 5\n", "- k = 7\n", "- k = 9" ] }, { "cell_type": "code", "execution_count": null, "id": "b0a5b843-b022-4778-845f-4b2f87908dee", "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] }, { "cell_type": "markdown", "id": "30926e47-71e9-4260-ade1-dd1e9514b534", "metadata": {}, "source": [ "## Part 3: 5 points" ] }, { "cell_type": "markdown", "id": "7e237793-c49d-4cf5-a5d5-ab2436ab7b4f", "metadata": {}, "source": [ "Use the knn algorithm you implemented above to determine the average accuracy \n", "(as a percentage of the known values) of applying the training set to the test set using\n", "- k = 1\n", "- k = 3\n", "- k = 5\n", "- k = 7\n", "- k = 9" ] }, { "cell_type": "code", "execution_count": null, "id": "15d0f3b7-2278-4afa-9c1b-87b16e28cc5e", "metadata": {}, "outputs": [], "source": [ "# Place answer here." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.1" } }, "nbformat": 4, "nbformat_minor": 5 }