Skip to content

Commit

Permalink
move code
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Jun 20, 2024
1 parent b22b018 commit 6c2c2fc
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions python/examples/ml/iris.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
"Source [Kaggle Iris](https://www.kaggle.com/uciml/iris)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9796f468-014b-47e3-82fd-38d2169d8168",
"metadata": {},
"outputs": [],
"source": [
"!pip install seaborn scikit-learn pandas numpy matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -70,25 +80,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "b2e8b3dd",
"metadata": {},
"outputs": [],
"source": [
"y = df[\"Species\"]\n",
"X = df[[\"SepalLengthCm\", \"SepalWidthCm\",\"PetalLengthCm\",\"PetalWidthCm\"]]\n",
"x_train, x_test, y_train, y_test = train_test_split(X, y, stratify=y)\n",
"model = LogisticRegression(max_iter=200).fit(x_train, y_train)\n",
"print('train accuracy:', model.score(x_train, y_train))\n",
"print('test accuracy:', model.score(x_test, y_test))\n",
"y_prediction = model.predict(x_test)\n",
"print('test classification report:')\n",
"print(classification_report(y_test, y_prediction))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2009513b",
"id": "1a6962cb-180c-4d7c-9422-7275f5e35fd8",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -99,7 +91,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "e43ea3c1",
"id": "6a3cbab0-706c-486c-9c25-163a054d8b6a",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -111,7 +103,7 @@
},
{
"cell_type": "markdown",
"id": "b8f49821",
"id": "ecec6a69-47c7-4ca0-9cd1-4a3de69b9171",
"metadata": {},
"source": [
"Set the color manually"
Expand All @@ -120,7 +112,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "04beedc6",
"id": "afc942c1-c205-4e10-a34f-830510e1ee0f",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -130,6 +122,24 @@
"sns.scatterplot(x=\"SepalLengthCm\", y=\"SepalWidthCm\", hue=\"Species\", data=df, palette=palette);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b2e8b3dd",
"metadata": {},
"outputs": [],
"source": [
"y = df[\"Species\"]\n",
"X = df[[\"SepalLengthCm\", \"SepalWidthCm\",\"PetalLengthCm\",\"PetalWidthCm\"]]\n",
"x_train, x_test, y_train, y_test = train_test_split(X, y, stratify=y)\n",
"model = LogisticRegression(max_iter=200).fit(x_train, y_train)\n",
"print('train accuracy:', model.score(x_train, y_train))\n",
"print('test accuracy:', model.score(x_test, y_test))\n",
"y_prediction = model.predict(x_test)\n",
"print('test classification report:')\n",
"print(classification_report(y_test, y_prediction))"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -291,7 +301,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
"version": "3.12.3"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 6c2c2fc

Please sign in to comment.