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.

401 lines
18 KiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"id": "799f31eb",
"metadata": {},
"source": [
"线性回归预测的是连续数值,逻辑回归预测的是离散数值。"
]
},
{
"cell_type": "markdown",
"id": "fc3c8eef",
"metadata": {},
"source": [
"线性回归: \n",
"1.预测天气 \n",
"2.预测股票 \n",
"3.预测房价 \n",
"逻辑回归: \n",
"1.邮件是否是垃圾邮件 \n",
"2.猫狗分类 \n",
"3.是否贷款"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "0b62f4a6",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "efe20171",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(\"insurance_data.csv\")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "a0336e69",
"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>age</th>\n",
" <th>bought_insurance</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>22</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>25</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>47</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>52</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>46</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" age bought_insurance\n",
"0 22 0\n",
"1 25 0\n",
"2 47 1\n",
"3 52 0\n",
"4 46 1"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "50fb949d",
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e77e37f4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.collections.PathCollection at 0x2716f2d0608>"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/NK7nSAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAeKElEQVR4nO3df3TV9X348VcC5AbBBCySAEahqy065EdBs5R6ejozc5yH1f06OdYVDv2xo6MOzXYmaRXadTWsHY71wMyk7dqdzUH1TNdWi2OxsOOalRHGqW4WpdLBURPgbOZi1MQln+8ffr2aAjYXE98JPB7n3GP43Pfn3vfH903u83zuzU1JlmVZAAAkUpp6AgDA2U2MAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUuNTT2AoBgYG4rnnnotzzz03SkpKUk8HABiCLMvi+PHjMXPmzCgtPfX5jzERI88991zU1NSkngYAcBoOHz4cF1xwwSmvHxMxcu6550bEawdTUVGReDYAwFDk8/moqakpPI+fypiIkddfmqmoqBAjADDG/Ly3WHgDKwCQlBgBAJISIwBAUmIEAEhKjAAASYkRACApMQIAJCVGAICkxAgAkFTRMfIv//IvsWzZspg5c2aUlJTEgw8++HP32blzZ7z//e+PXC4X73nPe+Ib3/jGaU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ACQlRgCApMQIAJCUGAEAkhIjAEBSYgQASEqMAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACApMQIAJCVGAICkxAgAkJQYAQCSEiMAQFJiBABISowAAEmJEQAgKTECACQlRgCApMQIAJCUGAEAkhIjAEBSYgQASEqMAABJiREAICkxAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACApMQIAJCVGAICkxAgAkJQYAQCSEiMAQFJiBABISowAAEmJEQAgqdOKkc2bN8fs2bOjvLw8amtrY/fu3W85/oUXXohVq1bFjBkzIpfLxXvf+954+OGHT2vCAMCZZXyxO2zbti2ampqitbU1amtrY+PGjdHQ0BD79++P6dOnnzC+r68vfuVXfiWmT58e999/f8yaNSv++7//O6ZMmTIc8wcAxriSLMuyYnaora2Nyy+/PDZt2hQREQMDA1FTUxM333xzrFmz5oTxra2t8eUvfzl+/OMfx4QJE05rkvl8PiorK6O7uzsqKipO6zYAgHfWUJ+/i3qZpq+vLzo6OqK+vv6NGygtjfr6+mhvbz/pPt/+9rejrq4uVq1aFVVVVTFv3ry48847o7+//5T309vbG/l8ftAFADgzFRUjx44di/7+/qiqqhq0vaqqKjo7O0+6zzPPPBP3339/9Pf3x8MPPxx33HFHbNiwIf7kT/7klPfT0tISlZWVhUtNTU0x0wQAxpAR/22agYGBmD59etxzzz2xePHiaGxsjM9+9rPR2tp6yn2am5uju7u7cDl8+PBITxMASKSoN7BOmzYtxo0bF11dXYO2d3V1RXV19Un3mTFjRkyYMCHGjRtX2HbJJZdEZ2dn9PX1RVlZ2Qn75HK5yOVyxUwNABijijozUlZWFosXL462trbCtoGBgWhra4u6urqT7rN06dI4cOBADAwMFLY99dRTMWPGjJOGCABwdin6ZZqmpqbYsmVLfPOb34wnn3wybrrppujp6YmVK1dGRMTy5cujubm5MP6mm26K//mf/4nVq1fHU089FQ899FDceeedsWrVquE7CgBgzCr6c0YaGxvj6NGjsXbt2ujs7IyFCxfG9u3bC29qPXToUJ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aJKVOmxHvf+944cOCA75mEZsyYEZdeeumgbZdccknhJbTX////7G82jdW1ESOnIcuy+PSnPx0PPPBAPProozFnzpxB1y9evDgmTJgQbW1thW379++PQ4cORV1d3Ts93bPewMBA9Pb2WpeErrrqqnj88cdj3759hcuSJUvihhtuKHxtbUaHF198MX7yk5/EjBkzfM8ktHTp0hM+MuKpp56Kiy66KCIi5syZE9XV1YPWJp/Pxw9/+MOxuTap30E7Ft10001ZZWVltnPnzuz5558vXF566aXCmBtvvDG78MILs0cffTTbs2dPVldXl9XV1SWc9dlhzZo12a5du7KDBw9mP/rRj7I1a9ZkJSUl2T/90z9lWWZdRpM3/zZNllmbVP7gD/4g27lzZ3bw4MHsX//1X7P6+vps2rRp2ZEjR7Issy6p7N69Oxs/fnz2xS9+MXv66aezv/u7v8vOOeec7G//9m8LY9avX59NmTIl+8d//MfsRz/6UfaRj3wkmzNnTvbyyy8nnPnpESOnISJOevnrv/7rwpiXX345+73f+71s6tSp2TnnnJP9+q//evb888+nm/RZ4uMf/3h20UUXZWVlZdn555+fXXXVVYUQyTLrMpr8bIxYmzQaGxuzGTNmZGVlZdmsWbOyxsbG7MCBA4XrrUs63/nOd7J58+ZluVwumzt3bnbPPfcMun5gYCC74447sqqqqiyXy2VXXXVVtn///kSzfXtKsizLUp6ZAQDObt4zAgAkJUYAgKTECACQlBgBAJISIwBAUmIEAEhKjAAASYkRACApMQIAJCVGAICkxAgAkJQYAQCS+n+c6suj7RLqHQAAAABJRU5ErkJggg==\n",
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.scatter(df.age, df.bought_insurance, marker=\"+\", color='r')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "bf219340",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(27, 2)"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "3a6ed8a7",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.model_selection import train_test_split"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "c85065da",
"metadata": {},
"outputs": [],
"source": [
"x_train, x_test, y_train, y_test = train_test_split(df[['age']], df.bought_insurance, train_size=0.9, random_state=10)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "16437565",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(24, 3)"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(x_train), len(x_test)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "4d83ec8c",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.linear_model import LogisticRegression"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "61312ccd",
"metadata": {},
"outputs": [],
"source": [
"lr = LogisticRegression()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "dac8d670",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"LogisticRegression()"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.fit(x_train, y_train)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "698480b6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([1, 1, 0], dtype=int64),\n",
" 7 1\n",
" 5 1\n",
" 18 0\n",
" Name: bought_insurance, dtype: int64)"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.predict(x_test), y_test"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "89c91628",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.score(x_test, y_test)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "452bb440",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.06470723, 0.93529277],\n",
" [0.10327405, 0.89672595],\n",
" [0.92775095, 0.07224905]])"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.predict_proba(x_test)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "1246d4de",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"D:\\envs\\stark-lin\\lib\\site-packages\\sklearn\\base.py:451: UserWarning: X does not have valid feature names, but LogisticRegression was fitted with feature names\n",
" \"X does not have valid feature names, but\"\n",
"D:\\envs\\stark-lin\\lib\\site-packages\\sklearn\\base.py:451: UserWarning: X does not have valid feature names, but LogisticRegression was fitted with feature names\n",
" \"X does not have valid feature names, but\"\n"
]
},
{
"data": {
"text/plain": [
"(array([1], dtype=int64), array([0], dtype=int64))"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lr.predict([[53]]), lr.predict([[20]])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bc340fea",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}