None instances pesent in the code."
+ ],
+ "metadata": {
+ "id": "91bMnvq8oqbp"
+ }
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "!cp \"/content/Machine-Learning-Simplified/Day-1/LRTestCases.py\" \"/content/\""
+ ],
+ "metadata": {
+ "id": "6DNQ2HHJHjYZ"
+ },
+ "execution_count": 4,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "from LRTestCases import *"
+ ],
+ "metadata": {
+ "id": "dG5rIH8KHUOT"
+ },
+ "execution_count": 5,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 6,
+ "metadata": {
+ "id": "1tOdDoSwZeIE"
+ },
+ "outputs": [],
+ "source": [
+ "def error(yhat, y):\n",
+ " error = yhat-y #Subtract y from yhat\n",
+ " return error"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#TEST YOUR IMPLEMENTATION\n",
+ "test_error_function(error)"
+ ],
+ "metadata": {
+ "id": "D7yM32C_Xz-g",
+ "outputId": "aadd9af5-e683-4004-af05-31d11c6f100d",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "execution_count": 7,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "def error_square(error):\n",
+ " square = error #Square the error claculated above\n",
+ " return square"
+ ],
+ "metadata": {
+ "id": "Nnoygph2er5y"
+ },
+ "execution_count": 8,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#TEST YOUR IMPLEMENTATION\n",
+ "test_error_sqaure(error_square)"
+ ],
+ "metadata": {
+ "id": "MHGCiEXJX_AR",
+ "outputId": "9059134c-7f19-41e6-9815-c172cc439ccb",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 193
+ }
+ },
+ "execution_count": 10,
+ "outputs": [
+ {
+ "output_type": "error",
+ "ename": "NameError",
+ "evalue": "ignored",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
+ "\u001b[0;32mnum_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."
+ ],
+ "metadata": {
+ "id": "AhWGXBq82p6P"
+ }
+ },
+ {
+ "cell_type": "code",
+ "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"
+ ],
+ "metadata": {
+ "id": "OlNwBvu52cUv"
+ },
+ "execution_count": 19,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "test_gradient_descent(gradient_descent, compute_cost, compute_gradient)"
+ ],
+ "metadata": {
+ "id": "dpmvXbs4lmHO",
+ "outputId": "9e9c14d9-8cbe-42ff-e5ff-f4d4b8041f1f",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ }
+ },
+ "execution_count": 20,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "Iteration 1/10, Cost: 0.000000\n",
+ "Iteration 2/10, Cost: 0.000000\n",
+ "Iteration 3/10, Cost: 0.000000\n",
+ "Iteration 4/10, Cost: 0.000000\n",
+ "Iteration 5/10, Cost: 0.000000\n",
+ "Iteration 6/10, Cost: 0.000000\n",
+ "Iteration 7/10, Cost: 0.000000\n",
+ "Iteration 8/10, Cost: 0.000000\n",
+ "Iteration 9/10, Cost: 0.000000\n",
+ "Iteration 10/10, Cost: 0.000000\n",
+ "Final parameters: w = 0.7955, b = 0.2545\n",
+ "Final cost: 0.000000\n",
+ "\u001b[92mTest passed!\u001b[0m\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [],
+ "metadata": {
+ "id": "NknHm9DGGonf"
+ },
+ "execution_count": null,
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "# **Project:** Melanoma Tumor Size Prediction"
+ ],
+ "metadata": {
+ "id": "_Vb4kNxkG_Ml"
+ }
+ },
+ {
+ "cell_type": "code",
+ "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"
+ ],
+ "metadata": {
+ "id": "ibTpczTtGokE"
+ },
+ "execution_count": 21,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#Read the dataset\n",
+ "data = pd.read_csv('/content/Machine-Learning-Simplified/Day-1/melanoma_dataset.csv')"
+ ],
+ "metadata": {
+ "id": "eqAMMJ9lGohp"
+ },
+ "execution_count": 25,
+ "outputs": []
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "#Display the dataset\n",
+ "data"
+ ],
+ "metadata": {
+ "id": "Q14KncK6GofO",
+ "outputId": "27cb70ba-e8c5-43d5-b052-cf5d92cfd4fd",
+ "colab": {
+ "base_uri": "https://localhost:8080/",
+ "height": 424
+ }
+ },
+ "execution_count": 26,
+ "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()