diff --git a/TP1.ipynb b/TP1.ipynb index 2f38326..6e1f4c7 100644 --- a/TP1.ipynb +++ b/TP1.ipynb @@ -110,6 +110,77 @@ "sns.heatmap(df.corr(numeric_only=True),annot=True,fmt=\".2f\")\n", "plt.show()" ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[10 0 0]\n", + " [ 0 9 0]\n", + " [ 0 0 11]]\n", + " precision recall f1-score support\n", + "\n", + " setosa 1.00 1.00 1.00 10\n", + " versicolor 1.00 1.00 1.00 9\n", + " virginica 1.00 1.00 1.00 11\n", + "\n", + " accuracy 1.00 30\n", + " macro avg 1.00 1.00 1.00 30\n", + "weighted avg 1.00 1.00 1.00 30\n", + "\n" + ] + } + ], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "\n", + "X = df.drop('species',axis=1)\n", + "y = df[\"species\"]\n", + "\n", + "X_train,X_test,y_train,y_test = train_test_split(X, y, test_size=0.2, random_state=42)\n", + "\n", + "from sklearn.linear_model import LogisticRegression\n", + "from sklearn.metrics import confusion_matrix,classification_report\n", + "\n", + "model = LogisticRegression(max_iter=200)\n", + "model.fit(X_train,y_train)\n", + "\n", + "y_pred = model.predict(X_test)\n", + "\n", + "print(confusion_matrix(y_test,y_pred))\n", + "print(classification_report(y_test,y_pred))" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Précision moyenn : 0.9733333333333334\n" + ] + } + ], + "source": [ + "from sklearn.model_selection import cross_val_score\n", + "scores = cross_val_score(model,X,y,cv=5)\n", + "print(\"Précision moyenn :\",scores.mean())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {