
RUSHIKESH GHRCE
Use WhatsApp on your phone to see older messages from before 5/14/2023.
6/22/2023
7/26/2023
7/27/2023
SUNDAY
TODAY
diff --git a/Day-1/Submission/day 1.html b/Day-1/Submission/day 1.html new file mode 100644 index 0000000..3f29055 --- /dev/null +++ b/Day-1/Submission/day 1.html @@ -0,0 +1,255 @@ + + +






























 WhatsApp_files/366370577_1350216579036356_1806947111078586200_n.jpg)
 WhatsApp_files/162965831_162223329465079_1256920320382701333_n.jpg)
 WhatsApp_files/322285883_753824072633962_2337447654777813057_n.jpg)
 WhatsApp_files/341088330_1090466472344329_4633387913944235934_n.jpg)
 WhatsApp_files/315756989_880773399942184_8569270858386107567_n.jpg)
 WhatsApp_files/323159273_1535747550233572_2289969575697346651_n.jpg)
 WhatsApp_files/353770684_639222681438779_9183543429864699491_n.jpg)
 WhatsApp_files/356598937_592356029685720_3655108522845518183_n.jpg)
 WhatsApp_files/346669675_1211814112853754_1368128035108198161_n.jpg)
None instances pesent in the code."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 48,
+ "metadata": {
+ "id": "6DNQ2HHJHjYZ"
+ },
+ "outputs": [],
+ "source": [
+ "!cp \"/content/Machine-Learning-Simplified/Day-1/LRTestCases.py\" \"/content/\""
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 49,
+ "metadata": {
+ "id": "dG5rIH8KHUOT"
+ },
+ "outputs": [],
+ "source": [
+ "from LRTestCases import *"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 50,
+ "metadata": {
+ "id": "1tOdDoSwZeIE"
+ },
+ "outputs": [],
+ "source": [
+ "def error(yhat, y):\n",
+ " error = yhat - y #Subtract y from yhat\n",
+ " return error"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 51,
+ "metadata": {
+ "id": "D7yM32C_Xz-g",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "ffb59f57-0026-44ba-dba0-5bdad7dc4ee7"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#TEST YOUR IMPLEMENTATION\n",
+ "test_error_function(error)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 52,
+ "metadata": {
+ "id": "Nnoygph2er5y"
+ },
+ "outputs": [],
+ "source": [
+ "def error_square(error):\n",
+ " square = error **2 #Square the error claculated above\n",
+ " return square"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 53,
+ "metadata": {
+ "id": "MHGCiEXJX_AR",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "883e2874-6c1b-4f32-f141-bf04c994655c"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#TEST YOUR IMPLEMENTATION\n",
+ "test_error_square_function(error_square)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 54,
+ "metadata": {
+ "id": "wgwOEQK9fMqA"
+ },
+ "outputs": [],
+ "source": [
+ "def total_squared_error(error, num):\n",
+ " total_squared_error = 0\n",
+ " for i in range(num):\n",
+ " total_squared_error = total_squared_error + error #Add the \"error\" to the \"total_sqared_error\"\n",
+ " return total_squared_error"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 55,
+ "metadata": {
+ "id": "ilzjasT4YJAh",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "955e953f-30c6-4ce8-e7df-0157a3db8b30"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#TEST YOUR IMPLEMENTATION\n",
+ "test_total_squared_error_function(total_squared_error)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "oS7bM8mBjJ-u"
+ },
+ "source": [
+ "$\\text{Mean Squared Error}=\\frac{1}{2*m}\\sum\\limits_{i = 0}^{m-1}(y-ŷ)^2$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 56,
+ "metadata": {
+ "id": "Q6sFN7i2piR8"
+ },
+ "outputs": [],
+ "source": [
+ "def mse(total_squared_error, num):\n",
+ " denominator = 2*num #Multipy num with 2\n",
+ " mse = total_squared_error/denominator #Divide \"total_sqaured_error\" by \"denominator\"\n",
+ " return num"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 57,
+ "metadata": {
+ "id": "fZ816KtRYsoj",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "8ee6b888-02f1-4c09-bb6e-13dd537638ba"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#TEST YOUR IMPLEMENTATION\n",
+ "test_mse_function(mse)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "3Uqj2E0BlU_U"
+ },
+ "source": [
+ "**Finding the predicted value**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 58,
+ "metadata": {
+ "id": "oiwBU-fSjp5C"
+ },
+ "outputs": [],
+ "source": [
+ "def predicted_value(w, x, b):\n",
+ " yhat = w*x+b #Multiply 'w' with 'x' and add 'b'\n",
+ " return yhat"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 59,
+ "metadata": {
+ "id": "MXs2kadnreTF",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "983f2ee4-cbc1-47ab-c3ef-47cf6e1ee5bd"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ],
+ "source": [
+ "#TEST YOUR IMPLEMENTATION\n",
+ "test_predicted_value(predicted_value)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "qW9qAdiUwOrk"
+ },
+ "source": [
+ "## Cost Function\n",
+ "The equation for cost with one variable is:\n",
+ "$$J(w,b) = \\frac{1}{2m} \\sum\\limits_{i = 0}^{m-1} (ŷ - y^{(i)})^2$$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 65,
+ "metadata": {
+ "id": "RCCqRXf-wNoI"
+ },
+ "outputs": [],
+ "source": [
+ "def compute_cost(x, y, w, b):\n",
+ " # number of training examples\n",
+ " m = x.shape[0]\n",
+ " total_squared_error = 0\n",
+ " for i in range(m):\n",
+ " yhat = w * x[i] + b\n",
+ " error = yhat - y[i] #Subtract \"y[i]\" from \"yhat\"\n",
+ " squared_error = error**2 #Square the error\n",
+ " total_squared_error = error + total_squared_error #Add the \"error\" to the \"total_sqared_error\"\n",
+ " denominator = m*2 #Multiply m by 2\n",
+ " total_cost = total_squared_error/denominator #Divide total_cost by denominator\n",
+ " return total_cost"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "OGswOCVFzR7W"
+ },
+ "source": [
+ "# Gradient Descent\n",
+ "## 1. Compute Gradient\n",
+ "The gradient is defined as:\n",
+ "$$\n",
+ "\\begin{align}\n",
+ "\\frac{\\partial J(w,b)}{\\partial w} &= \\frac{1}{m} \\sum\\limits_{i = 0}^{m-1} (ŷ - y^{(i)})x^{(i)} \\\\\n",
+ " \\frac{\\partial J(w,b)}{\\partial b} &= \\frac{1}{m} \\sum\\limits_{i = 0}^{m-1} (ŷ - y^{(i)}) \\\\\n",
+ "\\end{align}\n",
+ "$$"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 66,
+ "metadata": {
+ "id": "VMBk0PnA0wK3"
+ },
+ "outputs": [],
+ "source": [
+ "def compute_gradient(x, y, w, b):\n",
+ " # Number of training examples\n",
+ " m = x.shape[0]\n",
+ " dj_dw = 0\n",
+ " dj_db = 0\n",
+ "\n",
+ " for i in range(m):\n",
+ " yhat = w * x[i] + b\n",
+ " dj_dw_i = (yhat - y[i]) * x[i]\n",
+ " dj_db_i = yhat - y[i]\n",
+ " dj_db += dj_db_i\n",
+ " dj_dw += dj_dw_i\n",
+ " dj_dw = dj_dw / m\n",
+ " dj_db = dj_db / m\n",
+ "\n",
+ " return dj_dw, dj_db"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 67,
+ "metadata": {
+ "id": "3U-qZNSFE1QK",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "295516bf-cb99-42c1-e1c8-17c17e1d6681"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ],
+ "source": [
+ "test_compute_gradient(compute_gradient)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "AhWGXBq82p6P"
+ },
+ "source": [
+ "## 2. Update the parameters num_iterations times\n",
+ "$$\\begin{align*} \\text{repeat}&\\text{ until convergence:} \\; \\lbrace \\newline\n",
+ "\\; w &= w - \\alpha \\frac{\\partial J(w,b)}{\\partial w} \\; \\newline\n",
+ " b &= b - \\alpha \\frac{\\partial J(w,b)}{\\partial b} \\newline \\rbrace\n",
+ "\\end{align*}$$\n",
+ "where, parameters $w$, $b$ are updated simultaneously."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 68,
+ "metadata": {
+ "id": "OlNwBvu52cUv"
+ },
+ "outputs": [],
+ "source": [
+ "def gradient_descent(x, y, learning_rate, num_iterations):\n",
+ " # Initialize weights and bias\n",
+ " w = 0\n",
+ " b = 0\n",
+ " # Number of training examples\n",
+ " m = x.shape[0]\n",
+ " for _ in range(num_iterations):\n",
+ " # Compute gradients using the compute_gradient function\n",
+ " dj_dw, dj_db = compute_gradient(x, y, w, b)\n",
+ "\n",
+ " # Update weights and bias\n",
+ " w = w - learning_rate * dj_dw\n",
+ " b = b - learning_rate * dj_db\n",
+ " # Compute the cost for monitoring\n",
+ " cost = compute_cost(x, y, w, b)\n",
+ " print(f'Iteration {_+1}/{num_iterations}, Cost: {cost:.6f}')\n",
+ " return w, b"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 69,
+ "metadata": {
+ "id": "dpmvXbs4lmHO",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "20a72a06-6e97-4cc3-d294-6be9d01e96ae"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Iteration 1/10, Cost: -1.782000\n",
+ "Iteration 2/10, Cost: -1.589760\n",
+ "Iteration 3/10, Cost: -1.420232\n",
+ "Iteration 4/10, Cost: -1.270730\n",
+ "Iteration 5/10, Cost: -1.138884\n",
+ "Iteration 6/10, Cost: -1.022606\n",
+ "Iteration 7/10, Cost: -0.920053\n",
+ "Iteration 8/10, Cost: -0.829601\n",
+ "Iteration 9/10, Cost: -0.749820\n",
+ "Iteration 10/10, Cost: -0.679447\n",
+ "Final parameters: w = 0.7955, b = 0.2545\n",
+ "Final cost: -0.679447\n",
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ],
+ "source": [
+ "test_gradient_descent(gradient_descent, compute_cost, compute_gradient)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 69,
+ "metadata": {
+ "id": "NknHm9DGGonf"
+ },
+ "outputs": [],
+ "source": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "_Vb4kNxkG_Ml"
+ },
+ "source": [
+ "# **Project:** Melanoma Tumor Size Prediction"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 70,
+ "metadata": {
+ "id": "ibTpczTtGokE"
+ },
+ "outputs": [],
+ "source": [
+ "import pandas as pd\n",
+ "import numpy as np\n",
+ "from sklearn.linear_model import LinearRegression\n",
+ "from sklearn.metrics import mean_squared_error, mean_absolute_error\n",
+ "from sklearn.model_selection import train_test_split\n",
+ "import seaborn as sns\n",
+ "import matplotlib.pyplot as plt"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 71,
+ "metadata": {
+ "id": "eqAMMJ9lGohp"
+ },
+ "outputs": [],
+ "source": [
+ "#Read the dataset\n",
+ "data = pd.read_csv('/content/Machine-Learning-Simplified/Day-1/melanoma_dataset.csv')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 72,
+ "metadata": {
+ "id": "Q14KncK6GofO",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 423
+ },
+ "outputId": "c1c2ba0e-d576-4608-868c-82bc2d4cb538"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ " mass_npea tumor_size\n",
+ "0 18.159306 7.490802\n",
+ "1 39.693228 19.014286\n",
+ "2 32.659956 14.639879\n",
+ "3 27.556925 11.973170\n",
+ "4 9.800536 3.120373\n",
+ ".. ... ...\n",
+ "995 5.343260 1.831641\n",
+ "996 39.080774 18.346272\n",
+ "997 8.435708 2.736373\n",
+ "998 40.580192 19.004747\n",
+ "999 20.147810 8.920115\n",
+ "\n",
+ "[1000 rows x 2 columns]"
+ ],
+ "text/html": [
+ "\n",
+ "\n",
+ " | \n", + " | mass_npea | \n", + "tumor_size | \n", + "
|---|---|---|
| 0 | \n", + "18.159306 | \n", + "7.490802 | \n", + "
| 1 | \n", + "39.693228 | \n", + "19.014286 | \n", + "
| 2 | \n", + "32.659956 | \n", + "14.639879 | \n", + "
| 3 | \n", + "27.556925 | \n", + "11.973170 | \n", + "
| 4 | \n", + "9.800536 | \n", + "3.120373 | \n", + "
| ... | \n", + "... | \n", + "... | \n", + "
| 995 | \n", + "5.343260 | \n", + "1.831641 | \n", + "
| 996 | \n", + "39.080774 | \n", + "18.346272 | \n", + "
| 997 | \n", + "8.435708 | \n", + "2.736373 | \n", + "
| 998 | \n", + "40.580192 | \n", + "19.004747 | \n", + "
| 999 | \n", + "20.147810 | \n", + "8.920115 | \n", + "
1000 rows × 2 columns
\n", + "| \n", + " | mass_npea | \n", + "tumor_size | \n", + "
|---|---|---|
| count | \n", + "1000.000000 | \n", + "1000.000000 | \n", + "
| mean | \n", + "22.709158 | \n", + "9.805131 | \n", + "
| std | \n", + "11.682122 | \n", + "5.842747 | \n", + "
| min | \n", + "1.575483 | \n", + "0.092640 | \n", + "
| 25% | \n", + "12.290811 | \n", + "4.719465 | \n", + "
| 50% | \n", + "22.968280 | \n", + "9.936148 | \n", + "
| 75% | \n", + "32.664439 | \n", + "14.886392 | \n", + "
| max | \n", + "44.255681 | \n", + "19.994353 | \n", + "
LinearRegression()In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
LinearRegression()