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

1144 lines
601 KiB
Plaintext

2 years ago
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"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": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sklearn import datasets\n",
"iris = datasets.load_iris()\n",
"list(iris.keys())"
]
},
{
"cell_type": "code",
"execution_count": 2,
"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": 2,
"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",
2 years ago
"execution_count": 3,
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": 12,
"id": "29679ab5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff81b97610>]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiQAAAGgCAYAAACaOnwjAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAtwklEQVR4nO3df3QU133//5e0AokkSMVO+GEktjFSwPyQAVsySCVQjA1GuNCekxAOMSsH/4pxAj0+jk2b1o3dWvg4IU1OcrBkZEQPxrQ4AYqC4WBHplSQavnhFGgOEYkx2hpB/8ASthvsSvP5w1/26zWS0Kx2596ZfT7O2T80zHDfd0az+2J2mHeW4ziOAAA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ABAADGEUgAAIBxBBIAAGAcgQQAABhHIIE1bO1qaUsnTAAIMgIJrGBrV0ubOmECQJDxYDQYZ2tXSzrrAsDA8GA0+IqtXS1t64QJAEFGIIFxtna1tK0TJgAEGYEExtna1dK2TpgAEGTcQwJr2NrVks66AJAcuv0CAADjuKkVAAD4CoEEAAAYRyABAADGEUgAAIBxBBIAAGAcgQQAABhHILGQjd1l6ZILwBTeSzIDgcQyNnaXpUsuAFN4L8kcPBjNIjZ2l6VLLgBTeC/xPx6M5lM2dpelSy4AU3gvySwEEovY2F2WLrkATOG9JLMQSCxiY3dZuuQCMIX3kszCPSQWsrG7LF1yAZjCe4l/0e0XAAAYx02tAADAVwgkAADAOAIJAAAwjkACAACMI5AAAADjXAWS9evXq7S0VPn5+crPz9eMGTP06qu
"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": 13,
"id": "2874984a",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff81298d00>]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA0e0lEQVR4nO3de3hU9Z3H8c8kgYCWBEohAZKMrEnlTkGQa9ca6WYta7Xt4wVRqFy80QehrSLdVVAejdbVUt0uSBPBLlpXt4LrvYCRykNELtKKtBgegWSAwLNKEvAS2MzZP1jHDGSSc5I5c27v1/PM85CTc/l+f+dM5suZ33wnZBiGIQAAAIekOR0AAAAINooRAADgKIoRAADgKIoRAAD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2rL71rW9p+fLlpo/DnBF4TXl5uW666SZFo1GlpaVpxYoVmjlzptNhAUBK2d5n5OTJk1q9erVmzJjRYiEiSZWVlZo0aVLcspKSElVWVra678bGRjU0NMQ9AK+IRCKxQkSSotGobr75Zu6QAEAC7S5G1q5dq7q6Ov34xz9OuE5tba1ycnLiluXk5Ki2trbVfZeWlio7Ozv2yM/Pb2+YQMrRgAoArGl3MVJeXq7LLrtMffv2TWY8kqSFCxeqvr4+9qipqUn6MQC70IAKAKxpVzFy4MABrV+/XrNmzWp1vdzcXB05ciRu2ZEjR5Sbm9vqdpmZmcrKyop7AF5BAyoAsKZdxcjKlSv
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.plot(lp,'.k')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"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": 17,
"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": 29,
"id": "a75ea97f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff65ac3e80>]"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGiCAYAAAA1LsZRAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAwSklEQVR4nO3de3xU9Z3/8ffMQBICZLwg4TLhUsk+1KpQgWTx8uPySEl/8sPiaqXqQyBGQBd9QNNWiSLobmtcvCxdQQGJylZdaNkVtwtLayNosbjcFot4g9YQBkwgreRKLsyc3x+nSQi5MJPM5DuX1/PxOI85c3Jm5hMmYd75fr/n+3VYlmUJAADAEKfpAgAAQHwjjAAAAKMIIwAAwCjCCAAAMIowAgAAjCKMAAAAowgjAADAKMIIAAAwijACAACMIowAAACjgg4j77//vqZPn64hQ4bI4XBo8+bNF3zMjh07dN111ykxMVGjRo3Sa6+91oVSAQBALAo6jNTU1Gj06NFatWpVQOd/+eWXmjZtmiZPnqwDBw5o0aJFuu+++/TrX/866GIBAEDscXRnoTyHw6G33npLM2bM6PCcRx55RFu2bNHHH3/cfOz73/++Tp8+rW3btnX1pQEAQIzoFe4X2LVrl7Kyslody87O1qJFizp8TH19verr65vv+/1+/eUvf9Gll14qh8MRrlIBAEAIWZalqqoqDRkyRE5nx50xYQ8jpaWlSk1NbXUsNTVVlZWVOnPmjPr06dPmMQUFBXryySfDXRoAAOgBx44dk8fj6fDrYQ8jXZGfn6+8vLzm+xUVFRo2bJiOHTumlJQUg5UBCKmaGmnIEHv/xAmpb1+z9QAIqcrKSqWlpal///6dnhf2MDJo0CCVlZW1O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AAAYRRgBAABGEUYAAIBRXE0DwByHQxo+vGUfQFyiZQRhUVdXp8LCQt1yyy1KS0tTcnKyHA5Hp9uePXtMl42elpwsFRfbG3OMAHGLlhGE3EcffaTbb79dR44cCfgxTqdTV199dRirilzr1q3Tzp07JUkHDx5sPrZjxw5J0o033qj77rvPVHkAEHaEEYTUH//4R2VlZam8vFySdMstt2jWrFkaOXKkTp48qcLCQm3atKn5/KlTp6p3795KTU1Vnz59TJVt1M6dO7V+/fpWxz744AN98MEHzfcJIwAindcrHT4spadLHk9wj3VYVuRPe1hZWSm3262KigqlpKQE/Li6ujp9+eWXGjlypJKSksJYYfC686ZFKsuydP311+vDDz+UJK1Zs0bz5s1rc96dd96pDRs2SJI2b96s7373uxd8bkcIxhO8+uqrmjNnTrefB+3r0u/bmTPS//k/9v7770txGkiBaFdYKM2bJ/n9ktMprV0r5eYG/vnNmBEDCgvtMXtTpti3hYWmKwqNjRs3NgeRH/7wh+0GEUlatGhR835TVwTilN8v7d1rb36/6WoAdIHX2xJEJPt2/nz7eKDopulhHb1p2dnR30KyatUqSdKll16qJ554osPzvvWtbzXvewP8aW0aS9Ednmj/BwaACHT4cNu/JXw+6cgR6brrAnsOwkgP6+xNi+bPytLS0uZBmHfddZf69evX4bkJCQlyOByyLEtOZ2CNc/E6uBUAIl16ut01c+5nm8sljRoV+HPQTdPDmt60cwX7pkWi999/v3l/6tSpnZ5bVlampqFKaWlpYa0LABBeHo89RsTlsu+7XNKaNcH9gU3LSA9retPmz7dbRLrypkWijz/+uHl/9OjRnZ67d+/e5v3x48cH/fxd5fF4dNFFF3X7eQAAreXm2sMNjhyx/7gO9jONMGJAd9+0SFRSUtK8P3jw4E7P3bJliyR7bpHJkycH9PzXXHNN14v7q0CupgnFVTuxJgouuAMQATyern+eEUYM6c6bFon853QW1tfXq1ev9n+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
"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": 34,
"id": "f59aa9ba",
"metadata": {},
"outputs": [],
"source": [
"X=iris.data[:,1:2]\n",
"y=(iris.target==0).astype(int)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"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": 37,
"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": 41,
"id": "4539a843",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff538572e0>]"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAABAKElEQVR4nO3de3xU1b3///ckkAQEEjhAAiQmiICIAnIRIlVRU6P1WNFyROUHaOOlFC+Ueo5wVMLFilKlVlGxiIJHKyBV66kWixgEkeMFDCJQFAuSKAnwbUkQJIFk/f4YM5AwezJ7bnsur+fjMY/Anr1m7+zZ2fOZtT7rs13GGCMAAACHJDm9AwAAILERjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEcRjAAAAEe1cHoH/FFfX69vv/1Wbdu2lcvlcnp3AACAH4wxOnjwoLp27aqkJOv+j5gIRr799lvl5OQ4vRsAACAAZWVlys7Otnw+JoKRtm3bSnL/Mu3atXN4bwAAgD+qq6uVk5Pj+Ry3EhPBSMPQTLt27QhGAACIMc2lWJDACgAAHEUwAgAAHEUwAgAAHEUwAgAAHEUwAgAAHEUwAgAAHEUwAgAA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lvQKICd46N4NJRgWCQTAC76z6XX1drSSGb4AYYDUUQzIqnEIwAmve8kx8Xa2YgQNEPV+dm/70fjAdF+FAMAJ7rK5WEsM3QAxornOT3g84oYXTO4AYVFQkFRY2TnotKfE92AzAEU2n6TZ0bjZNRG0YipHc6/F
"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": 45,
"id": "0196eda3",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff536c56d0>]"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAA2zElEQVR4nO3de3RU5b3/8c/MhCRcAzQmASYmaCIoitgQYvCGQBsvpUKrh6NUUOMKUkSR9izBC4hUY2m1LAvIxfxEpApHW6laxUtOUPFwuEO9FYNySYQEaCVBIAnMPL8/ppkQMjOZCUn2TPJ+rTVrk/3sZ+/vzCQzH/bl2TZjjBEAAIBF7FYXAAAA2jfCCAAAsBRhBAAAWIowAgAALEUYAQAAliKMAAAASxFGAACApQgjAADAUlFWFxAMt9ut/fv3q2vXrrLZbFaXAwAAgmCM0dGjR9W7d2/Z7f73f0REGNm/f7+Sk5OtLg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NehXaampsYYY0xNTY3ZdWhXUOs1xpgN+zaYEydOGGOMOXHihNmwb0NQbWf7fAPV3NjzDaSxvo3VheCdOHHCfPHFF97fkbMR6DOgJUyYMMHcdNNNxhhjrrnmGnP//fc3WEaSef31170/V1RUmJUrV5q7777bxMXFmZ///OfGGGPKy8tNcXGx9+HPv/71LxMfH29mzpxpjDGmf//+ZsqUKfX61j6qq6uNMcakpKSYP/zhD40+n0DvRbDf3yGHkaKiIiOpwWPChAnGGM+LfM011zToM2jQIBM
"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",
"## multiple features class"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "00ba053b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[<matplotlib.lines.Line2D at 0xffff67a417f0>]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAAjDUlEQVR4nO3df2zU9eHH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45GJx+xETHoGAGmkoKB7Ai47ZmCN57PdNhtpJh6zE9HaCwAAbEFrLwAASAuEEQAAYBTPjACAATU10pEjkZc1N0tDhkjTp0deHqt1VzLXQltfH7nz5qIhQ6TCwsTGlcwx2Xk+aPxNDcIIAFxmNTXSnXcm9xmRWnclcy209fVSSUlynxFtXMkck53ng8bf1OE2DQBcZtGuiFgR7QqEqRbaWFdE4hVtXMkck53ng8bf1CGMAAAAowgjAADAKMIIAAAwijACAACMIowAAACjCCMAAMAowggAXGYTJiT/GZFadyVzLbTRxmNFtHElc0x2ng8af1OHojwAMIAZWK2NixlY01O8f78JIwAAwBa09gIAgLRAGAEAAEZRlAcAUTj1eQCnjgtIFGEEACJwaiOrU8cFJIPbNAAQgVMbWZ06LiAZhBEAAGAUYQQAABhFGAEAAEYRRgAAgFGEEQAAYBRhBAAAGEUYAYAInNrI6tRxAclg0jMAiKCgoHviMKfNdOrUcQHJIIwAQBQFBc78o+7UcQGJ4jYNAAAwijACAACM4jYNAESRTDuuyWZdN7b6uvGY8BXCCABEkEw7rslmXTe
"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",
"plt.plot(pl,pw,'sb')"
]
},
{
"cell_type": "code",
"execution_count": 39,
"id": "b3849a04",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-4 {color: black;background-color: white;}#sk-container-id-4 pre{padding: 0;}#sk-container-id-4 div.sk-toggleable {background-color: white;}#sk-container-id-4 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-4 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-4 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-4 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-4 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-4 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-4 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-4 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-4 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 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-4 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-4 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-4 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-4 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-4 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-4 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-4 div.sk-item {position: relative;z-index: 1;}#sk-container-id-4 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-4 div.sk-item::before, #sk-container-id-4 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-4 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-4 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-4 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-4 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-4 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-4 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-4 div.sk-label-container {text-align: center;}#sk-container-id-4 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-4 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-4\" class=\"sk-top-container\
],
"text/plain": [
"LogisticRegression(C=10, random_state=42)"
]
},
"execution_count": 39,
"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",
"lrmi=LogisticRegression(solver='lbfgs',\n",
" C=10,\n",
" random_state=42)\n",
"lrmi.fit(X,y)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"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=lrmi.predict_proba(Xnew)"
]
},
{
"cell_type": "code",
"execution_count": 41,
"id": "f34d82b2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0xffff3def9c10>"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA04AAAF4CAYAAABjHKkYAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3RU1RbA4d+09N4TEgiEEEIn9A4K0gVEVDoIKj6aBUWq9CZFRBQUIVIUQYr03lsIhN5LIAkppPdk2n1/xCBIEpghDAHPt1bWe8zcU+beCLPv3vccmSRJEoIgCIIgCIIgCEKh5C96AoIgCIIgCIIgCCWdCJwEQRAEQRAEQRCeQAROgiAIgiAIgiAITyACJ0EQBEEQBEEQhCcQgZMgCIIgCIIgCMITiMBJEARBEARBEAThCUTgJAiCIAiCIAiC8AQicBIEQRAEQRAEQXgCETgJgiAIgiAIgiA8gQicBEEQBEEQBEEQnuCFBk7Tp0+nTp062Nra4ubmRufOnbl27VqRbYKDg5HJZI/8WFhYmGjGgiAIgiAIgiD8F73QwOngwYMMHjyYEydOsHv3bjQaDW+88QaZmZlFtrOzsyMmJubBz927d000Y0EQBEEQBEEQ/ouUL3LwHTt2PPLn4OBg3NzcOH36NE2bNi20nUwmw8PD43lPTxAEQRAEQRAEAXjBgdO/paamAuDk5FTkcRkZGZQpUwa9Xk9QUBDTpk2jcuXKBR6bm5tLbm7ugz/r9XqSkpJwdnZGJpMV3+QFQRAEQRAEQXipSJJEeno6Xl5eyOVFF+PJJEmSTDSvIun1et58801SUlI4cuRIoccdP36cGzduUK1aNVJTU5k9ezaHDh3i0qVLeHt7P3b8hAkTmDhx4vOcuiAIgiAIgiAIL7HIyMgCY4mHlZjA6eOPP2b79u0cOXLkiZN+mEajITAwkO7duzN58uTH3v93xik1NZXSpUsTGRmJnZ1dscxdEAShJJEkiV2bwljy3R60Gh0ubnaMm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RG6f/m16SWHjhGPPOHUEvSVRwcOGHpp0p72B8puh+ThIzrwZzNe0OAJ1KNaN/2U6o5KbL/ERkHORI3FQ0+gzM5LY0dh+Pj00jk40vCILwshGBUxGKOjk5OTmEh4dTpkwZrKyKd8Up4fnJzs7mzp07lC1bFgsLixc9HUF4qWSkZzN30l8c3Ze3lHiT1yvx6bhOWNsW739LkiSxYd955q06gFqjw8PZlilD2lO1vHGleyduRzBi3XYSMrOwUqmY2PF1OlYLNLif47F3GXZ4E/HZmVgqVUyt15q3/KoYNScArV7Hr3c2sz5qHwAVbEvzVWB/3C0MeybrWaRrojkYM5bE3LxnzCo79CDIZZAo3TOhPbf3MGz7ML5r+x0ty7V80dN5YWYdncW4/eOY3GIyXzb68kVPRxAKJAKnIjxN4CS+gL9cxHUThGcjSRJ/rQ7h52/zSvc8vZ0YM6Mb/oHGBTVFuXbnPqO/30JUXF7p3tB3m/BemyCjslzx6ZmMWLedkDt5pXvdgqowpm0LLFSGBQj3szP49PBmjsbeBeDd8tWYWLcVFs9QuheSeIG511aRoc3CWmnJpxV60sDF+GepDKXTqzmd+ANXUtYA4GpRlWYek7BWuZtsDv9V+ctRh0aHUserzn922Wm9Xo/tDFuyNFlYqaxI/yodufyFLuYsCAV6aZYjFwRBEF48mUxG5+71mfPL+7h7OhATlcSn/Zewee1JivveWoCvG79O7slrdfzR6fR8+9tBRs7fRFpmjsF9udpas7TPW/yvaT1kwNqwi7y75HduJyQZ1I+bpQ3LW77LJ9UbIwP+uHmeztuWczM10eA55avnXJUFQV8SYFuGTG02Uy4vYcmtDWj1pll0SCE3o67rJzT3nIZKbkN8zgU2R/QjKvOYScb
"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()"
]
},
{
"cell_type": "markdown",
"id": "b566781b",
"metadata": {},
"source": [
"# Multiclass"
]
},
{
"cell_type": "code",
"execution_count": 51,
"id": "090c8abc",
"metadata": {},
"outputs": [],
"source": [
"X=iris.data[:,2:]\n",
"y=iris.target"
]
},
{
"cell_type": "code",
"execution_count": 52,
"id": "aa59ee97",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.contour.QuadContourSet at 0xffff3d208c40>"
]
},
"execution_count": 52,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAz8AAAFlCAYAAADF31b7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOzdd3gU1frA8e/MzpZskk0lnRogkNARKaKgAiKoYO+A2K+9i71cxd6uvys27NiwS5cq0jsJNSHUNNKzyfaZ3x+bBLiSkEk2FHM+z5MHiTPnnJ0sm3nnnPO+kqZpGoIgCIIgCIIgCP9w8okegCAIgiAIgiAIwvEggh9BEARBEARBEFoEEfwIgiAIgiAIgtAiiOBHEARBEARBEIQWQQQ/giAIgiAIgiC0CCL4EQRBEARBEAShRRDBjyAIgiAIgiAILYIIfgRBEARBEARBaBFE8CMIgiAIgiAIQosggh9BEARBEARBEFoEXcHPe++9R48ePbDZbNhsNgYOHMisWbPqPP7TTz9FkqQjviwWS5MHLQiCIAiCIAiCoJei5+CkpCReeuklOnXqhKZpfPbZZ4wZM4b169eTlpZ21HNsNhvbt2+v/bskSU0bsSAIgiAIgiAIQiPoCn4uvPDCI/7+wgsv8N5777FixYo6gx9JkoiLi2v8CAVBE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jztr3oyi6zvC5CNEsO+6sY5H6f+LfABcE4df9TzpXAF40XhBL3blpBd3bH+mYLprhikWAWt0Iv7nQIq+2yh8uzteKYVobmPHkTpEdrRx+Dvyzh7bjHh3T14SmXWPxTK7D5R5Mw0iSKpgiAIgnCKE8GPILRQDrv/T3Nw4Nv
"text/plain": [
"<Figure size 1000x400 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"lrmi2=LogisticRegression(multi_class='multinomial',\n",
" solver='lbfgs',\n",
" C=10,\n",
" random_state=42)\n",
"lrmi2.fit(X,y)\n",
"x0,x1=np.meshgrid(\n",
" np.linspace(0,8,500).reshape(-1,1),\n",
" np.linspace(0,3.5,200).reshape(-1,1))\n",
"Xnew=np.c_[x0.ravel(), x1.ravel()]\n",
"\n",
"yProba=lrmi2.predict_proba(Xnew)\n",
"yPred=lrmi2.predict(Xnew)\n",
"\n",
"from matplotlib.colors import ListedColormap\n",
"customc=ListedColormap(['#fafab0', '#9898ff', '#a0faa0'])\n",
"zz1=yProba[:,1].reshape(x0.shape)\n",
"zz=yPred.reshape(x0.shape)\n",
"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,zz1,cmap=plt.cm.brg)\n",
"plt.clabel(contour,inline=1,fontsize=12)\n",
"plt.contourf(x0,x1,zz,cmap=customc)"
]
},
{
"cell_type": "code",
"execution_count": 50,
"id": "01ed7f9b",
"metadata": {},
"outputs": [],
"source": [
"from sklearn.linear_model import LogisticRegression\n",
"X=iris.data[:,2:]\n",
"y=(iris.target==2).astype(int)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "9f90fa65",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-5 {color: black;background-color: white;}#sk-container-id-5 pre{padding: 0;}#sk-container-id-5 div.sk-toggleable {background-color: white;}#sk-container-id-5 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-5 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-5 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-5 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-5 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-5 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-5 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-5 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-5 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-5 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-5 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-5 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-5 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-5 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-5 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-5 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-5 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-5 div.sk-item {position: relative;z-index: 1;}#sk-container-id-5 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-5 div.sk-item::before, #sk-container-id-5 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-5 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-5 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-5 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-5 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-5 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-5 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-5 div.sk-label-container {text-align: center;}#sk-container-id-5 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-5 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-5\" class=\"sk-top-container\
],
"text/plain": [
"LogisticRegression(C=100000000000000000000, random_state=80)"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mlr2=LogisticRegression(solver='lbfgs', C=100**10, \n",
" random_state=80)\n",
"mlr2.fit(X,y)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "c84364aa",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"x0,x1=np.meshgrid(\n",
" np.linspace(1,7,500).reshape(-1,1),\n",
" np.linspace(0,3,200).reshape(-1,1))"
]
},
{
"cell_type": "code",
"execution_count": 47,
"id": "c97642ee",
"metadata": {},
"outputs": [],
"source": [
"Xnew=np.c_[x0.ravel(), x1.ravel()]\n",
"yPred=mlr2.predict_proba(Xnew)"
]
},
{
"cell_type": "code",
"execution_count": 48,
"id": "080dd993",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(3.0, 7.0, 0.7, 3.0)"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAi4AAAGiCAYAAADA0E3hAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAADMZ0lEQVR4nOzdd3xT1f/H8VeS7t1CB9Cyoey994aylyLKUr8q4ACULRuRKUNFEBVBEFH2XmVvCmVvKKWF7r2bNLnfP9KW1aZJm5YWzvPx4PH7Ue6599yEr3zuyTufI5MkSUIQBEEQBKEIkL/uCQiCIAiCIOhLFC6CIAiCIBQZonARBEEQBKHIEIWLIAiCIAhFhihcBEEQBEEoMkThIgiCIAhCkSEKF0EQBEEQigxRuAiCIAiCUGSIwkUQBEEQhCJDFC6CIAiCIBQZBhUuK1asoFatWtjZ2WFnZ0fTpk3Zt2+fzjGbNm2iSpUqWFhYULNmTfbu3ZunCQuCIAiC8PYyqHBxd3dn3rx5XLp0iYsXL9KuXTt69erFzZs3szz+zJkzDBw4kI8//pjLly/Tu3dvevfuzY0bN4wyeUEQBEEQ3i6yvG6y6OTkxMKFC/n4449f+bMBAwaQmJjI7t27M3/WpEkT6tSpw8qVK/NyWUEQBEEQ3kImuR2oVqvZtGkTiYmJNG3aNMtjzp49y9dff/3Czzp37sz27dt1njs1NZXU1NTM32s0GqKioihWrBgymSy3UxYEQRAEoQBJkkR8fDwlS5ZELjdOrNbg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FakCpc/279DKWs7HsfH0H/fepZfP4Nao9E5xiw9uDu7xgic0oO7X1/+ge1PjqKRdI+FZ4XK851xleoEQpOv4GxRAytFMe23jpB
"text/plain": [
"<Figure size 640x480 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"plt.plot(X[y==0, 0], X[y==0,1],'bs')\n",
"plt.plot(X[y==1, 0], X[y==1,1],'g^')\n",
"zz=yPred[:,1].reshape(x0.shape)\n",
"contour=plt.contour(x0,x1,zz)\n",
"plt.clabel(contour, inline=1, fontsize=12)\n",
"plt.axis([3,7,0.7,3])"
]
},
{
"cell_type": "markdown",
"id": "29f23df4",
"metadata": {},
"source": [
"## Multiclass classifer"
]
},
{
"cell_type": "code",
"execution_count": 65,
"id": "0dc5a275",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-8 {color: black;background-color: white;}#sk-container-id-8 pre{padding: 0;}#sk-container-id-8 div.sk-toggleable {background-color: white;}#sk-container-id-8 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-8 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-8 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-8 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-8 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-8 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-8 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-8 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-8 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-8 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-8 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-8 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-8 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-8 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-8 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-8 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-8 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-8 div.sk-item {position: relative;z-index: 1;}#sk-container-id-8 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-8 div.sk-item::before, #sk-container-id-8 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-8 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-8 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-8 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-8 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-8 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-8 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-8 div.sk-label-container {text-align: center;}#sk-container-id-8 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-8 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-8\" class=\"sk-top-container\
],
"text/plain": [
"LogisticRegression(C=10, multi_class='multinomial', random_state=42)"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"X=iris.data[:,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": null,
"id": "a0bd6104",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 66,
"id": "ae96a421",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"x0,x1=np.meshgrid(\n",
" np.linspace(1,7,500).reshape(-1,1),\n",
" np.linspace(0,3,200).reshape(-1,1))"
]
},
{
"cell_type": "code",
"execution_count": 67,
"id": "7efb4dbf",
"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,
"id": "2d63e529",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0xffff23600220>"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAj8AAAG6CAYAAADnOSfBAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIH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OlXNoO+JrQuYfc6mu4rx4+85uBQeBYlkn+XadQ8zyr4CzJ0PU/OcROdxVR/G16AMc/1gSQhobGjYsmfm5SXn/9bTp37nOtp3EV1V32UqyujpLRs5e27aCrflRuY+94yHlK5tbnOLj1ftJvj0WyOmkxdRlRf9kASuUXQj8yCPOPzcFXwrk2h/wRJ1EzHR4dX0jQ+f0cWj2XB8De5wM48k/N7kVDQ+PGRBM/NyAjR97DiBFjy3xsy5btyHIwd911B2vWLKvlmVWOKHxFKp6t3hRTFPmRje5HfVRVxX7U5RGX1yC2agf2AnmLHuHYorFc+D+XPUujf2yn5cTFSPmV1+HRDQjAvDIWgmScO/PIG3ICJcWz+j1CQIe3col7KReAAy/7c/ANX622lYaGxg2HJn5qkZycvezfP5KcnL01epxp0yazdu0GLly4eNVjs2bNoUuXTrRv35Z69ULKHcNmuzZ1X6ob+XHaCpe99O6/tJ2J2ag5VpAE+eHRVTuwl7DMfoCENwdy8os7UfQS9ZYcI27wN+iTcivtq+vuh+/aFohwHcr+AvIHHEc579nzKAS0ezWP9n9zJV4f/psf+1/00wSQhobGDYUmfmqR5OR5ZGVtITl5fo0e5447hhEWFsrs2XNL3Z+bm8uiRct44IH7rlr2euCBJ7jrrnt58813adSoNa1bdwVg+/Zf6Ny5D2ZzJN26DWDp0p+Q5WD27TtYI3MXkutTtqqRH8Xu6i8b3I/8OE5fBkAXE1w
"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('Petal Width', fontsize=12)\n",
"plt.ylabel('Petal Length', fontsize=12)\n",
"#plt.axis([0,7,0,3.5])\n",
"plt.legend()"
]
},
{
"cell_type": "markdown",
"id": "a9531c07",
"metadata": {},
"source": [
"## Sepal"
]
},
{
"cell_type": "code",
"execution_count": 76,
"id": "d99ec4da",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>#sk-container-id-9 {color: black;background-color: white;}#sk-container-id-9 pre{padding: 0;}#sk-container-id-9 div.sk-toggleable {background-color: white;}#sk-container-id-9 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-9 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-9 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-9 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-9 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-9 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-9 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-9 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-9 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-9 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-9 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-9 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-9 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-9 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-9 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-9 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-9 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-9 div.sk-item {position: relative;z-index: 1;}#sk-container-id-9 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-9 div.sk-item::before, #sk-container-id-9 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-9 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-9 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-9 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-9 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-9 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-9 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-9 div.sk-label-container {text-align: center;}#sk-container-id-9 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-9 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-9\" class=\"sk-top-container\
],
"text/plain": [
"LogisticRegression(C=10, multi_class='multinomial', random_state=42)"
]
},
"execution_count": 76,
"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": 83,
"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": 84,
"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": 85,
"id": "2d1cc5a0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0xffff23370a00>"
]
},
"execution_count": 85,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjIAAAG6CAYAAAASx6xxAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjYuMCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy89olMNAAAACXBIWXMAAA9hAAAPYQGoP6dpAAD1kklEQVR4nOzdd3RUVdfA4d+dnt5DAknovRcFQREUUAQpdgEbVuSzvxbsHcv72hUVBbEAKtKkSxMUQwfpNYQE0nubeu/3x5BGCqkQYD9rZSEzd849E1mZnXP23kfRNE1DCCGEEOI8pDvXExBCCCGEqCkJZIQQQghx3pJARgghhBDnLQlkhBBCCHHekkBGCCGEEOctCW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q+ho0HNtKsZbOi13t6ld7p6NqjK1uPbOW5157DWmDlvtvu456b76n1PKtLAhkhhBDiLDl9NaZQRasydXmG0shbRqLoFH6b+Ru//PALY+4Zg6IodOnehYP7DtKiVYsyXyZT5VtoPr4+jL51NB9+/SFTZ01l0dxFZKRn1Ml8q0oCGSGEEOIsKFyN0VF+PokOpcyqTF2eoeTt7c2oW0bx5gtvkpSQxO133Q7AI888wuYNm3n2kWfZtWMXRw4dYemCpTz7yLOVjjflwynMnTWXQ/sPceTgERbOWUhoWCh+/n51NueqkEBGCCGEOAvsLjtx2fGolF9jo6IRl30Cu8udCFvbvJjyjB0/lsyMTAYOGUhY4zAAOnbpyII1Czh68CjXX3k9V/W8indffbfo+Yp4e3vz6X8/ZdClgxjcezBxsXHMWjQLne7shhZStSSEEEJUQV1ULcVlxZOSn1b
"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([0,7,0,3.5])\n",
"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
}