{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "05f41765",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas\n",
    "from pandas import DataFrame\n",
    "import matplotlib.pyplot as plt\n",
    "from sklearn.linear_model import LinearRegression"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "7f82f718",
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pandas.read_csv('data.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "656efe3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "x= DataFrame(data, columns = ['col_1'])\n",
    "y= DataFrame(data, columns = ['col_2'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "6db0a71e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 44908 characters]",
      "text/plain": [
       "<Figure size 720x432 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.figure(figsize=(10,6))\n",
    "plt.scatter(x,y,alpha=.4)\n",
    "plt.xlim(0,4.5e8)\n",
    "plt.ylim(0,3e9)\n",
    "plt.xlabel(\"Feature\")\n",
    "plt.ylabel(\"Target\")\n",
    "plt.title(\"Feature v/s Target\")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "ec3fb414",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearRegression()"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# y = theta_0 + theta_1*X\n",
    "rgr = LinearRegression()\n",
    "rgr.fit(x,y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "40be1d77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[3.11150918]])"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#theta_1 or slope\n",
    "th0= rgr.coef_ \n",
    "th0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "e4c31635",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>production_budget_usd</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>10000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>400000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>750000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>10000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5029</th>\n",
       "      <td>225000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5030</th>\n",
       "      <td>215000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5031</th>\n",
       "      <td>306000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5032</th>\n",
       "      <td>200000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5033</th>\n",
       "      <td>425000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5034 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      production_budget_usd\n",
       "0                   1000000\n",
       "1                     10000\n",
       "2                    400000\n",
       "3                    750000\n",
       "4                     10000\n",
       "...                     ...\n",
       "5029              225000000\n",
       "5030              215000000\n",
       "5031              306000000\n",
       "5032              200000000\n",
       "5033              425000000\n",
       "\n",
       "[5034 rows x 1 columns]"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#theta_0 or c\n",
    "th1 = rgr.intercept_\n",
    "th1\n",
    "Y=rgr.predict(x)\n",
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0d71ef51",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "",
     "evalue": "",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31mRunning cells with 'Python 3.10.4 64-bit' requires ipykernel package.\n",
      "\u001b[1;31mRun the following command to install 'ipykernel' into the Python environment. \n",
      "\u001b[1;31mCommand: '\"c:/Program Files/Python310/python.exe\" -m pip install ipykernel -U --user --force-reinstall'"
     ]
    }
   ],
   "source": [
    "plt.figure(figsize=(10,6))\n",
    "plt.scatter(x,y,alpha=.3)\n",
    "\n",
    "plt.scatter(x,Y) \n",
    "plt.plot(x['col_1'],Y,color='black')  #to convert dataframe to an array \n",
    "plt.xlim(0,450000000)\n",
    "plt.ylim(0,3000000000)\n",
    "plt.xlabel(\"Feature\")\n",
    "plt.ylabel(\"Target\")\n",
    "plt.title(\"Feature v/s Target\")\n",
    "\n",
    "plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.10.4 64-bit",
   "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.10.4"
  },
  "vscode": {
   "interpreter": {
    "hash": "26de051ba29f2982a8de78e945f0abaf191376122a1563185a90213a26c5da77"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
