-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClassifAI_ 2 - KNN Part 1
1 lines (1 loc) · 21.8 KB
/
ClassifAI_ 2 - KNN Part 1
1
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"ClassifAI: 2 - KNN Part 1","provenance":[{"file_id":"1bq3o8BF6b3Ye3ZkIjAFYXLU26S9G483O","timestamp":1653851738725},{"file_id":"1gs1vylRznm37mvmDdZz_R8fYPxLUnnuR","timestamp":1633812055755},{"file_id":"1huRMCV_62rtivjV79va3DJWQKsl_Zvs3","timestamp":1617834022690}],"collapsed_sections":[]},"kernelspec":{"name":"python3","display_name":"Python 3"}},"cells":[{"cell_type":"code","metadata":{"id":"9J_-tg8yjrr9","executionInfo":{"status":"ok","timestamp":1660431344446,"user_tz":420,"elapsed":412,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}}},"source":["import pandas as pd\n","from math import *"],"execution_count":1,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/","height":206},"id":"r467CkSVg9HL","executionInfo":{"status":"ok","timestamp":1660431351819,"user_tz":420,"elapsed":282,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"306b0d22-583c-4aa7-f5d5-ba0a4d1ff3e8"},"source":["# Load the dataset\n","\n","url = \"https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv\"\n","names = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width', 'class']\n","dataset = pd.read_csv(url, names=names)\n","dataset.head()"],"execution_count":2,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" sepal_length sepal_width petal_length petal_width class\n","0 5.1 3.5 1.4 0.2 Iris-setosa\n","1 4.9 3.0 1.4 0.2 Iris-setosa\n","2 4.7 3.2 1.3 0.2 Iris-setosa\n","3 4.6 3.1 1.5 0.2 Iris-setosa\n","4 5.0 3.6 1.4 0.2 Iris-setosa"],"text/html":["\n"," <div id=\"df-79a5aef9-b34c-4af7-9e6e-04ad8d43a1c5\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>sepal_length</th>\n"," <th>sepal_width</th>\n"," <th>petal_length</th>\n"," <th>petal_width</th>\n"," <th>class</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>5.1</td>\n"," <td>3.5</td>\n"," <td>1.4</td>\n"," <td>0.2</td>\n"," <td>Iris-setosa</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>4.9</td>\n"," <td>3.0</td>\n"," <td>1.4</td>\n"," <td>0.2</td>\n"," <td>Iris-setosa</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>4.7</td>\n"," <td>3.2</td>\n"," <td>1.3</td>\n"," <td>0.2</td>\n"," <td>Iris-setosa</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>4.6</td>\n"," <td>3.1</td>\n"," <td>1.5</td>\n"," <td>0.2</td>\n"," <td>Iris-setosa</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>5.0</td>\n"," <td>3.6</td>\n"," <td>1.4</td>\n"," <td>0.2</td>\n"," <td>Iris-setosa</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-79a5aef9-b34c-4af7-9e6e-04ad8d43a1c5')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-79a5aef9-b34c-4af7-9e6e-04ad8d43a1c5 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-79a5aef9-b34c-4af7-9e6e-04ad8d43a1c5');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":2}]},{"cell_type":"markdown","metadata":{"id":"JJsUMcRykFGd"},"source":["**Step 1.) Euclidean Distance Function**\n","\n","First, let's create a function that calculates the euclidean distance between two rows from the above table. The formula for euclidean distance is:\n","\n","$$ d(x, y) = \\sqrt{\\sum_{i=1}^{n}({x_i - y_i})^2}$$\n","\n","where $x$ is the first row of data, $y$ is the second row of data, and $i$ is the index of a specific column as we sum across all n columns.\n","\n","So, for example, the euclidean distance between row 0 and row 1 is:\n","\n","$$ \\sqrt{(5.1 - 4.9)^2 + (3.5 - 3.0)^2 + (1.4 - 1.4)^2 + (0.2 - 0.2)^2} \\approx 0.53852. $$\n","\n","Hint: the function should ignore the last column in each row from the distance calculation! This is because the last column is simply the flower's class."]},{"cell_type":"code","metadata":{"id":"BRxiEoB4jpuu","executionInfo":{"status":"ok","timestamp":1660431395649,"user_tz":420,"elapsed":291,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}}},"source":["def euclidean_distance(row1, row2):\n"," distance = 0.0\n"," for i in range(len(row1) - 1):\n"," distance += pow(row1[i] - row2[i], 2)\n"," return sqrt(distance)"],"execution_count":3,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"5TzXEFwtkCGJ","executionInfo":{"status":"ok","timestamp":1660431395994,"user_tz":420,"elapsed":4,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"811ccbe1-fb70-49ba-f241-ea822623f2cb"},"source":["# Test that your function correctly calculates the distance between row 0 and row 1 (0.53852)\n","row0 = dataset.loc[0]\n","row1 = dataset.loc[1]\n","euclidean_distance(row0, row1)"],"execution_count":4,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0.5385164807134502"]},"metadata":{},"execution_count":4}]},{"cell_type":"markdown","metadata":{"id":"-cyJzLH-pCo8"},"source":["**Step 2.) Get Nearest Neightbors**\n","\n","Now, let's create a function that finds the $k$ closest instances for a new piece of data in the dataset as defined by our euclidean distance function. In order to find the neighbors for a new piece of data, we should:\n","\n","1. Calculate the distance between each row in the dataset to the new piece of data\n","2. Sort all rows in the training dataset by their distance to the new data from smallest to largest\n","3. Select the top $k$ rows as the most similar neighbors\n","\n","Keep track of the distance for each row in the dataset as a tuple of a row and a distance. Tuples are used to store multiple items in a single variable. For example:"]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"jPgqenisstAY","executionInfo":{"status":"ok","timestamp":1660431401068,"user_tz":420,"elapsed":304,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"369d3abb-240c-4b6f-efe5-dc0dff06e1e0"},"source":["a_tuple = (1, 2, 3)\n","print(a_tuple)\n","print(a_tuple[0])"],"execution_count":5,"outputs":[{"output_type":"stream","name":"stdout","text":["(1, 2, 3)\n","1\n"]}]},{"cell_type":"code","metadata":{"id":"61W0lxwlox5i","executionInfo":{"status":"ok","timestamp":1660431406242,"user_tz":420,"elapsed":233,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}}},"source":["def get_neighbors(dataset, new_data, num_neighbors):\n"," row_count = dataset.shape[0]\n"," distances = []\n"," for row_index in range(row_count): #row_count\n"," row = dataset.loc[row_index]\n"," distances.append((row[4], euclidean_distance(row, new_data)))\n"," distances.sort(key=lambda tup: tup[1])\n"," neighbors = distances[:num_neighbors]\n"," return neighbors"],"execution_count":6,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"E3bP3sRMtN6o","executionInfo":{"status":"ok","timestamp":1660431407734,"user_tz":420,"elapsed":248,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"7b1f5f9c-5198-4f2d-dbc6-02e940182a17"},"source":["# Test that your function correctly finds the 5 nearest neighbors to row 0\n"," \n","new_data = dataset.loc[0]\n","neighbors = get_neighbors(dataset, new_data, 5)\n","for neighbor in neighbors:\n"," print(neighbor)"],"execution_count":7,"outputs":[{"output_type":"stream","name":"stdout","text":["('Iris-setosa', 0.0)\n","('Iris-setosa', 0.09999999999999998)\n","('Iris-setosa', 0.1414213562373093)\n","('Iris-setosa', 0.14142135623730964)\n","('Iris-setosa', 0.14142135623730995)\n"]}]},{"cell_type":"markdown","metadata":{"id":"8DQUSD3AD7t2"},"source":["**3.) Making Predictions**\n","\n","For a k-NN classifier, we make predictions based on the most represented class among the $k$ neighbors. As such, create a function that returns the most common class represented by the neighbors."]},{"cell_type":"code","metadata":{"id":"T4adXtOgGw_Y","executionInfo":{"status":"ok","timestamp":1660431703818,"user_tz":420,"elapsed":249,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}}},"source":["import itertools\n","import operator\n","\n","def most_common(L): # L = list of classes sorted by Euclidean Distance\n"," # get an iterable of (item, iterable) pairs\n"," SL = sorted((x, i) for i, x in enumerate(L)) # SL = list with indexes stored in tuple, grouped by class\n"," # print 'SL:', SL \n"," groups = itertools.groupby(SL, key=lambda tup: tup[0]) #key=operator.itemgetter(0)\n"," # auxiliary function to get \"quality\" for an item\n"," def _auxfun(g):\n"," item, iterable = g # iterable = group of common class, each element = tuple (class, index)\n"," count = 0\n"," min_index = len(L)\n"," for _, where in iterable:\n"," count += 1\n"," min_index = min(min_index, where) # smallest min_index means closest neighbor\n"," # print 'item %r, count %r, minind %r' % (item, count, min_index)\n"," return count, -min_index\n"," # pick the highest-count/earliest item\n"," return max(groups, key=_auxfun)[0]"],"execution_count":8,"outputs":[]},{"cell_type":"code","metadata":{"id":"T5SEdHiItYyJ","executionInfo":{"status":"ok","timestamp":1660431704106,"user_tz":420,"elapsed":3,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}}},"source":["def predict_classification(dataset, new_data, num_neighbors):\n"," neighbors = get_neighbors(dataset, new_data, num_neighbors)\n"," neighbor_classes = []\n"," for TUPLE in neighbors:\n"," neighbor_classes.append(TUPLE[0])\n"," prediction = most_common(neighbor_classes)\n"," return prediction\n"," \n"," \n"],"execution_count":9,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"A0FUIVkLII43","executionInfo":{"status":"ok","timestamp":1660431729146,"user_tz":420,"elapsed":280,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"519521c8-ce07-466c-eb9c-f0eaf24e45ab"},"source":["# This block of code should predict that the new flower is of the class iris-versicolor\n","\n","new_flower = [5.9, 2.8, 4.35, 1.3]\n","result1 = predict_classification(dataset, new_flower, 11)\n","print(\"The new flower is of the class \" + result1)\n","result2 = predict_classification(dataset, new_flower, 11)\n","print(\"The new flower is of the class \" + result2)"],"execution_count":10,"outputs":[{"output_type":"stream","name":"stdout","text":["The new flower is of the class Iris-versicolor\n","The new flower is of the class Iris-versicolor\n"]}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"n94G1cAYJh3D","executionInfo":{"status":"ok","timestamp":1660431732132,"user_tz":420,"elapsed":305,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"6df79f7d-4ad0-4b6d-a5e9-41c42b6363e2"},"source":["# This block of code should predict that the second new flower is of the class iris-virginica\n","\n","new_flower2 = [6.5, 3.0, 5.55, 2.0]\n","result3 = predict_classification(dataset, new_flower2, 13)\n","print(\"The new flower is of the class \" + result3)\n","result4 = predict_classification(dataset, new_flower2, 13)\n","print(\"The new flower is of the class \" + result4)"],"execution_count":11,"outputs":[{"output_type":"stream","name":"stdout","text":["The new flower is of the class Iris-virginica\n","The new flower is of the class Iris-virginica\n"]}]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"koDqfxi5JxsN","executionInfo":{"status":"ok","timestamp":1660431734536,"user_tz":420,"elapsed":291,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"074e5b8c-5a50-44dd-d6c9-534e89096b3e"},"source":["# This block of code should predict that the third new flower is of the class iris-setosa\n","\n","new_flower3 = [5.0, 3.4, 1.5, 0.2]\n","result5 = predict_classification(dataset, new_flower3, 15)\n","print(\"The new flower is of the class \" + result5)\n","result6 = predict_classification(dataset, new_flower3, 15)\n","print(\"The new flower is of the class \" + result6)"],"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["The new flower is of the class Iris-setosa\n","The new flower is of the class Iris-setosa\n"]}]},{"cell_type":"markdown","metadata":{"id":"nW3CIOflK149"},"source":["**1.) Define the problem:**\n","\n","Can we predict the class of the iris flower given sepal length, sepal width, petal length, and petal width?"]},{"cell_type":"markdown","metadata":{"id":"-gBxHW0bK8ab"},"source":["**2.) Prepare your data:**\n","\n","We've already loaded the dataset. Now we need to split the dataset for two purposes:\n","\n","1. To *train* our k-NN classifier.\n","2. To *test* the performance of our classifier.\n","\n","Let's use 80% of our dataset to train and 20% to test.\n","\n"]},{"cell_type":"code","metadata":{"id":"xbMZXjqEKGub","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1660431739816,"user_tz":420,"elapsed":379,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"0fd78d8c-ba08-4f68-f7ef-d04ac511f9b1"},"source":["training_proportion = 0.8\n","# Find the total number of flowers (rows) in the dataset\n","num_flowers = dataset.shape[0]\n","# Find the number of flowers (rows) in the training set as an integer\n","num_train = training_proportion * dataset.shape[0]\n","# Find the number of flowers (rows) in the testing set as an integer\n","num_test = dataset.shape[0] - (training_proportion) * dataset.shape[0]\n","# Don't edit the code below this line\n","print(\"Total: \", num_flowers, \";\",\n"," \"Training: \", num_train, \";\",\n"," \"Testing: \", num_test)"],"execution_count":13,"outputs":[{"output_type":"stream","name":"stdout","text":["Total: 150 ; Training: 120.0 ; Testing: 30.0\n"]}]},{"cell_type":"code","metadata":{"id":"rWONjRQDM-q_","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1660431749267,"user_tz":420,"elapsed":262,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"cc404c88-1251-493c-bbb0-c09a5990b9c2"},"source":["# This code randomly shuffles the row of our dataset before we split it into testing and training sets\n","print(dataset.head())\n","dataset = dataset.sample(frac=1).reset_index(drop=True)\n","print(dataset.head())"],"execution_count":14,"outputs":[{"output_type":"stream","name":"stdout","text":[" sepal_length sepal_width petal_length petal_width class\n","0 5.1 3.5 1.4 0.2 Iris-setosa\n","1 4.9 3.0 1.4 0.2 Iris-setosa\n","2 4.7 3.2 1.3 0.2 Iris-setosa\n","3 4.6 3.1 1.5 0.2 Iris-setosa\n","4 5.0 3.6 1.4 0.2 Iris-setosa\n"," sepal_length sepal_width petal_length petal_width class\n","0 6.7 3.1 5.6 2.4 Iris-virginica\n","1 7.7 2.6 6.9 2.3 Iris-virginica\n","2 5.6 2.5 3.9 1.1 Iris-versicolor\n","3 4.6 3.1 1.5 0.2 Iris-setosa\n","4 6.5 2.8 4.6 1.5 Iris-versicolor\n"]}]},{"cell_type":"markdown","metadata":{"id":"8cgduM7yOOoJ"},"source":["Now, use the Pandas take() method to split the dataset into testing and training sets:\n","```python\n","pd.DataFrame.take(indices)\n","```\n","where indices is an array of ints indicating which positions to take.\n"]},{"cell_type":"code","metadata":{"id":"0le4SPE8NrqC","executionInfo":{"status":"ok","timestamp":1660431753500,"user_tz":420,"elapsed":240,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}}},"source":["training = dataset.take(range(int(num_train)))\n","testing = dataset.take(range(int(num_train), int(num_train + num_test)))"],"execution_count":15,"outputs":[]},{"cell_type":"code","metadata":{"id":"IwmH3HraRkdb","colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"status":"ok","timestamp":1660431753767,"user_tz":420,"elapsed":3,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"d183f483-0bb8-4f11-d2eb-54fd576e854b"},"source":["# Check that your training set has 80% of the data and your testing set has 20%\n","print(\"Training: \", training.shape[0], \";\",\n"," \"Testing: \", testing.shape[0])"],"execution_count":16,"outputs":[{"output_type":"stream","name":"stdout","text":["Training: 120 ; Testing: 30\n"]}]},{"cell_type":"markdown","metadata":{"id":"nBvcR_znCX6R"},"source":["**3.) Evaluate your algorithm:**\n","\n","Finally, let's check the accuracy of this model by validating it against the 20% testing set that we created earlier.\n","\n","*Make sure to use your training set, not the whole dataset! You can set $k$ to whatever you want!*"]},{"cell_type":"code","metadata":{"id":"vVwCjdmyRw16","executionInfo":{"status":"ok","timestamp":1660431755800,"user_tz":420,"elapsed":323,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}}},"source":["# Create two lists, one for your predictions and one for the actual flower classes\n","\n","testing_row_count = testing.shape[0]\n","predictions = []\n","actual = []\n","for row_index in range(0, testing_row_count):\n"," prediction = predict_classification(training, testing.iloc[row_index], 10)\n"," predictions.append(prediction)\n"," actual.append(testing.iloc[row_index][-1])"],"execution_count":17,"outputs":[]},{"cell_type":"code","metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"uN-x_WBSE4Wp","executionInfo":{"status":"ok","timestamp":1660431757907,"user_tz":420,"elapsed":3,"user":{"displayName":"Leo Huang","userId":"16558901284710269921"}},"outputId":"3f210694-7b14-4d99-faeb-c9649987c1d6"},"source":["# Count up the number of similar elements between the two lists and find proportion of that count out of the total number of elements in one list (accuracy)\n","count = 0\n","total_number = int(num_test)\n","\n","for i in range(total_number):\n"," if predictions[i] == actual[i]:\n"," count += 1\n","accuracy = count / total_number\n","accuracy"],"execution_count":18,"outputs":[{"output_type":"execute_result","data":{"text/plain":["0.9333333333333333"]},"metadata":{},"execution_count":18}]},{"cell_type":"code","source":[""],"metadata":{"id":"eiDN5se8pWKz"},"execution_count":null,"outputs":[]}]}