You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

405 lines
44 KiB
Plaintext

6 months ago
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "7d1db536",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "76b100fc",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"carprices.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "806166f8",
"metadata": {},
"outputs": [],
"source": [
"df = df.drop(\"Car Model\", axis=\"columns\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "1dfdbd5a",
"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>Mileage</th>\n",
" <th>Sell Price($)</th>\n",
" <th>Age(yrs)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>69000</td>\n",
" <td>18000</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>35000</td>\n",
" <td>34000</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>57000</td>\n",
" <td>26100</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>22500</td>\n",
" <td>40000</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>46000</td>\n",
" <td>31500</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>59000</td>\n",
" <td>29400</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>52000</td>\n",
" <td>32000</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>72000</td>\n",
" <td>19300</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>91000</td>\n",
" <td>12000</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>67000</td>\n",
" <td>22000</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>83000</td>\n",
" <td>20000</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>79000</td>\n",
" <td>21000</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>59000</td>\n",
" <td>33000</td>\n",
" <td>5</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Mileage Sell Price($) Age(yrs)\n",
"0 69000 18000 6\n",
"1 35000 34000 3\n",
"2 57000 26100 5\n",
"3 22500 40000 2\n",
"4 46000 31500 4\n",
"5 59000 29400 5\n",
"6 52000 32000 5\n",
"7 72000 19300 6\n",
"8 91000 12000 8\n",
"9 67000 22000 6\n",
"10 83000 20000 7\n",
"11 79000 21000 7\n",
"12 59000 33000 5"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "d76d64b6",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "acdf9d06",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.collections.PathCollection at 0x1bb29b183c8>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "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OVMyVRk5LiOqRdAAAEqzaf8fhnP/uZQkND9eCDD+rcuXNKT0/Xc889Z+0PCwvTjh07NHfuXLndbt1www3KzMzUD3/4Q6smISFBeXl5WrhwodasWaP+/fvrxRdfVHp6ulUzdepUnTx5UsuWLZPH49Ho0aOVn5/f7GHk9jQpKU53J8Yy4zEAAJ3AVc2TYxdtNU8OAABoP9d1nhwAAIDOjpADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsiZADAABsqVUhZ/369Ro5cqRcLpdcLpfcbrd27txp7f/GN76hkJCQgNecOXMCjlFVVaWMjAz16NFD0dHRWrRokS5cuBBQU1RUpOTkZDmdTg0dOlS5ubnN2rJu3ToNGjRI4eHhSk1NVWlpaWtOBQAA2FyrQk7//v21cuVKlZWV6Z133tE3v/lN3XfffTp06JBV89hjj6m6utp6rVq1ytrX2NiojIwMNTQ0aM+ePXr55ZeVm5urZcuWWTWVlZXKyMjQXXfdpfLyci1YsECzZ8/Wrl27rJrNmzcrOztbOTk52r9/v0aNGqX09HTV1NRcS18AAAAbCTHGmGs5QFRUlJ555hnNmjVL3/jGNzR69GitXr26xdqdO3fq3nvv1fHjxxUTEyNJev7557V48WKdPHlSDodDixcvVl5enioqKqy/mzZtmmpra5Wfny9JSk1N1bhx47R27VpJkt/vV3x8vObPn68lS5Zccdt9Pp8iIyPl9XrlcrmusgcAAEB7utLf76t+JqexsVGbNm3SmTNn5Ha7re2vvPKK+vbtq6SkJC1dulSfffaZta+kpEQjRoywAo4kpaeny+fzWVeDSkpKlJaWFvBZ6enpKikpkSQ1NDSorKwsoCY0NFRpaWlWzeWcO3dOPp8v4AUAAOypW2v/4ODBg3K73aqvr1fPnj21bds2JSYmSpK+853vaODAgerXr58OHDigxYsX6+jRo/r1r38tSfJ4PAEBR5L13uPxfGGNz+fT2bNn9emnn6qxsbHFmiNHjnxh21esWKHly5e39pQBAEAX1OqQM2zYMJWXl8vr9epXv/qVMjMzVVxcrMTERD3++ONW3YgRIxQXF6cJEyboww8/1JAhQ9q04Vdj6dKlys7Ott77fD7Fx8d3YIsAAMD10uqQ43A4NHToUEnSmDFjtG/fPq1Zs0YvvPBCs9rU1FRJ0gcffKAhQ4YoNja22SioEydOSJJiY2Ot/2zadmmNy+VSRESEwsLCFBYW1mJN0zEux+l0yul0tuJsAQBAV3XN8+T4/X6dO3euxX3l5eWSpLi4OEmS2+3WwYMHA0ZBFRQUyOVyWbe83G63CgsLA45TUFBgPffjcDg0ZsyYgBq/36/CwsKAZ4MAAEBwa9WVnKVLl2ry5MkaMGCA6urqtHHjRhUVFWnXrl368MMPtXHjRt1zzz3q06ePDhw4oIULF2r8+PEaOXKkJGnixIlKTEzUjBkztGrVKnk8Hj399NPKysqyrrDMmTNHa9eu1VNPPaWZM2dq9+7d2rJli/Ly8qx2ZGdnKzMzU2PHjlVKSopWr16tM2fO6NFHH23DrgEAAF2aaYW
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.scatter(df[\"Mileage\"], df[\"Sell Price($)\"])"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "1627f829",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.collections.PathCollection at 0x1bb28350d08>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjkAAAGdCAYAAADwjmIIAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb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IVoPxkcx4zEAAJ1Am+bJMYv2micHAAB0nNs6Tw4AAEBnR8gBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACmRMgBAACm1KqQs2XLFo0aNUo2m002m00Oh0P79+/37b///vtlsVj8XosWLfI7RmVlpdLS0nTHHXcoMjJSK1as0LVr1/xqCgsLlZiYqJCQEA0dOlQ5OTmNetm0aZMGDx6s0NBQJScnq6SkpDVfBQAAmFyrQk5MTIzWrVun0tJSHT16VA888IAefvhhnTx50lfz1FNPqaqqyvdav369b5/H41FaWprq6+t16NAhbdu2TTk5OVq9erWvpqKiQmlpaZo0aZLKysq0bNkyLVy4UAcOHPDV7Nq1S5mZmcrOztaxY8c0evRopaamqrq6+lbOBQAAMBGLYRjGrRwgIiJCL7/8shYsWKD7779fY8aM0YYNG5qs3b9/v6ZPn65z586pf//+kqRXX31VWVlZunDhgqxWq7KyspSbm6vy8nLf5+bMmaPLly8rLy9PkpScnKzx48dr48aNkiSv16vY2FgtXbpUK1eubHHvbrdbdrtdLpdLNputjWcAAAB0pJb+frf5mRyPx6OdO3fqypUrcjgcvu1vvvmm+vbtq4SEBK1atUpfffWVb19xcbFGjhzpCziSlJqaKrfb7bsaVFxcrJSUFL+/lZqaquLiYklSfX29SktL/WqCgoKUkpLiq2lOXV2d3G633wsAAJhTj9Z+4MSJE3I4HKqtrVXv3r21Z88excfHS5Iee+wxDRo0SAMGDNDx48eVlZWlM2fO6He/+50kyel0+gUcSb73TqfzG2vcbre+/vprXbp0SR6Pp8ma06dPf2Pva9eu1Zo1a1r7lQEAQBfU6pAzbNgwlZWVyeVy6T//8z+Vnp6uoqIixcfH6+mnn/bVjRw5UtHR0Zo8ebI+++wzDRkypF0bb4tVq1YpMzPT997tdis2NjaAHQEAgNul1SHHarVq6NChkqSxY8fqyJEjeuWVV/Taa681qk1OTpYkffrppxoyZIiioqIajYI6f/68JCkqKsr3nw3bbqyx2WwKCwtTcHCwgoODm6xpOEZzQkJCFBIS0opvCwAAuqpbnifH6/Wqrq6uyX1lZWWSpOjoaEmSw+HQiRMn/EZB5efny2az+W55ORwOFRQU+B0nPz/f99yP1WrV2LFj/Wq8Xq8KCgr8ng0CAADdW6uu5KxatUrTpk3TwIEDVVNTox07dqiwsFAHDhzQZ599ph07duihhx5Snz59dPz4cS1fvlwTJ07UqFGjJElTpkxRfHy85s6dq/Xr18vpdOqFF15QRkaG7wrLokWLtHHjRj3//POaP3++Dh48qN27dys3N9fXR2ZmptLT0zVu3DglJSVpw4YNunLliubNm9eOpwYAAHRpRivMnz/fGDRokGG
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.scatter(df[\"Age(yrs)\"], df[\"Sell Price($)\"])"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "932ff8d6",
"metadata": {},
"outputs": [],
"source": [
"x = df.drop(\"Sell Price($)\", axis=\"columns\")\n",
"y = df[\"Sell Price($)\"]"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "a3714dd8",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "f7263cf1",
"metadata": {},
"outputs": [],
"source": [
"x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=10)#random_state可以保证每次运行结果都一样否则每次都是随机划分。"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "48944228",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(10, 3)"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(x_train), len(x_test)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "524b6f13",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.linear_model import LinearRegression"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "29f0bfaf",
"metadata": {},
"outputs": [],
"source": [
"lr = LinearRegression()"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "e60d2dd9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LinearRegression()"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.fit(x_train, y_train)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "dcefda82",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([41842.49106079, 22531.68057211, 18423.93325387])"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.predict(x_test)"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "ecefdb9b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.9224816911971742"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.score(x_test, y_test)"
]
}
],
"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.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}