.
This commit is contained in:
commit
42a130e272
7 files changed
+9878
No files matched your search
@@ -0,0 +1,10 @@
|
|||||||
|
Source for dog vision:
|
||||||
|
https://www.kaggle.com/c/dog-breed-identification
|
||||||
|
|
||||||
|
Source for bulldozer
|
||||||
|
https://www.kaggle.com/c/bluebook-for-bulldozers
|
||||||
|
|
||||||
|
From course:
|
||||||
|
https://www.udemy.com/course/complete-machine-learning-and-data-science-zero-to-mastery
|
||||||
|
Github of course:
|
||||||
|
https://github.com/mrdbourke/zero-to-mastery-ml
|
||||||
Executable
+749
@@ -0,0 +1,749 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "e003c92d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import numpy as np\n",
|
||||||
|
"import matplotlib.pyplot as plt\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"import sklearn"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "0a095019",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df = pd.read_csv('./data/buldozer/TrainAndValid.csv',\n",
|
||||||
|
" low_memory=False)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"id": "9c376485",
|
||||||
|
"metadata": {
|
||||||
|
"scrolled": true
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"name": "stdout",
|
||||||
|
"output_type": "stream",
|
||||||
|
"text": [
|
||||||
|
"<class 'pandas.core.frame.DataFrame'>\n",
|
||||||
|
"RangeIndex: 412698 entries, 0 to 412697\n",
|
||||||
|
"Data columns (total 53 columns):\n",
|
||||||
|
" # Column Non-Null Count Dtype \n",
|
||||||
|
"--- ------ -------------- ----- \n",
|
||||||
|
" 0 SalesID 412698 non-null int64 \n",
|
||||||
|
" 1 SalePrice 412698 non-null float64\n",
|
||||||
|
" 2 MachineID 412698 non-null int64 \n",
|
||||||
|
" 3 ModelID 412698 non-null int64 \n",
|
||||||
|
" 4 datasource 412698 non-null int64 \n",
|
||||||
|
" 5 auctioneerID 392562 non-null float64\n",
|
||||||
|
" 6 YearMade 412698 non-null int64 \n",
|
||||||
|
" 7 MachineHoursCurrentMeter 147504 non-null float64\n",
|
||||||
|
" 8 UsageBand 73670 non-null object \n",
|
||||||
|
" 9 saledate 412698 non-null object \n",
|
||||||
|
" 10 fiModelDesc 412698 non-null object \n",
|
||||||
|
" 11 fiBaseModel 412698 non-null object \n",
|
||||||
|
" 12 fiSecondaryDesc 271971 non-null object \n",
|
||||||
|
" 13 fiModelSeries 58667 non-null object \n",
|
||||||
|
" 14 fiModelDescriptor 74816 non-null object \n",
|
||||||
|
" 15 ProductSize 196093 non-null object \n",
|
||||||
|
" 16 fiProductClassDesc 412698 non-null object \n",
|
||||||
|
" 17 state 412698 non-null object \n",
|
||||||
|
" 18 ProductGroup 412698 non-null object \n",
|
||||||
|
" 19 ProductGroupDesc 412698 non-null object \n",
|
||||||
|
" 20 Drive_System 107087 non-null object \n",
|
||||||
|
" 21 Enclosure 412364 non-null object \n",
|
||||||
|
" 22 Forks 197715 non-null object \n",
|
||||||
|
" 23 Pad_Type 81096 non-null object \n",
|
||||||
|
" 24 Ride_Control 152728 non-null object \n",
|
||||||
|
" 25 Stick 81096 non-null object \n",
|
||||||
|
" 26 Transmission 188007 non-null object \n",
|
||||||
|
" 27 Turbocharged 81096 non-null object \n",
|
||||||
|
" 28 Blade_Extension 25983 non-null object \n",
|
||||||
|
" 29 Blade_Width 25983 non-null object \n",
|
||||||
|
" 30 Enclosure_Type 25983 non-null object \n",
|
||||||
|
" 31 Engine_Horsepower 25983 non-null object \n",
|
||||||
|
" 32 Hydraulics 330133 non-null object \n",
|
||||||
|
" 33 Pushblock 25983 non-null object \n",
|
||||||
|
" 34 Ripper 106945 non-null object \n",
|
||||||
|
" 35 Scarifier 25994 non-null object \n",
|
||||||
|
" 36 Tip_Control 25983 non-null object \n",
|
||||||
|
" 37 Tire_Size 97638 non-null object \n",
|
||||||
|
" 38 Coupler 220679 non-null object \n",
|
||||||
|
" 39 Coupler_System 44974 non-null object \n",
|
||||||
|
" 40 Grouser_Tracks 44875 non-null object \n",
|
||||||
|
" 41 Hydraulics_Flow 44875 non-null object \n",
|
||||||
|
" 42 Track_Type 102193 non-null object \n",
|
||||||
|
" 43 Undercarriage_Pad_Width 102916 non-null object \n",
|
||||||
|
" 44 Stick_Length 102261 non-null object \n",
|
||||||
|
" 45 Thumb 102332 non-null object \n",
|
||||||
|
" 46 Pattern_Changer 102261 non-null object \n",
|
||||||
|
" 47 Grouser_Type 102193 non-null object \n",
|
||||||
|
" 48 Backhoe_Mounting 80712 non-null object \n",
|
||||||
|
" 49 Blade_Type 81875 non-null object \n",
|
||||||
|
" 50 Travel_Controls 81877 non-null object \n",
|
||||||
|
" 51 Differential_Type 71564 non-null object \n",
|
||||||
|
" 52 Steering_Controls 71522 non-null object \n",
|
||||||
|
"dtypes: float64(3), int64(5), object(45)\n",
|
||||||
|
"memory usage: 166.9+ MB\n"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df.info()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 16,
|
||||||
|
"id": "e4a4e252",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAD4CAYAAADRuPC7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMA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jW/pLfhERqYQCjIiIVKI/12BERIbEsnVbWLSila0dnUyeUMeCpuk0z6jvO6MMCwowIjIsLVu3hYVLN9C5N+4R2tLRycKlGwAUZEYIBRiRYUQ99i6LVrQeCC6Fzr37WbSi9bitk5FGAUZkmFCPvbutHZ0DSpfhRxf5RYaJ3nrsx6PJE+oGlC7DjwKMyDChHnt3C5qmUzdmVLe0ujGjWNA0fYhKJAOlACMyTKjH3l3zjHpuvPLd1E+ow4D6CXXceOW7j8vpwpFK12BEhokFTdO7XYMB9dibZ9QroIxgCjAiw0RxItVdZHKsUIARGUbUY5djia7BiIhIJRRgRESkEgowIiJSCQUYERGphAKMiIhUQgFGREQqoQAjIiKVUIAREZFKKMCIiEgl9Jf8IiJ90IPgBkcBRkSkF3oQ3OApwIjIQdRj76JHNw+eAoyIdKMee3d6ENzLine truncated
|
||||||
|
"text/plain": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"needs_background": "light"
|
||||||
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"fig, ax = plt.subplots()\n",
|
||||||
|
"ax.scatter(df['saledate'][:1000],df['SalePrice'][:1000]);"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 13,
|
||||||
|
"id": "ed600fdb",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAZgAAAD4CAYAAADRuPC7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAaoklEQVR4nO3dcZSV9X3n8fcnTIKaBAUZDZmhHYycpOhJVpkQ0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/X2YDYAOyR9g+KZXh+keHqxmZlZTfXOIlsh6QHg36bQhyPisXxpmZnZWFfvLTIovrflhYj4AsVDJGdkysnMzMaBeh92eSvwcWB5Cr0W+EqupMzMbOyrtwfzQeBa4CcAEXEAPyrGzMyGUW+BeSk97j4AJL0+X0pmZjYe1FtgNkn6EnCepN8FvsPofPmYmZmNU6ecRZa+zGsj8DbgBeCtwCcjYmvm3MzMbAw7ZYGJiJD0zYiYDbiomJlZXeq9RfZ9Se/MmomZmY0r9X6S/1eB35O0n2ImmSg6N2/PlZiZmY1tw/ZgJP1CWv0AcBHwPoonKV+TXkdE0nmSNkt6WtJTkt4taYqkrZL2ptfJpeOXS+qTtEfS/FJ8tqSdad/qNF6EpImSNqb4dkldI83VzMxG5lS3yL4JEBE/Aj4XET8qL2dw3S8A/zsi3ga8A3gKWAZsi4iZwLa0jaRZQA9wCbAAuF3Line truncated
|
||||||
|
"text/plain": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {
|
||||||
|
"needs_background": "light"
|
||||||
|
},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df['SalePrice'].plot.hist();"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 22,
|
||||||
|
"id": "a6d54b7d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df = pd.read_csv('./data/buldozer/TrainAndValid.csv',\n",
|
||||||
|
" low_memory=False,\n",
|
||||||
|
" parse_dates=['saledate'])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 23,
|
||||||
|
"id": "8796321f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"dtype('<M8[ns]')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 23,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df.saledate.dtype"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 24,
|
||||||
|
"id": "92d8711b",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0 2006-11-16\n",
|
||||||
|
"1 2004-03-26\n",
|
||||||
|
"2 2004-02-26\n",
|
||||||
|
"3 2011-05-19\n",
|
||||||
|
"4 2009-07-23\n",
|
||||||
|
"Name: saledate, dtype: datetime64[ns]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 24,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df.saledate.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 27,
|
||||||
|
"id": "a29e2ad0",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"205615 1989-01-17\n",
|
||||||
|
"233186 1989-01-31\n",
|
||||||
|
"142491 1989-01-31\n",
|
||||||
|
"115536 1989-01-31\n",
|
||||||
|
"92301 1989-01-31\n",
|
||||||
|
"Name: saledate, dtype: datetime64[ns]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 27,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df.sort_values(by=['saledate'],inplace=True,ascending=True)\n",
|
||||||
|
"df.saledate.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 28,
|
||||||
|
"id": "0a2a301d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df_tmp = df.copy()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 29,
|
||||||
|
"id": "34c4362d",
|
||||||
|
"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>SalesID</th>\n",
|
||||||
|
" <th>SalePrice</th>\n",
|
||||||
|
" <th>MachineID</th>\n",
|
||||||
|
" <th>ModelID</th>\n",
|
||||||
|
" <th>datasource</th>\n",
|
||||||
|
" <th>auctioneerID</th>\n",
|
||||||
|
" <th>YearMade</th>\n",
|
||||||
|
" <th>MachineHoursCurrentMeter</th>\n",
|
||||||
|
" <th>UsageBand</th>\n",
|
||||||
|
" <th>saledate</th>\n",
|
||||||
|
" <th>...</th>\n",
|
||||||
|
" <th>Undercarriage_Pad_Width</th>\n",
|
||||||
|
" <th>Stick_Length</th>\n",
|
||||||
|
" <th>Thumb</th>\n",
|
||||||
|
" <th>Pattern_Changer</th>\n",
|
||||||
|
" <th>Grouser_Type</th>\n",
|
||||||
|
" <th>Backhoe_Mounting</th>\n",
|
||||||
|
" <th>Blade_Type</th>\n",
|
||||||
|
" <th>Travel_Controls</th>\n",
|
||||||
|
" <th>Differential_Type</th>\n",
|
||||||
|
" <th>Steering_Controls</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>205615</th>\n",
|
||||||
|
" <td>1646770</td>\n",
|
||||||
|
" <td>9500.0</td>\n",
|
||||||
|
" <td>1126363</td>\n",
|
||||||
|
" <td>8434</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>18.0</td>\n",
|
||||||
|
" <td>1974</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-17</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>Straight</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>233186</th>\n",
|
||||||
|
" <td>1728883</td>\n",
|
||||||
|
" <td>30000.0</td>\n",
|
||||||
|
" <td>1523610</td>\n",
|
||||||
|
" <td>9105</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1986</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>142491</th>\n",
|
||||||
|
" <td>1508502</td>\n",
|
||||||
|
" <td>21000.0</td>\n",
|
||||||
|
" <td>1153157</td>\n",
|
||||||
|
" <td>4138</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1972</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>Angle</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>115536</th>\n",
|
||||||
|
" <td>1452578</td>\n",
|
||||||
|
" <td>33000.0</td>\n",
|
||||||
|
" <td>1544443</td>\n",
|
||||||
|
" <td>3854</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1974</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>Standard</td>\n",
|
||||||
|
" <td>Conventional</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>92301</th>\n",
|
||||||
|
" <td>1403418</td>\n",
|
||||||
|
" <td>24000.0</td>\n",
|
||||||
|
" <td>1390168</td>\n",
|
||||||
|
" <td>7110</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1986</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"<p>5 rows × 53 columns</p>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" SalesID SalePrice MachineID ModelID datasource auctioneerID \\\n",
|
||||||
|
"205615 1646770 9500.0 1126363 8434 132 18.0 \n",
|
||||||
|
"233186 1728883 30000.0 1523610 9105 132 99.0 \n",
|
||||||
|
"142491 1508502 21000.0 1153157 4138 132 99.0 \n",
|
||||||
|
"115536 1452578 33000.0 1544443 3854 132 99.0 \n",
|
||||||
|
"92301 1403418 24000.0 1390168 7110 132 99.0 \n",
|
||||||
|
"\n",
|
||||||
|
" YearMade MachineHoursCurrentMeter UsageBand saledate ... \\\n",
|
||||||
|
"205615 1974 NaN NaN 1989-01-17 ... \n",
|
||||||
|
"233186 1986 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"142491 1972 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"115536 1974 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"92301 1986 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"\n",
|
||||||
|
" Undercarriage_Pad_Width Stick_Length Thumb Pattern_Changer \\\n",
|
||||||
|
"205615 NaN NaN NaN NaN \n",
|
||||||
|
"233186 NaN NaN NaN NaN \n",
|
||||||
|
"142491 NaN NaN NaN NaN \n",
|
||||||
|
"115536 NaN NaN NaN NaN \n",
|
||||||
|
"92301 NaN NaN NaN NaN \n",
|
||||||
|
"\n",
|
||||||
|
" Grouser_Type Backhoe_Mounting Blade_Type Travel_Controls \\\n",
|
||||||
|
"205615 NaN None or Unspecified Straight None or Unspecified \n",
|
||||||
|
"233186 NaN NaN NaN NaN \n",
|
||||||
|
"142491 NaN None or Unspecified Angle None or Unspecified \n",
|
||||||
|
"115536 NaN NaN NaN NaN \n",
|
||||||
|
"92301 NaN NaN NaN NaN \n",
|
||||||
|
"\n",
|
||||||
|
" Differential_Type Steering_Controls \n",
|
||||||
|
"205615 NaN NaN \n",
|
||||||
|
"233186 NaN NaN \n",
|
||||||
|
"142491 NaN NaN \n",
|
||||||
|
"115536 Standard Conventional \n",
|
||||||
|
"92301 NaN NaN \n",
|
||||||
|
"\n",
|
||||||
|
"[5 rows x 53 columns]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 29,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df_tmp.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 31,
|
||||||
|
"id": "5c5497e4",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df_tmp['saleYear'] = df_tmp[:1].saledate.dt.year\n",
|
||||||
|
"df_tmp['saleMonth'] = df_tmp[:1].saledate.dt.month\n",
|
||||||
|
"df_tmp['saleDay'] = df_tmp[:1].saledate.dt.day\n",
|
||||||
|
"df_tmp['saleDayOfWeek'] = df_tmp[:1].saledate.dt.dayofweek\n",
|
||||||
|
"df_tmp['saleDayOYear'] = df_tmp[:1].saledate.dt.dayofyear"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 32,
|
||||||
|
"id": "6f16033a",
|
||||||
|
"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>SalesID</th>\n",
|
||||||
|
" <th>SalePrice</th>\n",
|
||||||
|
" <th>MachineID</th>\n",
|
||||||
|
" <th>ModelID</th>\n",
|
||||||
|
" <th>datasource</th>\n",
|
||||||
|
" <th>auctioneerID</th>\n",
|
||||||
|
" <th>YearMade</th>\n",
|
||||||
|
" <th>MachineHoursCurrentMeter</th>\n",
|
||||||
|
" <th>UsageBand</th>\n",
|
||||||
|
" <th>saledate</th>\n",
|
||||||
|
" <th>...</th>\n",
|
||||||
|
" <th>Backhoe_Mounting</th>\n",
|
||||||
|
" <th>Blade_Type</th>\n",
|
||||||
|
" <th>Travel_Controls</th>\n",
|
||||||
|
" <th>Differential_Type</th>\n",
|
||||||
|
" <th>Steering_Controls</th>\n",
|
||||||
|
" <th>saleYear</th>\n",
|
||||||
|
" <th>saleMonth</th>\n",
|
||||||
|
" <th>saleDay</th>\n",
|
||||||
|
" <th>saleDayOfWeek</th>\n",
|
||||||
|
" <th>saleDayOYear</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>205615</th>\n",
|
||||||
|
" <td>1646770</td>\n",
|
||||||
|
" <td>9500.0</td>\n",
|
||||||
|
" <td>1126363</td>\n",
|
||||||
|
" <td>8434</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>18.0</td>\n",
|
||||||
|
" <td>1974</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-17</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>Straight</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989.0</td>\n",
|
||||||
|
" <td>1.0</td>\n",
|
||||||
|
" <td>17.0</td>\n",
|
||||||
|
" <td>1.0</td>\n",
|
||||||
|
" <td>17.0</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>233186</th>\n",
|
||||||
|
" <td>1728883</td>\n",
|
||||||
|
" <td>30000.0</td>\n",
|
||||||
|
" <td>1523610</td>\n",
|
||||||
|
" <td>9105</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1986</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>142491</th>\n",
|
||||||
|
" <td>1508502</td>\n",
|
||||||
|
" <td>21000.0</td>\n",
|
||||||
|
" <td>1153157</td>\n",
|
||||||
|
" <td>4138</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1972</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>Angle</td>\n",
|
||||||
|
" <td>None or Unspecified</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>115536</th>\n",
|
||||||
|
" <td>1452578</td>\n",
|
||||||
|
" <td>33000.0</td>\n",
|
||||||
|
" <td>1544443</td>\n",
|
||||||
|
" <td>3854</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1974</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>Standard</td>\n",
|
||||||
|
" <td>Conventional</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>92301</th>\n",
|
||||||
|
" <td>1403418</td>\n",
|
||||||
|
" <td>24000.0</td>\n",
|
||||||
|
" <td>1390168</td>\n",
|
||||||
|
" <td>7110</td>\n",
|
||||||
|
" <td>132</td>\n",
|
||||||
|
" <td>99.0</td>\n",
|
||||||
|
" <td>1986</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>1989-01-31</td>\n",
|
||||||
|
" <td>...</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" <td>NaN</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"<p>5 rows × 58 columns</p>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" SalesID SalePrice MachineID ModelID datasource auctioneerID \\\n",
|
||||||
|
"205615 1646770 9500.0 1126363 8434 132 18.0 \n",
|
||||||
|
"233186 1728883 30000.0 1523610 9105 132 99.0 \n",
|
||||||
|
"142491 1508502 21000.0 1153157 4138 132 99.0 \n",
|
||||||
|
"115536 1452578 33000.0 1544443 3854 132 99.0 \n",
|
||||||
|
"92301 1403418 24000.0 1390168 7110 132 99.0 \n",
|
||||||
|
"\n",
|
||||||
|
" YearMade MachineHoursCurrentMeter UsageBand saledate ... \\\n",
|
||||||
|
"205615 1974 NaN NaN 1989-01-17 ... \n",
|
||||||
|
"233186 1986 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"142491 1972 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"115536 1974 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"92301 1986 NaN NaN 1989-01-31 ... \n",
|
||||||
|
"\n",
|
||||||
|
" Backhoe_Mounting Blade_Type Travel_Controls Differential_Type \\\n",
|
||||||
|
"205615 None or Unspecified Straight None or Unspecified NaN \n",
|
||||||
|
"233186 NaN NaN NaN NaN \n",
|
||||||
|
"142491 None or Unspecified Angle None or Unspecified NaN \n",
|
||||||
|
"115536 NaN NaN NaN Standard \n",
|
||||||
|
"92301 NaN NaN NaN NaN \n",
|
||||||
|
"\n",
|
||||||
|
" Steering_Controls saleYear saleMonth saleDay saleDayOfWeek saleDayOYear \n",
|
||||||
|
"205615 NaN 1989.0 1.0 17.0 1.0 17.0 \n",
|
||||||
|
"233186 NaN NaN NaN NaN NaN NaN \n",
|
||||||
|
"142491 NaN NaN NaN NaN NaN NaN \n",
|
||||||
|
"115536 Conventional NaN NaN NaN NaN NaN \n",
|
||||||
|
"92301 NaN NaN NaN NaN NaN NaN \n",
|
||||||
|
"\n",
|
||||||
|
"[5 rows x 58 columns]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 32,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"df_tmp.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 35,
|
||||||
|
"id": "c02bc1ce",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"df_tmp.drop('saledate',axis=1,inplace=True)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "e8765a53",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.ensemble import RandomForestRegressor\n",
|
||||||
|
"model = RandomForestRegressor(n_jobs=-1,\n",
|
||||||
|
" random_state=42)\n",
|
||||||
|
"model.fit"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
Executable
+837
@@ -0,0 +1,837 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 4,
|
||||||
|
"id": "7a9115cb",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"import matplotlib.pyplot as plt\n",
|
||||||
|
"import pandas as pd\n",
|
||||||
|
"import numpy as np\n",
|
||||||
|
"import seaborn as sns; sns.set()\n",
|
||||||
|
"from sklearn.model_selection import train_test_split"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 5,
|
||||||
|
"id": "b58c3a40",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"heart_disease=pd.read_csv('./data/heart-disease.csv')"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 6,
|
||||||
|
"id": "0bc694fa",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"x = heart_disease.drop('target',axis=1)\n",
|
||||||
|
"y = heart_disease['target']\n",
|
||||||
|
"\n",
|
||||||
|
"x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 7,
|
||||||
|
"id": "91e073a1",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.7868852459016393"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 7,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.ensemble import RandomForestClassifier\n",
|
||||||
|
"x = heart_disease.drop('target',axis=1)\n",
|
||||||
|
"y = heart_disease['target']\n",
|
||||||
|
"\n",
|
||||||
|
"x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)\n",
|
||||||
|
"\n",
|
||||||
|
"clf = RandomForestClassifier()\n",
|
||||||
|
"clf.fit(x_train, y_train)\n",
|
||||||
|
"\n",
|
||||||
|
"clf.score(x_test, y_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 8,
|
||||||
|
"id": "33eb1968",
|
||||||
|
"metadata": {
|
||||||
|
"scrolled": true
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1,\n",
|
||||||
|
" 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1,\n",
|
||||||
|
" 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1], dtype=int64)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 8,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"clf.predict(x_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 9,
|
||||||
|
"id": "5dc76fe7",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.7868852459016393"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 9,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"y_preds = clf.predict(x_test)\n",
|
||||||
|
"np.mean(y_preds == y_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 10,
|
||||||
|
"id": "3e29898c",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([[0.16, 0.84],\n",
|
||||||
|
" [0. , 1. ],\n",
|
||||||
|
" [0.14, 0.86],\n",
|
||||||
|
" [0.69, 0.31],\n",
|
||||||
|
" [0.21, 0.79]])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 10,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"clf.predict_proba(x_test[:5])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 15,
|
||||||
|
"id": "8f29756f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([1, 1, 1, 0, 1], dtype=int64)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 15,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"clf.predict(x_test[:5])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 17,
|
||||||
|
"id": "58ecfe8a",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.ensemble import RandomForestRegressor\n",
|
||||||
|
"from sklearn.datasets import fetch_california_housing\n",
|
||||||
|
"np.random.seed(42)\n",
|
||||||
|
"housing = fetch_california_housing()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 18,
|
||||||
|
"id": "969a0902",
|
||||||
|
"metadata": {
|
||||||
|
"scrolled": true
|
||||||
|
},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"{'data': array([[ 8.3252 , 41. , 6.98412698, ..., 2.55555556,\n",
|
||||||
|
" 37.88 , -122.23 ],\n",
|
||||||
|
" [ 8.3014 , 21. , 6.23813708, ..., 2.10984183,\n",
|
||||||
|
" 37.86 , -122.22 ],\n",
|
||||||
|
" [ 7.2574 , 52. , 8.28813559, ..., 2.80225989,\n",
|
||||||
|
" 37.85 , -122.24 ],\n",
|
||||||
|
" ...,\n",
|
||||||
|
" [ 1.7 , 17. , 5.20554273, ..., 2.3256351 ,\n",
|
||||||
|
" 39.43 , -121.22 ],\n",
|
||||||
|
" [ 1.8672 , 18. , 5.32951289, ..., 2.12320917,\n",
|
||||||
|
" 39.43 , -121.32 ],\n",
|
||||||
|
" [ 2.3886 , 16. , 5.25471698, ..., 2.61698113,\n",
|
||||||
|
" 39.37 , -121.24 ]]),\n",
|
||||||
|
" 'target': array([4.526, 3.585, 3.521, ..., 0.923, 0.847, 0.894]),\n",
|
||||||
|
" 'frame': None,\n",
|
||||||
|
" 'target_names': ['MedHouseVal'],\n",
|
||||||
|
" 'feature_names': ['MedInc',\n",
|
||||||
|
" 'HouseAge',\n",
|
||||||
|
" 'AveRooms',\n",
|
||||||
|
" 'AveBedrms',\n",
|
||||||
|
" 'Population',\n",
|
||||||
|
" 'AveOccup',\n",
|
||||||
|
" 'Latitude',\n",
|
||||||
|
" 'Longitude'],\n",
|
||||||
|
" 'DESCR': '.. _california_housing_dataset:\\n\\nCalifornia Housing dataset\\n--------------------------\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 20640\\n\\n :Number of Attributes: 8 numeric, predictive attributes and the target\\n\\n :Attribute Information:\\n - MedInc median income in block group\\n - HouseAge median house age in block group\\n - AveRooms average number of rooms per household\\n - AveBedrms average number of bedrooms per household\\n - Population block group population\\n - AveOccup average number of household members\\n - Latitude block group latitude\\n - Longitude block group longitude\\n\\n :Missing Attribute Values: None\\n\\nThis dataset was obtained from the StatLib repository.\\nhttps://www.dcc.fc.up.pt/~ltorgo/Regression/cal_housing.html\\n\\nThe target variable is the median house value for California districts,\\nexpressed in hundreds of thousands of dollars ($100,000).\\n\\nThis dataset was derived from the 1990 U.S. census, using one row per census\\nblock group. A block group is the smallest geographical unit for which the U.S.\\nCensus Bureau publishes sample data (a block group typically has a population\\nof 600 to 3,000 people).\\n\\nAn household is a group of people residing within a home. Since the average\\nnumber of rooms and bedrooms in this dataset are provided per household, these\\ncolumns may take surpinsingly large values for block groups with few households\\nand many empty houses, such as vacation resorts.\\n\\nIt can be downloaded/loaded using the\\n:func:`sklearn.datasets.fetch_california_housing` function.\\n\\n.. topic:: References\\n\\n - Pace, R. Kelley and Ronald Barry, Sparse Spatial Autoregressions,\\n Statistics and Probability Letters, 33 (1997) 291-297\\n'}"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 18,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"housing"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 27,
|
||||||
|
"id": "ba187d99",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"housing_df = pd.DataFrame(housing['data'],\n",
|
||||||
|
" columns=housing['feature_names'])\n",
|
||||||
|
"housing_df['target']=housing['target']\n"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 29,
|
||||||
|
"id": "f47503b8",
|
||||||
|
"metadata": {
|
||||||
|
"scrolled": true
|
||||||
|
},
|
||||||
|
"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>MedInc</th>\n",
|
||||||
|
" <th>HouseAge</th>\n",
|
||||||
|
" <th>AveRooms</th>\n",
|
||||||
|
" <th>AveBedrms</th>\n",
|
||||||
|
" <th>Population</th>\n",
|
||||||
|
" <th>AveOccup</th>\n",
|
||||||
|
" <th>Latitude</th>\n",
|
||||||
|
" <th>Longitude</th>\n",
|
||||||
|
" <th>target</th>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </thead>\n",
|
||||||
|
" <tbody>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>0</th>\n",
|
||||||
|
" <td>8.3252</td>\n",
|
||||||
|
" <td>41.0</td>\n",
|
||||||
|
" <td>6.984127</td>\n",
|
||||||
|
" <td>1.023810</td>\n",
|
||||||
|
" <td>322.0</td>\n",
|
||||||
|
" <td>2.555556</td>\n",
|
||||||
|
" <td>37.88</td>\n",
|
||||||
|
" <td>-122.23</td>\n",
|
||||||
|
" <td>4.526</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>1</th>\n",
|
||||||
|
" <td>8.3014</td>\n",
|
||||||
|
" <td>21.0</td>\n",
|
||||||
|
" <td>6.238137</td>\n",
|
||||||
|
" <td>0.971880</td>\n",
|
||||||
|
" <td>2401.0</td>\n",
|
||||||
|
" <td>2.109842</td>\n",
|
||||||
|
" <td>37.86</td>\n",
|
||||||
|
" <td>-122.22</td>\n",
|
||||||
|
" <td>3.585</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>2</th>\n",
|
||||||
|
" <td>7.2574</td>\n",
|
||||||
|
" <td>52.0</td>\n",
|
||||||
|
" <td>8.288136</td>\n",
|
||||||
|
" <td>1.073446</td>\n",
|
||||||
|
" <td>496.0</td>\n",
|
||||||
|
" <td>2.802260</td>\n",
|
||||||
|
" <td>37.85</td>\n",
|
||||||
|
" <td>-122.24</td>\n",
|
||||||
|
" <td>3.521</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>3</th>\n",
|
||||||
|
" <td>5.6431</td>\n",
|
||||||
|
" <td>52.0</td>\n",
|
||||||
|
" <td>5.817352</td>\n",
|
||||||
|
" <td>1.073059</td>\n",
|
||||||
|
" <td>558.0</td>\n",
|
||||||
|
" <td>2.547945</td>\n",
|
||||||
|
" <td>37.85</td>\n",
|
||||||
|
" <td>-122.25</td>\n",
|
||||||
|
" <td>3.413</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" <tr>\n",
|
||||||
|
" <th>4</th>\n",
|
||||||
|
" <td>3.8462</td>\n",
|
||||||
|
" <td>52.0</td>\n",
|
||||||
|
" <td>6.281853</td>\n",
|
||||||
|
" <td>1.081081</td>\n",
|
||||||
|
" <td>565.0</td>\n",
|
||||||
|
" <td>2.181467</td>\n",
|
||||||
|
" <td>37.85</td>\n",
|
||||||
|
" <td>-122.25</td>\n",
|
||||||
|
" <td>3.422</td>\n",
|
||||||
|
" </tr>\n",
|
||||||
|
" </tbody>\n",
|
||||||
|
"</table>\n",
|
||||||
|
"</div>"
|
||||||
|
],
|
||||||
|
"text/plain": [
|
||||||
|
" MedInc HouseAge AveRooms AveBedrms Population AveOccup Latitude \\\n",
|
||||||
|
"0 8.3252 41.0 6.984127 1.023810 322.0 2.555556 37.88 \n",
|
||||||
|
"1 8.3014 21.0 6.238137 0.971880 2401.0 2.109842 37.86 \n",
|
||||||
|
"2 7.2574 52.0 8.288136 1.073446 496.0 2.802260 37.85 \n",
|
||||||
|
"3 5.6431 52.0 5.817352 1.073059 558.0 2.547945 37.85 \n",
|
||||||
|
"4 3.8462 52.0 6.281853 1.081081 565.0 2.181467 37.85 \n",
|
||||||
|
"\n",
|
||||||
|
" Longitude target \n",
|
||||||
|
"0 -122.23 4.526 \n",
|
||||||
|
"1 -122.22 3.585 \n",
|
||||||
|
"2 -122.24 3.521 \n",
|
||||||
|
"3 -122.25 3.413 \n",
|
||||||
|
"4 -122.25 3.422 "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 29,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"housing_df.head()"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 33,
|
||||||
|
"id": "4346e2e7",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.model_selection import train_test_split\n",
|
||||||
|
"\n",
|
||||||
|
"X = housing_df.drop('target', axis=1)\n",
|
||||||
|
"y = housing['target']\n",
|
||||||
|
"\n",
|
||||||
|
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 37,
|
||||||
|
"id": "cd0d7834",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"model = RandomForestRegressor(n_estimators=1000)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 38,
|
||||||
|
"id": "0e65ca48",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"RandomForestRegressor(n_estimators=1000)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 38,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"model.fit(X_train, y_train)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 39,
|
||||||
|
"id": "394a8a63",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.8077999156142389"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 39,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"model.score(X_test,y_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 41,
|
||||||
|
"id": "2c4bb4b8",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"y_preds = model.predict(X_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 42,
|
||||||
|
"id": "ff01087a",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([0.659563 , 2.69825401, 4.99800197, ..., 0.84376895, 4.72698433,\n",
|
||||||
|
" 2.33940125])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 42,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"y_preds"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 44,
|
||||||
|
"id": "7516e56f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([0.696 , 3.356 , 5.00001, 3.606 , 2.766 , 0.835 , 1.22 ,\n",
|
||||||
|
" 1.693 , 3.153 , 0.789 ])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 44,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"np.array(y_test[:10])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 57,
|
||||||
|
"id": "aab2f50d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"RandomForestRegressor(n_estimators=1000)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 57,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.ensemble import RandomForestClassifier\n",
|
||||||
|
"\n",
|
||||||
|
"X = heart_disease.drop('target', axis=1)\n",
|
||||||
|
"y = heart_disease['target']\n",
|
||||||
|
"\n",
|
||||||
|
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
|
||||||
|
"\n",
|
||||||
|
"model = RandomForestClassifier(n_estimators=1000)\n",
|
||||||
|
"model.fit(X_train, y_train)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 59,
|
||||||
|
"id": "8617403d",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.4126102400932402"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 59,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"model.score(X_test, y_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 88,
|
||||||
|
"id": "37f1f469",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"RandomForestRegressor(n_estimators=50)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 88,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.ensemble import RandomForestRegressor\n",
|
||||||
|
"\n",
|
||||||
|
"X = heart_disease.drop('target', axis=1)\n",
|
||||||
|
"y = heart_disease['target']\n",
|
||||||
|
"\n",
|
||||||
|
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
|
||||||
|
"\n",
|
||||||
|
"model_reg = RandomForestRegressor(n_estimators=50)\n",
|
||||||
|
"model_reg.fit(X_train, y_train)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 89,
|
||||||
|
"id": "00bd7beb",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.1977237472766885"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 89,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"model_reg.score(X_test,y_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 90,
|
||||||
|
"id": "43d63da0",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.2423773420479305"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 90,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"maximum = 0\n",
|
||||||
|
"for i in range(10):\n",
|
||||||
|
" model_reg.fit(X_train, y_train)\n",
|
||||||
|
" if maximum < model_reg.score(X_test,y_test):\n",
|
||||||
|
" maximum = model_reg.score(X_test,y_test)\n",
|
||||||
|
"maximum"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 96,
|
||||||
|
"id": "a43b1703",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([0.83606557, 0.90163934, 0.78688525, 0.8 , 0.76666667])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 96,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.model_selection import cross_val_score\n",
|
||||||
|
"from sklearn.ensemble import RandomForestClassifier\n",
|
||||||
|
"\n",
|
||||||
|
"X = heart_disease.drop('target', axis=1)\n",
|
||||||
|
"y = heart_disease['target']\n",
|
||||||
|
"\n",
|
||||||
|
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
|
||||||
|
"\n",
|
||||||
|
"model = RandomForestClassifier(n_estimators=1000)\n",
|
||||||
|
"model.fit(X_train, y_train)\n",
|
||||||
|
"cross_val_score(model, X, y)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 94,
|
||||||
|
"id": "3801871c",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.819672131147541"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 94,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"model.score(X_test, y_test)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 97,
|
||||||
|
"id": "9e096485",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.8316129032258065"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 97,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"np.mean(cross_val_score(clf, X, y, cv=10))"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 98,
|
||||||
|
"id": "4a3038da",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([0.81967213, 0.8852459 , 0.80327869, 0.8 , 0.8 ])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 98,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"cross_val_score(clf, X, y, scoring=None )"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 102,
|
||||||
|
"id": "e1098ca4",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.metrics import roc_curve\n",
|
||||||
|
"X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
|
||||||
|
"\n",
|
||||||
|
"y_probs = clf.predict_proba(X_test)\n",
|
||||||
|
"y_probs_positive = y_probs[:,1]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 104,
|
||||||
|
"id": "ba39424f",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"fpr, tpr, thresholds =roc_curve(y_test, y_probs_positive)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 107,
|
||||||
|
"id": "1a5d135c",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"array([0. , 0. , 0. , 0. , 0. ,\n",
|
||||||
|
" 0.03571429, 0.03571429, 0.03571429, 0.03571429, 0.03571429,\n",
|
||||||
|
" 0.03571429, 0.03571429, 0.07142857, 0.07142857, 0.32142857,\n",
|
||||||
|
" 0.39285714, 0.71428571, 1. ])"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 107,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"fpr"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 108,
|
||||||
|
"id": "88352c7e",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def plot_roc_curve(fpr, tpr):\n",
|
||||||
|
" plt.plot(fpr, tpr, c='orange', label='ROC')\n",
|
||||||
|
" plt.plot([0,1],[0,1],c='darkblue', label='Guessing')\n",
|
||||||
|
" \n",
|
||||||
|
" plt.xlabel('FPR')\n",
|
||||||
|
" plt.ylabel('TPR')\n",
|
||||||
|
" plt.title('ROC curve')\n",
|
||||||
|
" "
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 109,
|
||||||
|
"id": "eaf11c67",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEXCAYAAACtTzM+AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjQuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/MnkTPAAAACXBIWXMAAAsTAAALEwEAmpwYAAAvi0lEQVR4nO3deXxM9/7H8VeCbIIQk6RVtVTFFntrKXJpiSIU1fXSxdXq8nMNgiax1ZZaGpfeLtEqLmqpvb1FS8USai+1FKW1lGQiloTsc35/1M29qSVBJpPMvJ+PRx+PnJwz5v2VmnfOzJzPuBiGYSAiIk7P1d4BRESkaFAhiIgIoEIQEZHrVAgiIgKoEERE5DoVgoiIAFDS3gFEbC0wMJCaNWvi6uqKi4sLqampeHt7M3r0aIKCggC4du0aM2bMYMOGDbi5uQHQrl073njjDTw8PHL+rOXLl7Nw4ULS0tLIzMykSZMmhIWFUbZsWbusTaQgueg6BHF0gYGBbNu2jQoVKuR877PPPmPdunUsWrSIrKwsXnzxRRo2bMjAgQPx9PQkNTWVqVOncvjwYebMmUPJkiX5+OOP2bRpE9OnT6dixYpkZmYyYcIEfv75ZxYsWGDHFYoUDJ0hiNPJysri3LlzlCtXDoA1a9ZgtVp55513co7x9PQkIiKCp556im+//Zbg4GA++eQTli9fTsWKFQEoVaoUQ4cO5dtvvyUjIyPnzOI/vv/+e6ZNm4bVasXLy4sxY8bg7e1NaGgoe/fuBeDMmTM528uWLePLL7/MOYPJzMzklVdeISQkBIDJkycDEBYWxpIlS/jiiy+wWq34+PgwYsQIHnroIZv/3YljUyGIU3jppZcAuHjxIu7u7rRt25aJEycCsHfvXpo2bXrDbVxcXGjRogW7d++mcuXKeHh4ULVq1VzHeHp60rVr1xtum5iYSFhYGHPnzqVOnTqsW7eOKVOmMHr06NvmPH78OBs2bMDb25ulS5eybNkyQkJCyM7OZtWqVfzrX/9ix44drFixgvnz5+Pp6cmWLVt4++23+eabb+7uL0fkOhWCOIU5c+ZQoUIFDh48yGuvvUazZs3w9fXN2Z+VlXXT22VkZFCiRAlcXV2xWq35vr89e/bw8MMPU6dOHQA6dOhAhw4dOHPmzG1vFxgYiLe3NwCdOnVi0qRJWCwWDh06RNWqValatSqLFy/mt99+47nnnsu53ZUrV7h06RI+Pj75zijyZ3qXkTiVunXr8s477zB8+PCcB+fGjRuza9euGx7wrVYrO3fupFGjRtSoUYOsrCx+/fXXXMekp6fTr18/4uPjc32/RIkSuLi45GwbhsGRI0dwcXHhf1+2y8zMzHU7Ly+vnK89PT0JCQnhq6++YunSpfTq1SsnV7du3Vi5ciUrV65k+fLlLF26NOcpMJG7pUIQp9OlSxfq16+f85RRSEgInp6eTJgwgbS0NADS0tIYO3YspUuXpn379ri5udGvXz8iIiJITEwE/jh7mDBhAqmpqfj7++e6jwYNGvDLL79w7NgxANavX5/zbqTMzEyOHz8OwNdff33brM888wzLly9nz549Oa8ltGrViq+//pqEhAQAvvjii5ynxETuhZ4yEqc0YsQIunbtyubNm2ndujWzZs3iww8/pEePHri6upKdnU27du2YNWsWpUqVAqB///54enrSt29f4I+zg0cffZQPP/zwhj+/YsWKTJkyhWHDhpGdnY23tzfR0dGUKVOGsLAw+vXrR4UKFejYseNtc9arV48SJUrQsWNH3N3dgT8KoV+/frz66qu4uLjg7e3NBx98kOuMRORu6G2nIiIC6CkjERG5ToUgIiKACkFERK5TIYiICKBCEBGR61QIIiICFPPrEC5evIrVeufvmvX19ebChRQbJCq6tGbnoDU7h7tds6urC+XLl77l/mJdCFarcVeF8J/bOhut2Tlozc7BFmvWU0YiIgKoEERE5DoVgoiIADY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+PHjuY4ZP348AwYMYNWqVVSrVo3PPvvMVnFExEGdOHGJXr2+ZuDAWOrW9WXjxl68/XZDSpa06e+7Dslmf2NxcXE0b94cHx8fvLy8CAkJYc2aNbmOsVqtXL16FYDU1FQ8PIrvh1OLSOHKzrbyySf7CQqazZ49CUya1Jrly0OpXr2cvaMVWzZ7DSEhIQGTyZSz7efnx/79+3MdM3z4cF599VUmTJiAp6cnixcvvqP78PX1vut8JlM+Blf96gauLvk7thhwlHXcCa3ZMR06lEjfvmvZvv0cnTpV4+OP21O5cll7xypUtvg526wQrFZrrgFRhmHk2k5LSyMiIoLZs2dTv359Pv/8c4YNG0ZMTEy+7+PChRSsVuOOs5lMZbBYkvM8zjs1A3erwYV8HFvU5XfNjkRrdjwZGdnMmLGP6Og9eHu78eGH7ejfvxGJiSkOve4/u9ufs6ury21/kbbZU0YBAQFYLJacbYvFgp+fX8720aNHcXd3p379+gA8++yz7Nixw1ZxRKSY27fPQocOy3jvvV107lyNzZuf4emnnXcyqS3YrBBatmzJtm3bSEpKIjU1lXXr1tGmTZuc/VWqVOH8+fOcOHECgPXr1xMUFGSrOCJSTKWmZjFmzHY6dlxOUlIac+eG8MknT2Ayedo7msOx2VNG/v7+mM1m+vTpQ2ZmJk8//TT169enX79+DBgwgKCgICZOnMjAgQMxDANfX18mTJhgqzgiUgzFxf2O2RzLyZNX6N27FiNHNqdcOQ2jsxWbXpgWGhpKaGhoru/NnDkz5+vg4GCCg4NtGUFEiqHk5AzeffcH5sw5RJUqZVm6tAuLine truncated
|
||||||
|
"text/plain": [
|
||||||
|
"<Figure size 432x288 with 1 Axes>"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "display_data"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"plot_roc_curve(fpr,tpr)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 110,
|
||||||
|
"id": "8cae5ee2",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [
|
||||||
|
{
|
||||||
|
"data": {
|
||||||
|
"text/plain": [
|
||||||
|
"0.9751082251082251"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"execution_count": 110,
|
||||||
|
"metadata": {},
|
||||||
|
"output_type": "execute_result"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"source": [
|
||||||
|
"from sklearn.metrics import roc_auc_score\n",
|
||||||
|
"\n",
|
||||||
|
"roc_auc_score(y_test, y_probs_positive)"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
Executable
+1559
File diff suppressed because it is too large.
Load diff
Executable
+159
@@ -0,0 +1,159 @@
|
|||||||
|
{
|
||||||
|
"cells": [
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "31ec7db3",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"#https://www.youtube.com/watch?v=w8yWXqWQYmU\n",
|
||||||
|
"\n",
|
||||||
|
"data = np.array(data)\n",
|
||||||
|
"m, n = data.shape\n",
|
||||||
|
"np.random.shuffle(data) # shuffle before splitting into dev and training sets\n",
|
||||||
|
"\n",
|
||||||
|
"data_dev = data[0:1000].T\n",
|
||||||
|
"Y_dev = data_dev[0]\n",
|
||||||
|
"X_dev = data_dev[1:n]\n",
|
||||||
|
"X_dev = X_dev / 255.\n",
|
||||||
|
"\n",
|
||||||
|
"data_train = data[1000:m].T\n",
|
||||||
|
"Y_train = data_train[0]\n",
|
||||||
|
"X_train = data_train[1:n]\n",
|
||||||
|
"X_train = X_train / 255.\n",
|
||||||
|
"_,m_train = X_train.shape"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 2,
|
||||||
|
"id": "4e2a280c",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def init_params():\n",
|
||||||
|
" W1 = np.random.rand(10, 784) - 0.5\n",
|
||||||
|
" b1 = np.random.rand(10, 1) - 0.5\n",
|
||||||
|
" W2 = np.random.rand(10, 10) - 0.5\n",
|
||||||
|
" b2 = np.random.rand(10, 1) - 0.5\n",
|
||||||
|
" return W1, b1, W2, b2\n",
|
||||||
|
"\n",
|
||||||
|
"def ReLU(Z):\n",
|
||||||
|
" return np.maximum(Z, 0)\n",
|
||||||
|
"\n",
|
||||||
|
"def softmax(Z):\n",
|
||||||
|
" A = np.exp(Z) / sum(np.exp(Z))\n",
|
||||||
|
" return A\n",
|
||||||
|
" \n",
|
||||||
|
"def forward_prop(W1, b1, W2, b2, X):\n",
|
||||||
|
" \"\"\"W1,W2 are wights, b1,b2 are biasis X is the input\"\"\"\n",
|
||||||
|
" Z1 = W1.dot(X) + b1 # value of layer 1 \n",
|
||||||
|
" A1 = ReLU(Z1) # value of layer 1 after applying activation\n",
|
||||||
|
" Z2 = W2.dot(A1) + b2 # value of layer 2\n",
|
||||||
|
" A2 = softmax(Z2) # value of layer 2 after applying activation\n",
|
||||||
|
" return Z1, A1, Z2, A2\n",
|
||||||
|
"\n",
|
||||||
|
"def ReLU_deriv(Z):\n",
|
||||||
|
" return Z > 0\n",
|
||||||
|
"\n",
|
||||||
|
"def one_hot(Y):\n",
|
||||||
|
" one_hot_Y = np.zeros((Y.size, Y.max() + 1))\n",
|
||||||
|
" one_hot_Y[np.arange(Y.size), Y] = 1\n",
|
||||||
|
" one_hot_Y = one_hot_Y.T\n",
|
||||||
|
" return one_hot_Y\n",
|
||||||
|
"\n",
|
||||||
|
"def backward_prop(Z1, A1, Z2, A2, W1, W2, X, Y):\n",
|
||||||
|
" one_hot_Y = one_hot(Y)\n",
|
||||||
|
" dZ2 = A2 - one_hot_Y #by how much layer 2 is off\n",
|
||||||
|
" dW2 = 1 / m * dZ2.dot(A1.T) # how much the weight contributed for the error of layer 2\n",
|
||||||
|
" db2 = 1 / m * np.sum(dZ2) # how much the bias contributed for the error of layer 2\n",
|
||||||
|
" dZ1 = W2.T.dot(dZ2) * ReLU_deriv(Z1) #by how much layer 1 is off\n",
|
||||||
|
" dW1 = 1 / m * dZ1.dot(X.T)\n",
|
||||||
|
" db1 = 1 / m * np.sum(dZ1)\n",
|
||||||
|
" return dW1, db1, dW2, db2\n",
|
||||||
|
"\n",
|
||||||
|
"def update_params(W1, b1, W2, b2, dW1, db1, dW2, db2, alpha):\n",
|
||||||
|
" \"\"\"alpha is the learning rate, by how much we want to change the weights and biasis each epoch\"\"\"\n",
|
||||||
|
" W1 = W1 - alpha * dW1\n",
|
||||||
|
" b1 = b1 - alpha * db1 \n",
|
||||||
|
" W2 = W2 - alpha * dW2 \n",
|
||||||
|
" b2 = b2 - alpha * db2 \n",
|
||||||
|
" return W1, b1, W2, b2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": 1,
|
||||||
|
"id": "86bd1d48",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def get_predictions(A2):\n",
|
||||||
|
" return np.argmax(A2, 0)\n",
|
||||||
|
"\n",
|
||||||
|
"def get_accuracy(predictions, Y):\n",
|
||||||
|
" print(predictions, Y)\n",
|
||||||
|
" return np.sum(predictions == Y) / Y.size\n",
|
||||||
|
"\n",
|
||||||
|
"def gradient_descent(X, Y, alpha, iterations):\n",
|
||||||
|
" W1, b1, W2, b2 = init_params()\n",
|
||||||
|
" for i in range(iterations):\n",
|
||||||
|
" Z1, A1, Z2, A2 = forward_prop(W1, b1, W2, b2, X)\n",
|
||||||
|
" dW1, db1, dW2, db2 = backward_prop(Z1, A1, Z2, A2, W1, W2, X, Y)\n",
|
||||||
|
" W1, b1, W2, b2 = update_params(W1, b1, W2, b2, dW1, db1, dW2, db2, alpha)\n",
|
||||||
|
" if i % 10 == 0: # print info for every 10th epoch\n",
|
||||||
|
" print(\"Iteration: \", i)\n",
|
||||||
|
" predictions = get_predictions(A2)\n",
|
||||||
|
" print(get_accuracy(predictions, Y))\n",
|
||||||
|
" return W1, b1, W2, b2"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"id": "f1e3bf4e",
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"def make_predictions(X, W1, b1, W2, b2):\n",
|
||||||
|
" _, _, _, A2 = forward_prop(W1, b1, W2, b2, X)\n",
|
||||||
|
" predictions = get_predictions(A2)\n",
|
||||||
|
" return predictions\n",
|
||||||
|
"\n",
|
||||||
|
"def test_prediction(index, W1, b1, W2, b2):\n",
|
||||||
|
" current_image = X_train[:, index, None]\n",
|
||||||
|
" prediction = make_predictions(X_train[:, index, None], W1, b1, W2, b2)\n",
|
||||||
|
" label = Y_train[index]\n",
|
||||||
|
" print(\"Prediction: \", prediction)\n",
|
||||||
|
" print(\"Label: \", label)\n",
|
||||||
|
" \n",
|
||||||
|
" current_image = current_image.reshape((28, 28)) * 255\n",
|
||||||
|
" plt.gray()\n",
|
||||||
|
" plt.imshow(current_image, interpolation='nearest')\n",
|
||||||
|
" plt.show()"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"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.5"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 5
|
||||||
|
}
|
||||||
Reference in new issue
Block a user