{ "cells": [ { "cell_type": "code", "execution_count": 3, "id": "b0e43fdc-4787-4b95-ae75-6f73750c0e78", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Defaulting to user installation because normal site-packages is not writeable\n", "Requirement already satisfied: scikit-learn in /home/hayden/.local/lib/python3.10/site-packages (1.4.2)\n", "Requirement already satisfied: scipy>=1.6.0 in /home/hayden/.local/lib/python3.10/site-packages (from scikit-learn) (1.13.0)\n", "Requirement already satisfied: joblib>=1.2.0 in /home/hayden/.local/lib/python3.10/site-packages (from scikit-learn) (1.4.0)\n", "Requirement already satisfied: threadpoolctl>=2.0.0 in /home/hayden/.local/lib/python3.10/site-packages (from scikit-learn) (3.4.0)\n", "Requirement already satisfied: numpy>=1.19.5 in /home/hayden/.local/lib/python3.10/site-packages (from scikit-learn) (1.26.4)\n", "Note: you may need to restart the kernel to use updated packages.\n", "1.4.2\n" ] } ], "source": [ "%pip install scikit-learn\n", "import sklearn\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "af4e3bc3-6fcc-46d8-b7cc-d2fed9a05fc1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "sklearn version: 1.4.2\n" ] } ], "source": [ "print(f\"sklearn version: {sklearn.__version__}\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "ee4d871c-441c-4ee9-8af0-415047644335", "metadata": {}, "outputs": [], "source": [ "from sklearn.datasets import load_iris\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.ensemble import RandomForestClassifier\n", "from sklearn.metrics import accuracy_score\n", "\n", "# Load the Iris dataset\n", "iris = load_iris()\n", "X, y = iris.data, iris.target\n", "\n", "# Split the data into training and test sets\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=42)\n", "\n", "# Initialize the classifier\n", "classifier = RandomForestClassifier(n_estimators=100, random_state=42)\n", "\n", "# Train the classifier\n", "classifier.fit(X_train, y_train)\n", "\n", "# Make predictions on the test set\n", "predictions = classifier.predict(X_test)\n", "\n", "# Calculate the accuracy\n", "accuracy = accuracy_score(y_test, predictions)" ] }, { "cell_type": "code", "execution_count": 7, "id": "84cd4fc6-4e68-4c79-bfeb-777bce8e62e5", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['model.joblib']" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from joblib import dump\n", "dump(classifier, 'model.joblib')" ] }, { "cell_type": "code", "execution_count": null, "id": "022af2af-01fd-4de5-a056-0f41337c0c1a", "metadata": {}, "outputs": [], "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.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }