diff --git a/Untitled10.ipynb b/Untitled10.ipynb new file mode 100644 index 0000000..8983709 --- /dev/null +++ b/Untitled10.ipynb @@ -0,0 +1,522 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyMDyF8V5/4X3nUD5uAIYzMW", + "include_colab_link": true + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 80 + }, + "id": "ZxPKNDMKWQGu", + "outputId": "2c376954-4508-47b7-9e6f-dc2d67008ee7" + }, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "LinearRegression()" + ], + "text/html": [ + "
LinearRegression()
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" + ] + }, + "metadata": {}, + "execution_count": 2 + } + ], + "source": [ + "from sklearn.linear_model import LinearRegression\n", + "\n", + "# Example: Train a simple model\n", + "X = [[0, 1], [1, 1], [2, 2], [3, 3]]\n", + "y = [0, 1, 2, 3]\n", + "model = LinearRegression()\n", + "model.fit(X,y)" + ] + }, + { + "cell_type": "code", + "source": [ + "import pickle\n", + "\n", + "# Save the model to a file\n", + "with open('model.pkl', 'wb') as file:\n", + " pickle.dump(model,file)" + ], + "metadata": { + "id": "QCu-y9jiWW7y" + }, + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "# Load the model from the file\n", + "with open('model.pkl', 'rb') as file:\n", + " loaded_model = pickle.load(file)\n", + "\n", + "# Test the loaded model\n", + "print(loaded_model.predict([[1, 1]])) # Should give the same result as the original model" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "f_5fTOW9WndY", + "outputId": "2511196b-30c7-4607-f02e-37039341287e" + }, + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "[1.]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "epR1EQWtWr05" + }, + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file