{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "LogisticRegression.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyN3MXNOCuHRm+lDyjDfEzk1",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
""
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "KEfIoNpkI-7W",
"colab_type": "text"
},
"source": [
"# ロジスティック回帰 サンプルプログラム"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "t3PvIlPGJHfj",
"colab_type": "text"
},
"source": [
"## データの準備と確認"
]
},
{
"cell_type": "code",
"metadata": {
"id": "LUMvxX_qHjBC",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 73
},
"outputId": "5c5dbe47-78fc-4645-f83b-a89819aff415"
},
"source": [
"# iris データセットの読み込んで概要を表示\n",
"from sklearn.datasets import load_iris\n",
"\n",
"iris = load_iris()\n",
"print(iris.data.shape)\n",
"print(iris.target.shape)\n",
"print(iris.target_names)"
],
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": [
"(150, 4)\n",
"(150,)\n",
"['setosa' 'versicolor' 'virginica']\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"id": "lYkroCT16Uvx",
"colab_type": "code",
"colab": {
"base_uri": "https://localhost:8080/",
"height": 206
},
"outputId": "61984f88-bfde-4df6-965f-1c7c3bd126be"
},
"source": [
"# irisデータをデータフレームに編入 / ターゲットの 0,1,2 は名称に変更\n",
"import pandas as pd\n",
"\n",
"df = pd.DataFrame(iris.data, columns=iris.feature_names)\n",
"df['target'] = iris.target_names[iris.target]\n",
"\n",
"df.head()"
],
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/html": [
"
| \n", " | sepal length (cm) | \n", "sepal width (cm) | \n", "petal length (cm) | \n", "petal width (cm) | \n", "target | \n", "
|---|---|---|---|---|---|
| 0 | \n", "5.1 | \n", "3.5 | \n", "1.4 | \n", "0.2 | \n", "setosa | \n", "
| 1 | \n", "4.9 | \n", "3.0 | \n", "1.4 | \n", "0.2 | \n", "setosa | \n", "
| 2 | \n", "4.7 | \n", "3.2 | \n", "1.3 | \n", "0.2 | \n", "setosa | \n", "
| 3 | \n", "4.6 | \n", "3.1 | \n", "1.5 | \n", "0.2 | \n", "setosa | \n", "
| 4 | \n", "5.0 | \n", "3.6 | \n", "1.4 | \n", "0.2 | \n", "setosa | \n", "