From a020d82c67552cd754492db48815446708518aea Mon Sep 17 00:00:00 2001 From: Monika Kataria Date: Fri, 17 Oct 2025 22:58:09 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Add=20Assignment=20#1=20=E2=80=93=20Anagram?= =?UTF-8?q?=20Checker=20solution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assignment_1.ipynb | 102 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 assignment_1.ipynb diff --git a/assignment_1.ipynb b/assignment_1.ipynb new file mode 100644 index 000000000..3174931f5 --- /dev/null +++ b/assignment_1.ipynb @@ -0,0 +1,102 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "a7768fe5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "# Part 1: Basic Anagram Checker\n", + "\n", + "def anagram_checker(word_a, word_b):\n", + " \"\"\"\n", + " Check if two words are anagrams of each other.\n", + " Ignores case sensitivity.\n", + " \"\"\"\n", + " # Convert both words to lowercase for comparison\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + "\n", + " # Sort letters and compare\n", + " return sorted(word_a) == sorted(word_b)\n", + "\n", + "# Testing Part 1\n", + "print(anagram_checker(\"Silent\", \"listen\")) # True\n", + "print(anagram_checker(\"Silent\", \"Night\")) # False\n", + "print(anagram_checker(\"night\", \"Thing\")) # True\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9f4c4b83", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "# Part 2: Expanding the Anagram Checker with Case Sensitivity\n", + "\n", + "def anagram_checker(word_a, word_b, is_case_sensitive=False):\n", + " \"\"\"\n", + " Check if two words are anagrams of each other.\n", + " Case sensitivity can be toggled with 'is_case_sensitive'.\n", + " \"\"\"\n", + "\n", + " # If not case-sensitive, convert both words to lowercase\n", + " if not is_case_sensitive:\n", + " word_a = word_a.lower()\n", + " word_b = word_b.lower()\n", + "\n", + " # Sort letters and compare\n", + " return sorted(word_a) == sorted(word_b)\n", + "\n", + "\n", + "# Testing Part 2\n", + "print(anagram_checker(\"Silent\", \"listen\", False)) # ✅ True (ignores case)\n", + "print(anagram_checker(\"Silent\", \"Listen\", True)) # ❌ False (case-sensitive)\n", + "print(anagram_checker(\"night\", \"Thing\", False)) # ✅ True\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "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.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From be8d0618de168703780b620838e6dad6c18e21d1 Mon Sep 17 00:00:00 2001 From: Monika Kataria Date: Sat, 25 Oct 2025 20:25:16 -0400 Subject: [PATCH 2/2] Complete Assignment #2 - Arthritis Drug Efficacy Analysis --- assignment_2.ipynb | 248 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 assignment_2.ipynb diff --git a/assignment_2.ipynb b/assignment_2.ipynb new file mode 100644 index 000000000..3a52aefdd --- /dev/null +++ b/assignment_2.ipynb @@ -0,0 +1,248 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "806a8681", + "metadata": {}, + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: '../../05_src/data/assignment_2_data/inflammation_01.csv'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[1], line 20\u001b[0m\n\u001b[1;32m 4\u001b[0m all_paths \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 5\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../../05_src/data/assignment_2_data/inflammation_01.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 6\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../../05_src/data/assignment_2_data/inflammation_02.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m../../05_src/data/assignment_2_data/inflammation_12.csv\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 17\u001b[0m ]\n\u001b[1;32m 19\u001b[0m \u001b[38;5;66;03m# Read and display the first file\u001b[39;00m\n\u001b[0;32m---> 20\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(all_paths[\u001b[38;5;241m0\u001b[39m], \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mr\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m f:\n\u001b[1;32m 21\u001b[0m lines \u001b[38;5;241m=\u001b[39m f\u001b[38;5;241m.\u001b[39mreadlines()\n\u001b[1;32m 23\u001b[0m \u001b[38;5;66;03m# Display first few rows for inspection\u001b[39;00m\n", + "File \u001b[0;32m/opt/anaconda3/lib/python3.12/site-packages/IPython/core/interactiveshell.py:324\u001b[0m, in \u001b[0;36m_modified_open\u001b[0;34m(file, *args, **kwargs)\u001b[0m\n\u001b[1;32m 317\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m {\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m}:\n\u001b[1;32m 318\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[1;32m 319\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIPython won\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt let you open fd=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfile\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m by default \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 320\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mas it is likely to crash IPython. If you know what you are doing, \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 321\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou can use builtins\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m open.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m 322\u001b[0m )\n\u001b[0;32m--> 324\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m io_open(file, \u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: '../../05_src/data/assignment_2_data/inflammation_01.csv'" + ] + } + ], + "source": [ + "import numpy as np\n", + "\n", + "# All file paths (provided)\n", + "all_paths = [\n", + " \"../../05_src/data/assignment_2_data/inflammation_01.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_02.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_03.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_04.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_05.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_06.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_07.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_08.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_09.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_10.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_11.csv\",\n", + " \"../../05_src/data/assignment_2_data/inflammation_12.csv\"\n", + "]\n", + "\n", + "# Read and display the first file\n", + "with open(all_paths[0], 'r') as f:\n", + " lines = f.readlines()\n", + "\n", + "# Display first few rows for inspection\n", + "for line in lines[:5]:\n", + " print(line.strip())\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "7871951f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "/Users/moli/Desktop/dsi projects/python\n" + ] + } + ], + "source": [ + "import os\n", + "print(os.getcwd())\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "b6e7873e", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "26d6c074", + "metadata": {}, + "outputs": [], + "source": [ + "all_paths = [\n", + " \"05_src/data/assignment_2_data/inflammation_01.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_02.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_03.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_04.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_05.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_06.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_07.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_08.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_09.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_10.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_11.csv\",\n", + " \"05_src/data/assignment_2_data/inflammation_12.csv\"\n", + "]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "87c23235", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0,0,1,3,1,2,4,7,8,3,3,3,10,5,7,4,7,7,12,18,6,13,11,11,7,7,4,6,8,8,4,4,5,7,3,4,2,3,0,0\n", + "0,1,2,1,2,1,3,2,2,6,10,11,5,9,4,4,7,16,8,6,18,4,12,5,12,7,11,5,11,3,3,5,4,4,5,5,1,1,0,1\n", + "0,1,1,3,3,2,6,2,5,9,5,7,4,5,4,15,5,11,9,10,19,14,12,17,7,12,11,7,4,2,10,5,4,2,2,3,2,2,1,1\n", + "0,0,2,0,4,2,2,1,6,7,10,7,9,13,8,8,15,10,10,7,17,4,4,7,6,15,6,4,9,11,3,5,6,3,3,4,2,3,2,1\n", + "0,1,1,3,3,1,3,5,2,4,4,7,6,5,3,10,8,10,6,17,9,14,9,7,13,9,12,6,7,7,9,6,3,2,2,4,2,0,1,1\n" + ] + } + ], + "source": [ + "with open(all_paths[0], 'r') as f:\n", + " lines = f.readlines()\n", + "\n", + "for line in lines[:5]:\n", + " print(line.strip())\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "f73d710f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number of patients: 60\n", + "First 5 minimum values: [0. 0. 0. 0. 0.]\n" + ] + } + ], + "source": [ + "import numpy as np\n", + "\n", + "def patient_summary(file_path, operation):\n", + " \"\"\"\n", + " Compute summary statistics (mean, max, or min) per patient.\n", + " Each row in the file corresponds to one patient.\n", + " \"\"\"\n", + " # Load the data (60 patients × 40 days)\n", + " data = np.loadtxt(fname=file_path, delimiter=',')\n", + " ax = 1 # perform operation across columns (days) for each patient\n", + "\n", + " # Choose operation type\n", + " if operation == 'mean':\n", + " summary_values = np.mean(data, axis=ax)\n", + " elif operation == 'max':\n", + " summary_values = np.max(data, axis=ax)\n", + " elif operation == 'min':\n", + " summary_values = np.min(data, axis=ax)\n", + " else:\n", + " raise ValueError(\"Invalid operation. Please choose 'mean', 'max', or 'min'.\")\n", + "\n", + " return summary_values\n", + "\n", + "# ✅ Test the function\n", + "data_min = patient_summary(all_paths[0], 'min')\n", + "print(\"Number of patients:\", len(data_min))\n", + "print(\"First 5 minimum values:\", data_min[:5])\n" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "1f01f8cf", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Any zero-mean patients? False\n" + ] + } + ], + "source": [ + "def check_zeros(x):\n", + " \"\"\"\n", + " Given an array x, check whether any values in x equal 0.\n", + " Return True if any values found, else False.\n", + " \"\"\"\n", + " flag = np.where(x == 0)[0]\n", + " return len(flag) > 0\n", + "\n", + "def detect_problems(file_path):\n", + " \"\"\"\n", + " Detects if any patient has a mean inflammation of 0.\n", + " Returns True if such a patient exists, False otherwise.\n", + " \"\"\"\n", + " means = patient_summary(file_path, 'mean')\n", + " has_zero = check_zeros(means)\n", + " return has_zero\n", + "\n", + "# ✅ Test\n", + "print(\"Any zero-mean patients?\", detect_problems(all_paths[0]))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "38e43fba", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean values (first 5): [5.45 5.425 6.1 5.9 5.55 ]\n", + "Max values (first 5): [18. 18. 19. 17. 17.]\n" + ] + } + ], + "source": [ + "print(\"Mean values (first 5):\", patient_summary(all_paths[0], 'mean')[:5])\n", + "print(\"Max values (first 5):\", patient_summary(all_paths[0], 'max')[:5])\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "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.12.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}