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.
logistic-regressors/logistic-regressor.ipynb

942 lines
462 KiB
Plaintext

2 years ago
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
2 years ago
"id": "03f8827e-7e96-494f-8f87-4eb8a2a03ff9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['data',\n",
" 'target',\n",
" 'frame',\n",
" 'target_names',\n",
" 'DESCR',\n",
" 'feature_names',\n",
" 'filename',\n",
" 'data_module']"
]
},
"execution_count": 2,
2 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn import datasets\n",
"iris = datasets.load_iris()\n",
"list(iris.keys())"
]
},
{
"cell_type": "code",
"execution_count": 3,
2 years ago
"id": "df29211b-b8ae-4d64-a903-de8ba22daa5f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'data': array([[5.1, 3.5, 1.4, 0.2],\n",
" [4.9, 3. , 1.4, 0.2],\n",
" [4.7, 3.2, 1.3, 0.2],\n",
" [4.6, 3.1, 1.5, 0.2],\n",
" [5. , 3.6, 1.4, 0.2],\n",
" [5.4, 3.9, 1.7, 0.4],\n",
" [4.6, 3.4, 1.4, 0.3],\n",
" [5. , 3.4, 1.5, 0.2],\n",
" [4.4, 2.9, 1.4, 0.2],\n",
" [4.9, 3.1, 1.5, 0.1],\n",
" [5.4, 3.7, 1.5, 0.2],\n",
" [4.8, 3.4, 1.6, 0.2],\n",
" [4.8, 3. , 1.4, 0.1],\n",
" [4.3, 3. , 1.1, 0.1],\n",
" [5.8, 4. , 1.2, 0.2],\n",
" [5.7, 4.4, 1.5, 0.4],\n",
" [5.4, 3.9, 1.3, 0.4],\n",
" [5.1, 3.5, 1.4, 0.3],\n",
" [5.7, 3.8, 1.7, 0.3],\n",
" [5.1, 3.8, 1.5, 0.3],\n",
" [5.4, 3.4, 1.7, 0.2],\n",
" [5.1, 3.7, 1.5, 0.4],\n",
" [4.6, 3.6, 1. , 0.2],\n",
" [5.1, 3.3, 1.7, 0.5],\n",
" [4.8, 3.4, 1.9, 0.2],\n",
" [5. , 3. , 1.6, 0.2],\n",
" [5. , 3.4, 1.6, 0.4],\n",
" [5.2, 3.5, 1.5, 0.2],\n",
" [5.2, 3.4, 1.4, 0.2],\n",
" [4.7, 3.2, 1.6, 0.2],\n",
" [4.8, 3.1, 1.6, 0.2],\n",
" [5.4, 3.4, 1.5, 0.4],\n",
" [5.2, 4.1, 1.5, 0.1],\n",
" [5.5, 4.2, 1.4, 0.2],\n",
" [4.9, 3.1, 1.5, 0.2],\n",
" [5. , 3.2, 1.2, 0.2],\n",
" [5.5, 3.5, 1.3, 0.2],\n",
" [4.9, 3.6, 1.4, 0.1],\n",
" [4.4, 3. , 1.3, 0.2],\n",
" [5.1, 3.4, 1.5, 0.2],\n",
" [5. , 3.5, 1.3, 0.3],\n",
" [4.5, 2.3, 1.3, 0.3],\n",
" [4.4, 3.2, 1.3, 0.2],\n",
" [5. , 3.5, 1.6, 0.6],\n",
" [5.1, 3.8, 1.9, 0.4],\n",
" [4.8, 3. , 1.4, 0.3],\n",
" [5.1, 3.8, 1.6, 0.2],\n",
" [4.6, 3.2, 1.4, 0.2],\n",
" [5.3, 3.7, 1.5, 0.2],\n",
" [5. , 3.3, 1.4, 0.2],\n",
" [7. , 3.2, 4.7, 1.4],\n",
" [6.4, 3.2, 4.5, 1.5],\n",
" [6.9, 3.1, 4.9, 1.5],\n",
" [5.5, 2.3, 4. , 1.3],\n",
" [6.5, 2.8, 4.6, 1.5],\n",
" [5.7, 2.8, 4.5, 1.3],\n",
" [6.3, 3.3, 4.7, 1.6],\n",
" [4.9, 2.4, 3.3, 1. ],\n",
" [6.6, 2.9, 4.6, 1.3],\n",
" [5.2, 2.7, 3.9, 1.4],\n",
" [5. , 2. , 3.5, 1. ],\n",
" [5.9, 3. , 4.2, 1.5],\n",
" [6. , 2.2, 4. , 1. ],\n",
" [6.1, 2.9, 4.7, 1.4],\n",
" [5.6, 2.9, 3.6, 1.3],\n",
" [6.7, 3.1, 4.4, 1.4],\n",
" [5.6, 3. , 4.5, 1.5],\n",
" [5.8, 2.7, 4.1, 1. ],\n",
" [6.2, 2.2, 4.5, 1.5],\n",
" [5.6, 2.5, 3.9, 1.1],\n",
" [5.9, 3.2, 4.8, 1.8],\n",
" [6.1, 2.8, 4. , 1.3],\n",
" [6.3, 2.5, 4.9, 1.5],\n",
" [6.1, 2.8, 4.7, 1.2],\n",
" [6.4, 2.9, 4.3, 1.3],\n",
" [6.6, 3. , 4.4, 1.4],\n",
" [6.8, 2.8, 4.8, 1.4],\n",
" [6.7, 3. , 5. , 1.7],\n",
" [6. , 2.9, 4.5, 1.5],\n",
" [5.7, 2.6, 3.5, 1. ],\n",
" [5.5, 2.4, 3.8, 1.1],\n",
" [5.5, 2.4, 3.7, 1. ],\n",
" [5.8, 2.7, 3.9, 1.2],\n",
" [6. , 2.7, 5.1, 1.6],\n",
" [5.4, 3. , 4.5, 1.5],\n",
" [6. , 3.4, 4.5, 1.6],\n",
" [6.7, 3.1, 4.7, 1.5],\n",
" [6.3, 2.3, 4.4, 1.3],\n",
" [5.6, 3. , 4.1, 1.3],\n",
" [5.5, 2.5, 4. , 1.3],\n",
" [5.5, 2.6, 4.4, 1.2],\n",
" [6.1, 3. , 4.6, 1.4],\n",
" [5.8, 2.6, 4. , 1.2],\n",
" [5. , 2.3, 3.3, 1. ],\n",
" [5.6, 2.7, 4.2, 1.3],\n",
" [5.7, 3. , 4.2, 1.2],\n",
" [5.7, 2.9, 4.2, 1.3],\n",
" [6.2, 2.9, 4.3, 1.3],\n",
" [5.1, 2.5, 3. , 1.1],\n",
" [5.7, 2.8, 4.1, 1.3],\n",
" [6.3, 3.3, 6. , 2.5],\n",
" [5.8, 2.7, 5.1, 1.9],\n",
" [7.1, 3. , 5.9, 2.1],\n",
" [6.3, 2.9, 5.6, 1.8],\n",
" [6.5, 3. , 5.8, 2.2],\n",
" [7.6, 3. , 6.6, 2.1],\n",
" [4.9, 2.5, 4.5, 1.7],\n",
" [7.3, 2.9, 6.3, 1.8],\n",
" [6.7, 2.5, 5.8, 1.8],\n",
" [7.2, 3.6, 6.1, 2.5],\n",
" [6.5, 3.2, 5.1, 2. ],\n",
" [6.4, 2.7, 5.3, 1.9],\n",
" [6.8, 3. , 5.5, 2.1],\n",
" [5.7, 2.5, 5. , 2. ],\n",
" [5.8, 2.8, 5.1, 2.4],\n",
" [6.4, 3.2, 5.3, 2.3],\n",
" [6.5, 3. , 5.5, 1.8],\n",
" [7.7, 3.8, 6.7, 2.2],\n",
" [7.7, 2.6, 6.9, 2.3],\n",
" [6. , 2.2, 5. , 1.5],\n",
" [6.9, 3.2, 5.7, 2.3],\n",
" [5.6, 2.8, 4.9, 2. ],\n",
" [7.7, 2.8, 6.7, 2. ],\n",
" [6.3, 2.7, 4.9, 1.8],\n",
" [6.7, 3.3, 5.7, 2.1],\n",
" [7.2, 3.2, 6. , 1.8],\n",
" [6.2, 2.8, 4.8, 1.8],\n",
" [6.1, 3. , 4.9, 1.8],\n",
" [6.4, 2.8, 5.6, 2.1],\n",
" [7.2, 3. , 5.8, 1.6],\n",
" [7.4, 2.8, 6.1, 1.9],\n",
" [7.9, 3.8, 6.4, 2. ],\n",
" [6.4, 2.8, 5.6, 2.2],\n",
" [6.3, 2.8, 5.1, 1.5],\n",
" [6.1, 2.6, 5.6, 1.4],\n",
" [7.7, 3. , 6.1, 2.3],\n",
" [6.3, 3.4, 5.6, 2.4],\n",
" [6.4, 3.1, 5.5, 1.8],\n",
" [6. , 3. , 4.8, 1.8],\n",
" [6.9, 3.1, 5.4, 2.1],\n",
" [6.7, 3.1, 5.6, 2.4],\n",
" [6.9, 3.1, 5.1, 2.3],\n",
" [5.8, 2.7, 5.1, 1.9],\n",
" [6.8, 3.2, 5.9, 2.3],\n",
" [6.7, 3.3, 5.7, 2.5],\n",
" [6.7, 3. , 5.2, 2.3],\n",
" [6.3, 2.5, 5. , 1.9],\n",
" [6.5, 3. , 5.2, 2. ],\n",
" [6.2, 3.4, 5.4, 2.3],\n",
" [5.9, 3. , 5.1, 1.8]]),\n",
" 'target': array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
" 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
" 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]),\n",
" 'frame': None,\n",
" 'target_names': array(['setosa', 'versicolor', 'virginica'], dtype='<U10'),\n",
" 'DESCR': '.. _iris_dataset:\\n\\nIris plants dataset\\n--------------------\\n\\n**Data Set Characteristics:**\\n\\n :Number of Instances: 150 (50 in each of three classes)\\n :Number of Attributes: 4 numeric, predictive attributes and the class\\n :Attribute Information:\\n - sepal length in cm\\n - sepal width in cm\\n - petal length in cm\\n - petal width in cm\\n - class:\\n - Iris-Setosa\\n - Iris-Versicolour\\n - Iris-Virginica\\n \\n :Summary Statistics:\\n\\n ============== ==== ==== ======= ===== ====================\\n Min Max Mean SD Class Correlation\\n ============== ==== ==== ======= ===== ====================\\n sepal length: 4.3 7.9 5.84 0.83 0.7826\\n sepal width: 2.0 4.4 3.05 0.43 -0.4194\\n petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)\\n petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)\\n ============== ==== ==== ======= ===== ====================\\n\\n :Missing Attribute Values: None\\n :Class Distribution: 33.3% for each of 3 classes.\\n :Creator: R.A. Fisher\\n :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\\n :Date: July, 1988\\n\\nThe famous Iris database, first used by Sir R.A. Fisher. The dataset is taken\\nfrom Fisher\\'s paper. Note that it\\'s the same as in R, but not as in the UCI\\nMachine Learning Repository, which has two wrong data points.\\n\\nThis is perhaps the best known database to be found in the\\npattern recognition literature. Fisher\\'s paper is a classic in the field and\\nis referenced frequently to this day. (See Duda & Hart, for example.) The\\ndata set contains 3 classes of 50 instances each, where each class refers to a\\ntype of iris plant. One class is linearly separable from the other 2; the\\nlatter are NOT linearly separable from each other.\\n\\n.. topic:: References\\n\\n - Fisher, R.A. \"The use of multiple measurements in taxonomic problems\"\\n Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\\n Mathematical Statistics\" (John Wiley, NY, 1950).\\n - Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.\\n (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.\\n - Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\\n Structure and Classification Rule for Recognition in Partially Exposed\\n Environments\". IEEE Transactions on Pattern Analysis and Machine\\n Intelligence, Vol. PAMI-2, No. 1, 67-71.\\n - Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\". IEEE Transactions\\n on Information Theory, May 1972, 431-433.\\n - See also: 1988 MLC Proceedings, 54-64. Cheeseman et al\"s AUTOCLASS II\\n conceptual clustering system finds 3 classes in the data.\\n - Many, many more ...',\n",
" 'feature_names': ['sepal length (cm)',\n",
" 'sepal width (cm)',\n",
" 'petal length (cm)',\n",
" 'petal width (cm)'],\n",
" 'filename': 'iris.csv',\n",
" 'data_module': 'sklearn.datasets.data'}"
]
},
"execution_count": 3,
2 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"iris"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "b8d7e32c-5ed5-411e-b411-e4304f47c087",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
".. _iris_dataset:\n",
"\n",
"Iris plants dataset\n",
"--------------------\n",
"\n",
"**Data Set Characteristics:**\n",
"\n",
" :Number of Instances: 150 (50 in each of three classes)\n",
" :Number of Attributes: 4 numeric, predictive attributes and the class\n",
" :Attribute Information:\n",
" - sepal length in cm\n",
" - sepal width in cm\n",
" - petal length in cm\n",
" - petal width in cm\n",
" - class:\n",
" - Iris-Setosa\n",
" - Iris-Versicolour\n",
" - Iris-Virginica\n",
" \n",
" :Summary Statistics:\n",
"\n",
" ============== ==== ==== ======= ===== ====================\n",
" Min Max Mean SD Class Correlation\n",
" ============== ==== ==== ======= ===== ====================\n",
" sepal length: 4.3 7.9 5.84 0.83 0.7826\n",
" sepal width: 2.0 4.4 3.05 0.43 -0.4194\n",
" petal length: 1.0 6.9 3.76 1.76 0.9490 (high!)\n",
" petal width: 0.1 2.5 1.20 0.76 0.9565 (high!)\n",
" ============== ==== ==== ======= ===== ====================\n",
"\n",
" :Missing Attribute Values: None\n",
" :Class Distribution: 33.3% for each of 3 classes.\n",
" :Creator: R.A. Fisher\n",
" :Donor: Michael Marshall (MARSHALL%PLU@io.arc.nasa.gov)\n",
" :Date: July, 1988\n",
"\n",
"The famous Iris database, first used by Sir R.A. Fisher. The dataset is taken\n",
"from Fisher's paper. Note that it's the same as in R, but not as in the UCI\n",
"Machine Learning Repository, which has two wrong data points.\n",
"\n",
"This is perhaps the best known database to be found in the\n",
"pattern recognition literature. Fisher's paper is a classic in the field and\n",
"is referenced frequently to this day. (See Duda & Hart, for example.) The\n",
"data set contains 3 classes of 50 instances each, where each class refers to a\n",
"type of iris plant. One class is linearly separable from the other 2; the\n",
"latter are NOT linearly separable from each other.\n",
"\n",
".. topic:: References\n",
"\n",
" - Fisher, R.A. \"The use of multiple measurements in taxonomic problems\"\n",
" Annual Eugenics, 7, Part II, 179-188 (1936); also in \"Contributions to\n",
" Mathematical Statistics\" (John Wiley, NY, 1950).\n",
" - Duda, R.O., & Hart, P.E. (1973) Pattern Classification and Scene Analysis.\n",
" (Q327.D83) John Wiley & Sons. ISBN 0-471-22361-1. See page 218.\n",
" - Dasarathy, B.V. (1980) \"Nosing Around the Neighborhood: A New System\n",
" Structure and Classification Rule for Recognition in Partially Exposed\n",
" Environments\". IEEE Transactions on Pattern Analysis and Machine\n",
" Intelligence, Vol. PAMI-2, No. 1, 67-71.\n",
" - Gates, G.W. (1972) \"The Reduced Nearest Neighbor Rule\". IEEE Transactions\n",
" on Information Theory, May 1972, 431-433.\n",
" - See also: 1988 MLC Proceedings, 54-64. Cheeseman et al\"s AUTOCLASS II\n",
" conceptual clustering system finds 3 classes in the data.\n",
" - Many, many more ...\n"
]
}
],
"source": [
"print(iris.DESCR)"
]
},
{
"cell_type": "code",
"execution_count": 4,
2 years ago
"id": "1a602ea1-efee-4b93-aa9d-1bff49564e2f",
"metadata": {},
"outputs": [],
2 years ago
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 5,
2 years ago
"id": "29679ab5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff6e024f10>]"
2 years ago
]
},
"execution_count": 5,
2 years ago
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiQAAAGgCAYAAACaOnwjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAtwklEQVR4nO3df3QU133//5e0AokkSMVO+GEktjFSwPyQAVsySCVQjA1GuNCekxAOMSsH/4pxAj0+jk2b1o3dWvg4IU1OcrBkZEQPxrQ4AYqC4WBHplSQavnhFGgOEYkx2hpB/8ASthvsSvP5w1/26zW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A8+JcT+cYbj6/CSQAACAtuKkVAAD4CoEEAAAYRyABAADGEUgAAIBxBBIAAGAcgQQAABhHIIE1bO1qaUsnTAAIMgIJrGBrV0ubOmECQJDxYDQYZ2tXSzrrAsDA8GA0+IqtXS1t64QJAEFGIIFxtna1tK0TJgAEGYEExtna1dK2TpgAEGTcQwJr2NrVks66AJAcuv0CAADjuKkVAAD4CoEEAAAYRyABAADGEUgAAIBxBBIAAGAcgQQAABhHILGQjd1l6ZILwBTeSzIDgcQyNnaXpUsuAFN4L8kcPBjNIjZ2l6VLLgBTeC/xPx6M5lM2dpelSy4AU3gvySwEEovY2F2WLrkATOG9JLMQSCxiY3dZuuQCMIX3kszCPSQWsrG7LF1yAZjCe4l/0e0XAAAYx02tAADAVwgkAADAOAIJAAAwjkACAACMI5AAAADjXAWS9evXq7S0VPn5+crPz9eMGTP06qu
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lp=iris.data[:,0:1]\n",
"wp=iris.data[:,1:2]\n",
"plt.plot(lp,wp,'.k')"
]
},
{
"cell_type": "code",
"execution_count": 6,
2 years ago
"id": "2874984a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff6df321f0>]"
2 years ago
]
},
"execution_count": 6,
2 years ago
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA0e0lEQVR4nO3de3hU9Z3H8c8kgYCWBEohAZKMrEnlTkGQa9ca6WYta7Xt4wVRqFy80QehrSLdVVAejdbVUt0uSBPBLlpXt4LrvYCRykNELtKKtBgegWSAwLNKEvAS2MzZP1jHDGSSc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K6+8Urt27ep45IDL0YAKAMzp0JyRefPm6eWXX1ZVVZVCodBZv7/mmmv06aef6uWXX44tGzt2rL71rW9p+fLlpo/DnBF4TXl5uW666SZFo1GlpaVpxYoVmjlzptNhAUBK2d5n5OTJk1q9erVmzJjRYiEiSZWVlZo0aVLcspKSElVWVra678bGRjU0NMQ9AK+IRCKxQkSSotGobr75Zu6QAEAC7S5G1q5dq7q6Ov34xz9OuE5tba1ycnLiluXk5Ki2trbVfZeWlio7Ozv2yM/Pb2+YQMrRgAoArGl3MVJeXq7LLrtMffv2TWY8kqSFCxeqvr4+9qipqUn6MQC70IAKAKxpVzFy4MABrV+/XrNmzWp1vdzcXB05ciRu2ZEjR5Sbm9vqdpmZmcrKyop7AF5BAyoAsKZdxcjKlSv
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.plot(lp,'.k')"
]
},
{
"cell_type": "code",
"execution_count": 7,
2 years ago
"id": "68274907",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n",
" 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n",
" 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
" 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\n",
" 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2])"
]
},
"execution_count": 7,
2 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"iris.target"
]
},
{
"cell_type": "markdown",
"id": "6120b70a",
"metadata": {},
"source": [
"# Logistic regressor\n",
"## Decision boudaries"
]
},
{
"cell_type": "code",
"execution_count": 8,
2 years ago
"id": "a75ea97f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff6de45b20>]"
2 years ago
]
},
"execution_count": 8,
2 years ago
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGiCAYAAAA1LsZRAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAwSklEQVR4nO3de3xU9Z3/8ffMQBICZLwg4TLhUsk+1KpQgWTx8uPySEl/8sPiaqXqQyBGQBd9QNNWiSLobmtcvCxdQQGJylZdaNkVtwtLayNosbjcFot4g9YQBkwgreRKLsyc3x+nSQi5MJPM5DuX1/PxOI85c3Jm5hMmYd75fr/n+3VYlmUJAADAEKfpAgAAQHwjjAAAAKMIIwAAwCjCCAAAMIowAgAAjCKMAAAAowgjAADAKMIIAAAwijACAACMIowAAACjgg4j77//vqZPn64hQ4bI4XBo8+bNF3zMjh07dN111ykxMVGjRo3Sa6+91oVSAQBALAo6jNTU1Gj06NFatWpVQOd/+eWXmjZtmiZPnqwDBw5o0aJFuu+++/TrX/866GIBAEDscXRnoTyHw6G33npLM2bM6PCcRx55RFu2bNHHH3/cfOz73/++Tp8+rW3btnX1pQEAQIzoFe4X2LVrl7Kyslody87O1qJFizp8TH19verr65vv+/1+/eUvf9Gll14qh8MRrlIBAEAIWZalqqoqDRkyRE5nx50xYQ8jpaWlSk1NbXUsNTVVlZWVOnPmjPr06dPmMQUFBXryySfDXRoAAOgBx44d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6bFon853QW1tfXq1ev9n+0vv76a7355puSpJtvvlkDBw7skfoCxQevAQMGmK4AQCd6YioKwghC4txQsXfvXk2cOLHd8/Lz81VRUSFJevjhhwN+fkJCjOrbVzp1ynQVADrQ0fwhocYAVoTEjTfe2Lz/1FNPtRsenn32Wa1Zs0aSdO+99+qmm27qsfpwYXPnztW9995rugwAESIU84cEijCCkJg+fbrS09MlSb/5zW908803a8uWLdq/f782bdqkqVOn6sc//rEkaeLEiXrxxRdNlot27N69W+PGjTNdBoAI0dlUFKHGdPAImYMHD2ry5Mn685//3OE5ubm5WrlyJe9HBKmrq1Pfvn1bjfu59dZb9R//8R9BP0+XpoP/v//X3v/v/2Y6eCCCeL32LOHnzx9SXBz42JFAP78ZM4KQueaaa3To0CEtX75cW7dubb7CxuPxaPLkyZo3b56uC3Q6PvSYhIQE/fa3v9WUKVP0xRdfqH///kpOTu6ZF/f7pffea9kHEDF6cioKwghCKjU1Vc8995yee+4506V0y+uvv67f/e532rdvnw4ePKiGhoaYXWjP6XTqq6++0vDhw5u72gBA6rmpKBgzArRjyZIlWrt2rY4ePXrBeVMi0eLFi+VwODrdzvWHP/zhgpPVAYhPHo80aVJ4p6MgjADtWLdunYqLi3Xq1Cndf//9IXnOOXPm9Nikaj/84Q/16aefdrqd66OPPiKMADCGbhqgHVlZWaZLaMPn82n9+vVav369Dhw4oPr6en3zm9/UY489pr/7u79rde5ll12myy67LODnPnjwoHLDMXkAAASAlhEgCtTV1Sk7O1u5ubmqqqpSTk6OcnJyVFJSottuu01vvPFGt56/sbFRn376qb766itVVVWFqGoAkczrlbZvD8+8IcEijABR4N5771VRUZH+5V/+Rfv379eKFSv00ksv6Q9/+IMGDBigJUuWdOv5f/rTn+rFF1/UkCFDen4OmORkewPQYwoL7ct2p0yxbwsLzdZDGAEiXFFRkf7t3/5N8+fP10MPPdTqa4MHD9bNN9/cPL6lq+677z599dVXsixLjzzySHdLDlz
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"t=np.linspace(-100, 100, 1000)\n",
"sig=1/(1+np.exp(-t+3))\n",
"plt.plot(t,sig, '.b', label=r\"$\\sigma=\\frac{1}{1+e^{-t}}$\")\n",
"plt.legend(loc='upper left', fontsize=20)\n",
"plt.axis([-5, 5, -0.1, 1])\n",
"plt.plot([0,0], [0,1], 'r--')"
]
},
{
"cell_type": "markdown",
"id": "2be6077b",
"metadata": {},
"source": [
"# Iris-Setosa Classifier based on petal width"
]
},
{
"cell_type": "code",
"execution_count": 9,
2 years ago
"id": "f59aa9ba",
"metadata": {},
"outputs": [],
"source": [
"X=iris.data[:,1:2]\n",
"y=(iris.target==0).astype(int)"
]
},
{
"cell_type": "code",
"execution_count": 10,
2 years ago
"id": "25839b5d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\
],
"text/plain": [
"LogisticRegression(random_state=42)"
]
},
"execution_count": 10,
2 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.linear_model import LogisticRegression\n",
"mylr=LogisticRegression(solver='lbfgs', random_state=42)\n",
"mylr.fit(X,y)"
]
},
{
"cell_type": "code",
"execution_count": 11,
2 years ago
"id": "4539a843",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff6d2c3190>]"
2 years ago
]
},
"execution_count": 11,
2 years ago
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAABAKElEQVR4nO3de3xU1b3///ckkAQEEjhAAiQmiICIAnIRIlVRU6P1WNFyROUHaOOlFC+Ueo5wVMLFilKlVlGxiIJHKyBV66kWixgEkeMFDCJQFAuSKAnwbUkQJIFk/f4YM5AwezJ7bnsur+fjMY/Anr1m7+zZ2fOZtT7rs13GGCMAAACHJDm9AwAAILERjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEe1cHoH/FFfX69vv/1Wbdu2lcvlcnp3AACAH4wxOnjwoLp27aqkJOv+j5gI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dygGEL2aXhZ8jRAz5AJ/EYzEm6Z/3eSZAAgRb5cFX993JOsUOOBEDNMkilDnmQCIW97SyHwNxzRXWAyJi2EaNOatP9Sq1+S776x7TBowhAPEJatOUV8dqfR+IFj0jMBe4TVK0gNxK5hkVMAbekbgPzt5Js0lvQKICd46N4NJRgWCQTAC76z6XX1drSSGb4AYYDUUQzIqnEIwAmve8kx8Xa2YgQNEPV+dm/70fjAdF+FAMAJ7rK5WEsM3QAxornOT3g84oYXTO4AYVFQkFRY2TnotKfE92AzAEU2n6TZ0bjZNRG0YipHc6/F
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"Xnew=np.linspace(2,5,70).reshape(-1,1)\n",
"yPred=mylr.predict_proba(Xnew)\n",
"plt.plot(Xnew,yPred[:,0],'.r', label='No Iris-Set')\n",
"plt.plot(Xnew,yPred[:,1],'.b', label='Iris-Set')\n",
"plt.legend()\n",
"plt.plot(X,y,'*g')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7474195c",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 12,
2 years ago
"id": "0196eda3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff6d24a070>]"
2 years ago
]
},
"execution_count": 12,
2 years ago
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA2zElEQVR4nO3de3RU5b3/8c/MhCRcAzQmASYmaCIoitgQYvCGQBsvpUKrh6NUUOMKUkSR9izBC4hUY2m1LAvIxfxEpApHW6laxUtOUPFwuEO9FYNySYQEaCVBIAnMPL8/ppk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KipCLbdNKikxpqjIMw22jT7+5z//vDEOhzGSZ/r884HbSkqMsds982ofDodnvr+2Vavqz6t9FBXVbae2n91ev4ZaVSerjNvtNsYY43a7TdXJqnrtB48eNKdOnTLGGHPq1Clz8OjBoPuWfFdiTp48aYwx5uTJk6bku7oXqeJEhXG5XMYYY1wul6k4Uf/vcNehXaampsYYY0xNTY3ZdWhXUOs1xpgN+zaYEydOGGOMOXHihNmwb0NQbWf7fAPV3NjzDaSxvo3VheCdOHHCfPHFF97fkbMR6DOgJUyYMMHcdNNNxhhjrrnmGnP//fc3WEaSef31170/V1RUmJUrV5q7777bxMXFmZ///OfGGGPKy8tNcXGx9+HPv/71LxMfH29mzpxpjDGmf//+ZsqUKfX61j6qq6uNMcakpKSYP/zhD40+n0DvRbDf3yGHkaKiIiOpwWPChAnGGM+LfM011zToM2jQIBM
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# Iris-Setosa Classifier based on petal width\n",
"\n",
"X=iris.data[:,0:1]\n",
"y=(iris.target==0).astype(int)\n",
"\n",
"from sklearn.linear_model import LogisticRegression\n",
"mylr=LogisticRegression(solver='lbfgs', random_state=42)\n",
"mylr.fit(X,y)\n",
"\n",
"Xnew=np.linspace(2,8,70).reshape(-1,1)\n",
"yPred=mylr.predict_proba(Xnew)\n",
"#plt.plot(Xnew,yPred[:,0],'.r', label='No Iris-Set')\n",
"plt.plot(Xnew,yPred[:,1],'.b', label='Iris-Set')\n",
"plt.legend()\n",
"plt.plot(X,y,'*g')"
]
},
{
"cell_type": "markdown",
"id": "4d56c901",
"metadata": {},
"source": [
"# Session 2: Softmax regression\n",
"\n",
"## Multiple features binary classifier (Virginica)"
2 years ago
]
},
{
"cell_type": "code",
"execution_count": 4,
2 years ago
"id": "00ba053b",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHR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3/9a2VlZemDDz7Qz372M/sKBgDARnTtle9MSEaG5Gnxk/z4eOn4cSnNpkut//3f/60f/ehH2rFjhyZPnixJuuWWW5SRkaHExETFx8dr1apV/s+/++67mjRpkhobG9WjRw8NGTJE2dnZ2rRpU9Dt0LUXAGAKXXsj8NlngUFEkpqapCM2PhtoxIgRys3N1QsvvCBJOnLkiHbv3q2SkhJ99NFHqqysVO/evf1Tfn6+PB6Pjh075l/H2LFj7SsQAIBOwq9pJA0bJsXFXXlmJNPmZwOVlJRo8eLFWrFihdauXavrrrtOkyZNUkNDgxYuXKgHH3zwijGDBw/2/+9evXrZWyAAAJ2AMyPyXYpZvdoXQCTf66pV9l2iaXbPPfcoLi5O69ev14svvqh58+bJ5XJpzJgx+vTTT5WZmXnF1L17d3uLAhBTgnXtDdXR1+pyO2q2e7xTuxzbyQn7zJmR75WUSPn5vkszmZn2BxFJ6t27twoLC1VWVqb6+noVFxdLkh555BHdfPPNWrRokebPn69evXrp008/VXV1tX7zm9/YXxiAmBCsa2+ojr5Wl9tRs93jndrl2E5O2WduYDVs7969ys3N1Z133qk33njDP7+mpkY//elPtXfvXnm9Xl133XUqLCzUo48+Ksn3094lS5ZoyZIlQdcf7ccHQPu4693KWJ4R0Cwv3hWv40uOS1Kby9KS04KODWe5HTW
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"pl=iris.data[:,2:3]\n",
"pw=iris.data[:,3:]\n",
"tg = iris.target\n",
"plt.plot(pl[tg==0,0],pw[tg==0,0],'.r',label='Set')\n",
"plt.plot(pl[tg==1,0],pw[tg==1,0],'.b',label='Ver')\n",
"plt.plot(pl[tg==2,0],pw[tg==2,0],'.g',label='Vir')\n",
"plt.legend()\n",
"plt.show()"
2 years ago
]
},
{
"cell_type": "code",
"execution_count": 53,
2 years ago
"id": "b3849a04",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-17 {color: black;background-color: white;}#sk-container-id-17 pre{padding: 0;}#sk-container-id-17 div.sk-toggleable {background-color: white;}#sk-container-id-17 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-17 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-17 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-17 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-17 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-17 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-17 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-17 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-17 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-17 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-17 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-17 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-17 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-17 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-17 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-17 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-17 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-17 div.sk-item {position: relative;z-index: 1;}#sk-container-id-17 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-17 div.sk-item::before, #sk-container-id-17 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-17 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-17 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-17 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-17 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-17 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-17 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-17 div.sk-label-container {text-align: center;}#sk-container-id-17 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-17 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container
2 years ago
],
"text/plain": [
"LogisticRegression(C=10, random_state=42, solver='newton-cg', tol=1e-05)"
2 years ago
]
},
"execution_count": 53,
2 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn.linear_model import LogisticRegression\n",
"X=iris.data[:,2:]\n",
"y=(iris.target==2).astype(int)\n",
"\n",
"lrvir=LogisticRegression(random_state=42, tol=1e-5, C=10, max_iter=100, solver='newton-cg')\n",
"lrvir.fit(X,y)"
2 years ago
]
},
{
"cell_type": "code",
"execution_count": 54,
2 years ago
"id": "3fa13847",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"x0, x1=np.meshgrid(\n",
" np.linspace(1,6.9,500).reshape(-1,1),\n",
" np.linspace(0.1,2.5,200).reshape(-1,1))\n",
"Xnew=np.c_[x0.ravel(), x1.ravel()]\n",
"yProb=lrvir.predict_proba(Xnew)"
2 years ago
]
},
{
"cell_type": "code",
"execution_count": 55,
2 years ago
"id": "f34d82b2",
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA04AAAF4CAYAAABjHKkYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3RU1RbA4d+09N4TEgiEEHoJvaOAdAERlQ6Cio9mQZEqvUkREQVFiBRFkCK99xYCoZfQAklIIb0n0+77IwZBksAMYQh4vrWy3mPmnjL3Rph9977nyCRJkhAEQRAEQRAEQRAKJX/RExAEQRAEQRAEQSjpROAkCIIgCIIgCILwBCJwEgRBEARBEARBeAIROAmCIAiCIAiCIDyBCJwEQRAEQRAEQRCeQAROgiAIgiAIgiAITyACJ0EQBEEQBEEQhCcQgZMgCIIgCIIgCMITiMBJEARBEARBEAThCUTgJAiCIAiCIAiC8AQvNHCaMWMGdevWxdbWFjc3N7p06UJYWFiRbYKCgpDJZI/8WFhYmGjGgiAIgiAIgiD8F73QwOnQoUMMGTKEkydPsmfPHjQaDW+88QaZmZlFtrOzsyMmJubBz927d000Y0EQBEEQBEEQ/ouUL3LwnTt3PvLnoKAg3NzcOHPmDM2aNSu0nUwmw8PD43lPTxAEQRAEQRAEAXjBgdO/paamAuDk5FTkcRkZGZQpUwa9Xk9gYCDTp0+nSpUqBR6bm5tLbm7ugz/r9XqSkpJ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eo7V2Nh4JcE2JYhU5vN1CtLWXprI1q9aRYdUsjNqOf6CS08p6OS2xCfc5EtEf2JyjxukvH
2 years ago
"text/plain": [
"<Figure size 1000x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(10,4))\n",
"plt.plot(X[y==0,0], X[y==0,1],'bs',label='No Virg')\n",
"plt.plot(X[y==1,0], X[y==1,1],'g^',label='Virginica')\n",
"zz=yProb[:,1].reshape(x0.shape)\n",
"contour=plt.contour(x0,x1,zz)\n",
"plt.clabel(contour, inline=1,fontsize=15)\n",
"plt.xlabel(\"Petal Length\")\n",
"plt.ylabel(\"Petal Width\")\n",
"plt.legend()\n",
"plt.show()"
2 years ago
]
},
{
"cell_type": "markdown",
"id": "b566781b",
"metadata": {},
"source": [
"## Multiple features and multiclass classifier (Virginica)"
2 years ago
]
},
{
"cell_type": "code",
"execution_count": 81,
2 years ago
"id": "090c8abc",
"metadata": {},
"outputs": [],
"source": [
"X=iris.data[:,2:]\n",
"y=iris.target"
]
},
{
"cell_type": "code",
"execution_count": 82,
2 years ago
"id": "aa59ee97",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<a list of 6 text.Text objects>"
2 years ago
]
},
"execution_count": 82,
2 years ago
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAz8AAAFlCAYAAADF31b7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3iT1RfA8e+bNN17TzpomWXvvTcCIqhsEFAQVMSBIHuKGxAQlL0UEFD23nvPMrpb6N47aZLfH6HF/uhIoYrQ+3mePo+2973vTVranJx7z5G0Wq0WQRAEQRAEQRCEV5zsRS9AEARBEARBEATh3yCCH0EQBEEQBEEQygUR/AiCIAiCIA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4IfQRAAiLyXzsgqpzCzMmBrcvtSX3/68z+58s1hbKs58/a1CaUKfP6fKlNJyF83ubv2IuH7A9BqdL9qjO3NqDasMf6jm2Plbaf3fPcvpbBxZuCT7XByibYDddvhXH1FECQIgiAI5YUIfgRBACAmLIuhXscxMpGxI7Njqa7NzVax0nUKOUmZdN/5Lt7d/ctsXemRSdxZdZ7by8+QHpms+6Qk4dOzBrU+aoVbK1+9iyQ8uJzCuqmBXNzzJAhqP8SVfpMr4uxtWmZrFgRBEAThv+l5YoNSnUReunQpNWvWxNLSEktLS5o0acLevXuLvWbLli1UqVIFY2NjatSowZ49e0q1QEEQ9GdorPsnnZOlobTva4TtCyAnKROLCjZ4dqlWpusyd7eh4ZTODAmZRrc/R+LRoTJotQTvuMH2Nov4rc7X3F13AbUyt8S5/OpZMXN3PX680ISG3RzQqLUcWPmQ4X4ndc1Sw7LKdO2CIAi
2 years ago
"text/plain": [
"<Figure size 1000x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lrmfmc=LogisticRegression(multi_class='multinomial',\n",
2 years ago
" solver='lbfgs',\n",
" C=100,\n",
2 years ago
" random_state=42)\n",
"lrmfmc.fit(X,y)\n",
2 years ago
"x0,x1=np.meshgrid(\n",
" np.linspace(0,8,500).reshape(-1,1),\n",
2 years ago
" np.linspace(0,3.5,200).reshape(-1,1))\n",
"\n",
"Xnew=np.c_[x0.ravel(), x1.ravel()]\n",
"yProba=lrmfmc.predict_proba(Xnew)\n",
"#yPred=lrmfmc.predict(Xnew)\n",
2 years ago
"\n",
"from matplotlib.colors import ListedColormap\n",
"#customc=ListedColormap(['#fafab0', '#9898ff', '#a0faa0'])\n",
"zz=yProba[:,1].reshape(x0.shape)\n",
"#zz=yPred.reshape(x0.shape)\n",
2 years ago
"plt.figure(figsize=(10,4))\n",
"plt.plot(X[y==2,0], X[y==2,1],'g^',label='Virg')\n",
"plt.plot(X[y==1,0], X[y==1,1],'bs',label='Versic')\n",
"plt.plot(X[y==0,0], X[y==0,1],'yo',label='Setos')\n",
"contour=plt.contour(x0,x1,zz,cmap=plt.cm.brg)\n",
2 years ago
"plt.clabel(contour,inline=1,fontsize=12)\n",
"#plt.contourf(x0,x1,zz,cmap=customc)"
2 years ago
]
},
{
"cell_type": "code",
"execution_count": 83,
"id": "ef386db5",
2 years ago
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAigAAAGiCAYAAADNzj2mAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAABGxUlEQVR4nO3df3xT9b0/8Ff6K/1hU0hLf9A2BQcWAVsRRtvIJjq0Fzsnj7uHinMD8ce+u4N7Ue7dnXjd2PBqdTwYuomIc4J3jqGoqCjYdWBxXfktZbQKiNIflLY0lKZtCGmbnO8fNaFpk7QnPck5OXk9H488HuvJ+fE+MOHNOyevj0YQBAFEREREChIhdwFEREREg7FBISIiIsVhg0JERESKwwaFiIiIFIcNChERESkOGxQiIiJSHDYoREREpDhsUIiIiEhx2KAQERGR4rBBISIiIsUR1aBs2LABeXl50Ol00Ol0KCoqwq5du7zuv3nzZmg0GrdXbGzsqIsmIiIidYsSs3NWVhaeeeYZTJ48GYIg4LXXXsOdd96Jo0ePYtq0aR6P0el0OHnypOtnjUYzuoqJiIhI9UQ1KHfccYfbz0899RQ2bNiA/fv3e21QNBoN0tPT/a+QiIiIwo6oBmUgu92Obdu2wWKxoKioyOt+3d3dyMnJgcPhwA033ICnn37aazPjZLPZYLPZXD87HA60t7cjOTmZExgiIqIQIQgCurq6MH78eEREiHzsVRDpn//8p5CQkCBERkYKSUlJwocffuh136qqKuG1114Tjh49KlRUVAjf/e53BZ1OJzQ2Nvq8xqpVqwQAfPHFF1988cWXCl7D/b3viUYQBAEi9PT0oKGhAWazGW+99RZeeeUV7N27F1OnTh322N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MxicikoGoCcrKlSsxf/58GAwGdHV1YcuWLaioqEBZWRkAYNGiRcjMzERpaSkAYPny5bjpppuwdu1alJSUYOvWrTh8+DBefvll6e+ESGLOSYoxpQxZ8TWcpBARBZGoBuX8+fNYtGgRmpubkZSUhLy8PJSVleHWW28FADQ0NCAi4spQxmg0YsuWLXjiiSfw+OOPY/LkyXj33XcxfTr/oCflK9AbABhQaalDQnsdzl4ywThurtxlERGFBVENyh//+Eef71dUVAzZdtddd+Guu+4SVRSRkkRbjTjaZMQ1KZs4SSEiChKuxUM0jAK9wW2RQT6TQkQUeGxQiEbIuchgg/kimxQiogBjg0IkwsBFBnc0cuFLIqJAYYNCJNLARQYZi09EFBhsUIj84HwmhbH4RESBwQaFyE/OKQoXGCQikh4bFCI/DXwehZMUIiJpiV6Lh4iu6F9gsBCV7VvBBQaJiKTDBoVIAs5YfKACABcYJCIaLTYoRBJwxeK31wGoA8AmhYhoNNigEEnIOUmx2MqADDYpRET+YoNCJCEuMEhEJA1+i4coAPonKXPRYL7IryATEfmBDQqFlfE2Lf70ZlXAr1OgN6BEX4haSy6qmr/g2j1ERCKxQaGwsuCGyUG93py4hagyFXOBQSIikfgMClGAlegL8aEJqLXUAajgMylERCPACQpREDgXGOQkhYhoZNigEAXJwGh8NilERL6xQSEKosGTFH7Dh4jIMzYoREHGRQaJiIbHh2SJZFCiL8SB9vE42A5wkUEioqHYoBDJpEBvwIF2fN2k1AFgND4RkRMbFCIZsUkhIvKMDQqRzJxNSnnTBAAVANikEBGxQSFSANcig+114CSFiIgNCpGi9C8yOAGcpBBRuGODQqQgAycpFttJnE0yMRqfiMISc1CIFIiLDBJRuGODQqRQJfpCNilEFLbYoBApGJsUIgpXbFCIFI5NChGFIzYoRCGgRF+IU6YlbFKIKGywQSE
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"yPred=lrmfmc.predict(Xnew)\n",
"zPred=yPred.reshape(x0.shape)\n",
"plt.contourf(x0,x1,zPred,alpha=0.4)\n",
"plt.plot(X[y==2,0], X[y==2,1],'g^',label='Virg')\n",
"plt.plot(X[y==1,0], X[y==1,1],'bs',label='Versic')\n",
"plt.plot(X[y==0,0], X[y==0,1],'yo',label='Setos')\n",
"plt.show()"
2 years ago
]
},
{
"cell_type": "markdown",
"id": "a9531c07",
"metadata": {},
"source": [
"## Homework: Sepal multi-features and multi-class"
2 years ago
]
},
{
"cell_type": "code",
"execution_count": 67,
2 years ago
"id": "d99ec4da",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-19 {color: black;background-color: white;}#sk-container-id-19 pre{padding: 0;}#sk-container-id-19 div.sk-toggleable {background-color: white;}#sk-container-id-19 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-19 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-19 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-19 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-19 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-19 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-19 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-19 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-19 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-19 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-19 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-19 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-19 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-19 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-19 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-19 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-19 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-19 div.sk-item {position: relative;z-index: 1;}#sk-container-id-19 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-19 div.sk-item::before, #sk-container-id-19 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-19 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-19 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-19 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-19 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-19 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-19 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-19 div.sk-label-container {text-align: center;}#sk-container-id-19 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-19 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container
2 years ago
],
"text/plain": [
"LogisticRegression(C=10, multi_class='multinomial', random_state=42)"
]
},
"execution_count": 67,
2 years ago
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X=iris.data[:,0:2]\n",
"y=iris.target\n",
"mlr3=LogisticRegression(\n",
" multi_class='multinomial',\n",
" solver='lbfgs',\n",
" C=10,\n",
" random_state=42)\n",
"mlr3.fit(X,y)"
]
},
{
"cell_type": "code",
"execution_count": 68,
2 years ago
"id": "7c28a9a5",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"x0,x1=np.meshgrid(\n",
" np.linspace(0,9,500).reshape(-1,1),\n",
" np.linspace(0,7,200).reshape(-1,1))"
]
},
{
"cell_type": "code",
"execution_count": 69,
2 years ago
"id": "258b2dd7",
"metadata": {},
"outputs": [],
"source": [
"Xnew=np.c_[x0.ravel(), x1.ravel()]\n",
"yPred=mlr3.predict_proba(Xnew)\n",
"yProba=mlr3.predict(Xnew)\n",
"zz=yProba.reshape(x0.shape)\n",
"zz1=yPred[:,1].reshape(x0.shape)"
]
},
{
"cell_type": "code",
"execution_count": 75,
2 years ago
"id": "2d1cc5a0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0xffff3d5ed7f0>"
2 years ago
]
},
"execution_count": 75,
2 years ago
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAkYAAAG6CAYAAADtZYmTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8o6BhiAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3iT1dvA8e+T3U1bSguUUkbZe8hSAcUBDlB/yhJQcW9xooLgwoVbEX1FVJaAL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xa2k0GkaOG8miHxeVSsBWLVmFbJPp1a8XI4eN5NY7b2Xzgc18t/A7dm7dyStPvVKqn69mfkXHrh3ZuHcjz7/+PN998R1rflvD/y36P7Yf286sn2cR0TzCY8/DFZLiyZSzDsjNzSUgIID09AX4+3vXdDiCIAiXEYfC1m06o47WZ1sTHhmO1qB1qQ9FUbjx+xs5lHwIm2JDLanpHNaZtRPXIkmSmyO2O3X8FP079mfFhhUMGDQAgNsG3UaziGbo9DrUajUzv5lZ0n7HvzsYPng4cXlxGAwGerTsQedunflx2YWkfvIzkzlx9AS/rv3VobgtRgsJsQlEN4vGbCg9FVeUW8RjDR8jJycHf39/Nz1rMWIkCIJQK82ZM7zkQxCKR4tsig0Am2Lz+KhRVLsoevfvzYIfFgBwJvoMO/7ZwdgHxnLk4BEW/biI5v7NSz5GDh2JLMvEx8SX9NG1V9dSfY6aMIrDBw7Tt31fJj8zmU1rPRe/q8SuNEEQhFpITJ0JxRRFYcamGagldUliBKCW1MzYNIPBLQd7bNRo7P1jefWZV3n/y/dZOHchka0i6T+wPwX
2 years ago
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from matplotlib.colors import ListedColormap\n",
"plt.plot(X[y==2,0], X[y==2,1],'y*', label='Virg')\n",
"plt.plot(X[y==1,0], X[y==1,1],'g^', label='Vers')\n",
"plt.plot(X[y==0,0], X[y==0,1],'bs', label='Set')\n",
"contour=plt.contour(x0,x1,zz1, cmap=plt.cm.brg)\n",
"ccmap=ListedColormap(['#fafab0', '#9898ff', '#a0faa0'])\n",
"plt.contourf(x0,x1,zz,cmap=ccmap)\n",
"plt.clabel(contour, inline=1,fontsize=12)\n",
"plt.xlabel('Sepal Width', fontsize=12)\n",
"plt.ylabel('Sepal Length', fontsize=12)\n",
"plt.axis([4,8.5,1,5])\n",
2 years ago
"plt.legend()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "37b5eb33",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "840fcc9a",
"metadata": {},
"outputs": [],
2 years ago
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}