From 894e2f4d72e23f24661a44f5da84e7ae3be5090b Mon Sep 17 00:00:00 2001 From: Tushar Ghule <32256009+tushar-ghule@users.noreply.github.com> Date: Wed, 15 Mar 2023 12:40:53 -0400 Subject: [PATCH 1/2] Created using Colaboratory --- Ch03_Tushar.ipynb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Ch03_Tushar.ipynb diff --git a/Ch03_Tushar.ipynb b/Ch03_Tushar.ipynb new file mode 100644 index 00000000..5bc1e653 --- /dev/null +++ b/Ch03_Tushar.ipynb @@ -0,0 +1,39 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [], + "authorship_tag": "ABX9TyPmOUQsb0KaXIHLHFWPL3t1", + "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": [ + "" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "N8FP075EIiEO" + }, + "outputs": [], + "source": [] + } + ] +} \ No newline at end of file From 69886dd464b41654244caec7b1919aba11b9fb2b Mon Sep 17 00:00:00 2001 From: Tushar Ghule <32256009+tushar-ghule@users.noreply.github.com> Date: Wed, 15 Mar 2023 13:04:40 -0400 Subject: [PATCH 2/2] Created using Colaboratory --- Ch03_Tushar.ipynb | 216 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 213 insertions(+), 3 deletions(-) diff --git a/Ch03_Tushar.ipynb b/Ch03_Tushar.ipynb index 5bc1e653..322a2ef5 100644 --- a/Ch03_Tushar.ipynb +++ b/Ch03_Tushar.ipynb @@ -4,7 +4,7 @@ "metadata": { "colab": { "provenance": [], - "authorship_tag": "ABX9TyPmOUQsb0KaXIHLHFWPL3t1", + "authorship_tag": "ABX9TyORLC2JDCkaONjXGhBNNON1", "include_colab_link": true }, "kernelspec": { @@ -28,12 +28,222 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "id": "N8FP075EIiEO" }, "outputs": [], - "source": [] + "source": [ + "from sklearn import datasets \n", + "import numpy as np " + ] + }, + { + "cell_type": "code", + "source": [ + "iris = datasets.load_iris()\n", + "X = iris.data[:, [2,3]]\n", + "Y = iris.target \n", + "\n", + "print(\"Class labels: \", np.unique(Y))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "idX04APuJ_g0", + "outputId": "e983a538-d7ce-4540-a4b4-cf0c3d1a73fd" + }, + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Class labels: [0 1 2]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from sklearn.model_selection import train_test_split\n", + "\n", + "X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size= 0.3, random_state=1, stratify = Y)" + ], + "metadata": { + "id": "EgcMvtktKRnN" + }, + "execution_count": 3, + "outputs": [] + }, + { + "cell_type": "code", + "source": [ + "print('Labels count in Y:', np.bincount(Y))\n", + "print('Labels count in Y_train:', np.bincount(y_train))\n", + "print('Labels count in Y_test:', np.bincount(y_test))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "vaDTfII-LqWc", + "outputId": "e32166c3-598f-4f1e-8682-54c5cd9ffa85" + }, + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "name": "stdout", + "text": [ + "Labels count in Y: [50 50 50]\n", + "Labels count in Y_train: [35 35 35]\n", + "Labels count in Y_test: [15 15 15]\n" + ] + } + ] + }, + { + "cell_type": "code", + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "\n", + "sc = StandardScaler()\n", + "sc.fit(X_train)\n", + "# this will get the values of mean and standard deviation \n", + "X_train_std = sc.transform(X_train)\n", + "X_test_std = sc.transform(X_test)\n" + ], + "metadata": { + "id": "BGg2xIMdL0Ib" + }, + "execution_count": 6, + "outputs": [] + }, + { + "cell_type": "markdown", + "source": [ + "Training the perceptron " + ], + "metadata": { + "id": "gXQ8fetLMh7J" + } + }, + { + "cell_type": "code", + "source": [ + "from sklearn.linear_model import Perceptron\n", + "\n", + "ppn = Perceptron(eta0 = 0.1, random_state = 1)\n", + "ppn.fit(X_train_std, y_train)" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 74 + }, + "id": "o5bohE6xMgYv", + "outputId": "77f1c87f-db79-4b9b-d884-57ba32d7eb84" + }, + "execution_count": 8, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "Perceptron(eta0=0.1, random_state=1)" + ], + "text/html": [ + "
Perceptron(eta0=0.1, random_state=1)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
Perceptron(eta0=0.1, random_state=1)