{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 机器学习100天——第3天:多元线性回归(Multiple Linear Regression)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 第1步:数据预处理" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**导入库**" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**导入数据集**" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "X:\n[[165349.2 136897.8 471784.1 'New York']\n [162597.7 151377.59 443898.53 'California']\n [153441.51 101145.55 407934.54 'Florida']\n [144372.41 118671.85 383199.62 'New York']\n [142107.34 91391.77 366168.42 'Florida']\n [131876.9 99814.71 362861.36 'New York']\n [134615.46 147198.87 127716.82 'California']\n [130298.13 145530.06 323876.68 'Florida']\n [120542.52 148718.95 311613.29 'New York']\n [123334.88 108679.17 304981.62 'California']]\nY:\n[192261.83 191792.06 191050.39 182901.99 166187.94 156991.12 156122.51\n 155752.6 152211.77 149759.96 146121.95 144259.4 141585.52 134307.35\n 132602.65 129917.04 126992.93 125370.37 124266.9 122776.86 118474.03\n 111313.02 110352.25 108733.99 108552.04 107404.34 105733.54 105008.31\n 103282.38 101004.64 99937.59 97483.56 97427.84 96778.92 96712.8\n 96479.51 90708.19 89949.14 81229.06 81005.76 78239.91 77798.83\n 71498.49 69758.98 65200.33 64926.08 49490.75 42559.73 35673.41\n 14681.4 ]\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ " R&D Spend Administration Marketing Spend State Profit\n", "0 165349.20 136897.80 471784.10 New York 192261.83\n", "1 162597.70 151377.59 443898.53 California 191792.06\n", "2 153441.51 101145.55 407934.54 Florida 191050.39\n", "3 144372.41 118671.85 383199.62 New York 182901.99\n", "4 142107.34 91391.77 366168.42 Florida 166187.94" ], "text/html": "
| \n | R&D Spend | \nAdministration | \nMarketing Spend | \nState | \nProfit | \n
|---|---|---|---|---|---|
| 0 | \n165349.20 | \n136897.80 | \n471784.10 | \nNew York | \n192261.83 | \n
| 1 | \n162597.70 | \n151377.59 | \n443898.53 | \nCalifornia | \n191792.06 | \n
| 2 | \n153441.51 | \n101145.55 | \n407934.54 | \nFlorida | \n191050.39 | \n
| 3 | \n144372.41 | \n118671.85 | \n383199.62 | \nNew York | \n182901.99 | \n
| 4 | \n142107.34 | \n91391.77 | \n366168.42 | \nFlorida | \n166187.94 | \n