diff --git a/Classification/Decision Tree Classification/decision_tree_classification.ipynb b/Classification/Decision Tree Classification/decision_tree_classification.ipynb new file mode 100644 index 0000000..1f581ac --- /dev/null +++ b/Classification/Decision Tree Classification/decision_tree_classification.ipynb @@ -0,0 +1,573 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0MRC0e0KhQ0S" + }, + "source": [ + "# Decision Tree Classification" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LWd1UlMnhT2s" + }, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YvGPUQaHhXfL" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "K1VMqkGvhc3-" + }, + "source": [ + "## Importing the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "M52QDmyzhh9s" + }, + "outputs": [], + "source": [ + "dataset = pd.read_csv('../../datasets/Social_Network_Ads.csv')\n", + "X = dataset.iloc[:, :-1].values\n", + "y = dataset.iloc[:, -1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YvxIPVyMhmKp" + }, + "source": [ + "## Splitting the dataset into the Training set and Test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AVzJWAXIhxoC" + }, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2065, + "status": "ok", + "timestamp": 1588269312367, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "P3nS3-6r1i2B", + "outputId": "fa90271e-3c0a-43c2-ba6c-cfce4819e98e" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2059, + "status": "ok", + "timestamp": 1588269312368, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "8dpDLojm1mVG", + "outputId": "4eaa18a3-6481-42bb-c409-7227565c7fe1" + }, + "outputs": [], + "source": [ + "print(y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2055, + "status": "ok", + "timestamp": 1588269312369, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qbb7i0DH1qui", + "outputId": "5c45ffab-4587-4828-8204-0f4fedf88980" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2051, + "status": "ok", + "timestamp": 1588269312369, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "kj1hnFAR1s5w", + "outputId": "984874ad-447c-441b-decb-3c775d9d7936" + }, + "outputs": [], + "source": [ + "print(y_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kW3c7UYih0hT" + }, + "source": [ + "## Feature Scaling" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9fQlDPKCh8sc" + }, + "outputs": [], + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "sc = StandardScaler()\n", + "X_train = sc.fit_transform(X_train)\n", + "X_test = sc.transform(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2046, + "status": "ok", + "timestamp": 1588269312370, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "syrnD1Op2BSR", + "outputId": "c71d71b1-d8b6-4391-dee4-6f8e48b848c2" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2041, + "status": "ok", + "timestamp": 1588269312370, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "JUd6iBRp2C3L", + "outputId": "5762f294-8c56-4d79-c441-3468e2cb5e6a" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bb6jCOCQiAmP" + }, + "source": [ + "## Training the Decision Tree Classification model on the Training set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 120 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2037, + "status": "ok", + "timestamp": 1588269312370, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "e0pFVAmciHQs", + "outputId": "1a9b0904-ea86-40d9-bca2-a28fdf00d56d" + }, + "outputs": [], + "source": [ + "from sklearn.tree import DecisionTreeClassifier\n", + "classifier = DecisionTreeClassifier(criterion = 'entropy', random_state = 0)\n", + "classifier.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "yyxW5b395mR2" + }, + "source": [ + "## Predicting a new result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2034, + "status": "ok", + "timestamp": 1588269312371, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "f8YOXsQy58rP", + "outputId": "cd4b80f5-59ad-40b1-d5f3-8fc98b87bd66" + }, + "outputs": [], + "source": [ + "print(classifier.predict(sc.transform([[30,87000]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vKYVQH-l5NpE" + }, + "source": [ + "## Predicting the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2029, + "status": "ok", + "timestamp": 1588269312371, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "p6VMTb2O4hwM", + "outputId": "05404102-6c3b-4c34-a180-e2a1d5a85e57" + }, + "outputs": [], + "source": [ + "y_pred = classifier.predict(X_test)\n", + "print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h4Hwj34ziWQW" + }, + "source": [ + "## Making the Confusion Matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2026, + "status": "ok", + "timestamp": 1588269312371, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "D6bpZwUiiXic", + "outputId": "031d8132-ae7a-4a4c-b2dd-26b88da40ed6" + }, + "outputs": [], + "source": [ + "from sklearn.metrics import confusion_matrix, accuracy_score\n", + "cm = confusion_matrix(y_test, y_pred)\n", + "print(cm)\n", + "accuracy_score(y_test, y_pred)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6OMC_P0diaoD" + }, + "source": [ + "## Visualising the Training set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 30339, + "status": "ok", + "timestamp": 1588269340691, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "_NOjKvZRid5l", + "outputId": "cd4f51f4-8260-40bf-aa20-e238d60ccc1e" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_train), y_train\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Decision Tree Classification (Training set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SZ-j28aPihZx" + }, + "source": [ + "## Visualising the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 55016, + "status": "ok", + "timestamp": 1588269365372, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qeTjz2vDilAC", + "outputId": "c9624a3f-544e-4033-8cb8-bb4b7b08ff4a" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_test), y_test\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Decision Tree Classification (Test set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyP02NrvZmmq4qjp5mwU3Mr2", + "collapsed_sections": [], + "machine_shape": "hm", + "name": "decision_tree_classification.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Classification/K-NN/k_nearest_neighbors.ipynb b/Classification/K-NN/k_nearest_neighbors.ipynb new file mode 100644 index 0000000..c1c07ec --- /dev/null +++ b/Classification/K-NN/k_nearest_neighbors.ipynb @@ -0,0 +1,573 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0MRC0e0KhQ0S" + }, + "source": [ + "# K-Nearest Neighbors (K-NN)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LWd1UlMnhT2s" + }, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YvGPUQaHhXfL" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "K1VMqkGvhc3-" + }, + "source": [ + "## Importing the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "M52QDmyzhh9s" + }, + "outputs": [], + "source": [ + "dataset = pd.read_csv('../../datasets/Social_Network_Ads.csv')\n", + "X = dataset.iloc[:, :-1].values\n", + "y = dataset.iloc[:, -1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YvxIPVyMhmKp" + }, + "source": [ + "## Splitting the dataset into the Training set and Test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AVzJWAXIhxoC" + }, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2393, + "status": "ok", + "timestamp": 1588492962259, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "P3nS3-6r1i2B", + "outputId": "2972f900-ae1f-493b-9097-11ab9314d030" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2386, + "status": "ok", + "timestamp": 1588492962260, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "8dpDLojm1mVG", + "outputId": "f2afb6eb-2911-439a-d6b6-9e025bbedc75" + }, + "outputs": [], + "source": [ + "print(y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2381, + "status": "ok", + "timestamp": 1588492962260, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qbb7i0DH1qui", + "outputId": "54ee7cd4-ffc8-429a-a52c-2ccd4e4d4411" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2375, + "status": "ok", + "timestamp": 1588492962260, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "kj1hnFAR1s5w", + "outputId": "bdc8000b-208d-441b-8a97-a552ebb53fa0" + }, + "outputs": [], + "source": [ + "print(y_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kW3c7UYih0hT" + }, + "source": [ + "## Feature Scaling" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9fQlDPKCh8sc" + }, + "outputs": [], + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "sc = StandardScaler()\n", + "X_train = sc.fit_transform(X_train)\n", + "X_test = sc.transform(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2367, + "status": "ok", + "timestamp": 1588492962261, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "syrnD1Op2BSR", + "outputId": "721c0899-23c8-42ff-dc5a-d008c774ac78" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2362, + "status": "ok", + "timestamp": 1588492962262, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "JUd6iBRp2C3L", + "outputId": "073a17d9-26cd-48e5-923b-0bdb74b5fb14" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bb6jCOCQiAmP" + }, + "source": [ + "## Training the K-NN model on the Training set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2356, + "status": "ok", + "timestamp": 1588492962262, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "e0pFVAmciHQs", + "outputId": "8cb18c23-669b-452a-9bee-b2f96534f0f5" + }, + "outputs": [], + "source": [ + "from sklearn.neighbors import KNeighborsClassifier\n", + "classifier = KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p = 2)\n", + "classifier.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "yyxW5b395mR2" + }, + "source": [ + "## Predicting a new result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2351, + "status": "ok", + "timestamp": 1588492962263, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "f8YOXsQy58rP", + "outputId": "e248f6c5-4613-4a9e-faed-093c46defda1" + }, + "outputs": [], + "source": [ + "print(classifier.predict(sc.transform([[30,87000]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vKYVQH-l5NpE" + }, + "source": [ + "## Predicting the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2345, + "status": "ok", + "timestamp": 1588492962263, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "p6VMTb2O4hwM", + "outputId": "14b859cb-16df-4e5d-894b-3bda8e756d3d" + }, + "outputs": [], + "source": [ + "y_pred = classifier.predict(X_test)\n", + "print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h4Hwj34ziWQW" + }, + "source": [ + "## Making the Confusion Matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 3505, + "status": "ok", + "timestamp": 1588492963427, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "D6bpZwUiiXic", + "outputId": "ec9468d5-c478-4ffa-ba1c-535eb56d7304" + }, + "outputs": [], + "source": [ + "from sklearn.metrics import confusion_matrix, accuracy_score\n", + "cm = confusion_matrix(y_test, y_pred)\n", + "print(cm)\n", + "accuracy_score(y_test, y_pred)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6OMC_P0diaoD" + }, + "source": [ + "## Visualising the Training set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 208261, + "status": "ok", + "timestamp": 1588493168185, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "_NOjKvZRid5l", + "outputId": "f2568ce7-3491-47f3-9191-a1dc6f6eee79" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_train), y_train\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 1),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 1))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('K-NN (Training set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SZ-j28aPihZx" + }, + "source": [ + "## Visualising the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 412932, + "status": "ok", + "timestamp": 1588493372859, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qeTjz2vDilAC", + "outputId": "a5de62bf-6fc1-4109-8749-0386a57d28e9" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_test), y_test\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 1),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 1))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('K-NN (Test set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyO/71HmJztjHpR9Q3DXpRZQ", + "collapsed_sections": [], + "machine_shape": "hm", + "name": "k_nearest_neighbors.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Classification/Kernel SVM/kernel_svm.ipynb b/Classification/Kernel SVM/kernel_svm.ipynb new file mode 100644 index 0000000..d55f04e --- /dev/null +++ b/Classification/Kernel SVM/kernel_svm.ipynb @@ -0,0 +1,573 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0MRC0e0KhQ0S" + }, + "source": [ + "# Kernel SVM" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LWd1UlMnhT2s" + }, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YvGPUQaHhXfL" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "K1VMqkGvhc3-" + }, + "source": [ + "## Importing the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "M52QDmyzhh9s" + }, + "outputs": [], + "source": [ + "dataset = pd.read_csv('../../datasets/Social_Network_Ads.csv')\n", + "X = dataset.iloc[:, :-1].values\n", + "y = dataset.iloc[:, -1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YvxIPVyMhmKp" + }, + "source": [ + "## Splitting the dataset into the Training set and Test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AVzJWAXIhxoC" + }, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1501, + "status": "ok", + "timestamp": 1588268004246, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "P3nS3-6r1i2B", + "outputId": "000cce2c-0721-441e-d7b6-36a07ad0ed20" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1496, + "status": "ok", + "timestamp": 1588268004246, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "8dpDLojm1mVG", + "outputId": "f889b621-535f-4bbf-f476-eda5e4221313" + }, + "outputs": [], + "source": [ + "print(y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1492, + "status": "ok", + "timestamp": 1588268004246, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qbb7i0DH1qui", + "outputId": "a3f11154-8674-4902-ca81-e296d2a6fca9" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1489, + "status": "ok", + "timestamp": 1588268004247, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "kj1hnFAR1s5w", + "outputId": "f636a0fb-dc1f-43b6-eda0-3e0b4d2f6053" + }, + "outputs": [], + "source": [ + "print(y_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kW3c7UYih0hT" + }, + "source": [ + "## Feature Scaling" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9fQlDPKCh8sc" + }, + "outputs": [], + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "sc = StandardScaler()\n", + "X_train = sc.fit_transform(X_train)\n", + "X_test = sc.transform(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1875, + "status": "ok", + "timestamp": 1588268004638, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "syrnD1Op2BSR", + "outputId": "b7131b3c-5c78-43c3-cb0d-5bf76726b6fb" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1871, + "status": "ok", + "timestamp": 1588268004638, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "JUd6iBRp2C3L", + "outputId": "d5c1422d-0160-42ee-d242-7600b7897307" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bb6jCOCQiAmP" + }, + "source": [ + "## Training the Kernel SVM model on the Training set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 86 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1868, + "status": "ok", + "timestamp": 1588268004639, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "e0pFVAmciHQs", + "outputId": "4dcb0795-fcfa-4753-c3a4-13c10d43015a" + }, + "outputs": [], + "source": [ + "from sklearn.svm import SVC\n", + "classifier = SVC(kernel = 'rbf', random_state = 0)\n", + "classifier.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "yyxW5b395mR2" + }, + "source": [ + "## Predicting a new result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1864, + "status": "ok", + "timestamp": 1588268004639, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "f8YOXsQy58rP", + "outputId": "6525f27b-9adf-48a6-cea4-cb15972e928d" + }, + "outputs": [], + "source": [ + "print(classifier.predict(sc.transform([[30,87000]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vKYVQH-l5NpE" + }, + "source": [ + "## Predicting the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1861, + "status": "ok", + "timestamp": 1588268004640, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "p6VMTb2O4hwM", + "outputId": "ec76af11-3625-4b2a-c1da-3bd7e77e8ade" + }, + "outputs": [], + "source": [ + "y_pred = classifier.predict(X_test)\n", + "print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h4Hwj34ziWQW" + }, + "source": [ + "## Making the Confusion Matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1858, + "status": "ok", + "timestamp": 1588268004640, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "D6bpZwUiiXic", + "outputId": "964dd5af-7158-455f-eba2-c205e1f05a19" + }, + "outputs": [], + "source": [ + "from sklearn.metrics import confusion_matrix, accuracy_score\n", + "cm = confusion_matrix(y_test, y_pred)\n", + "print(cm)\n", + "accuracy_score(y_test, y_pred)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6OMC_P0diaoD" + }, + "source": [ + "## Visualising the Training set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 326556, + "status": "ok", + "timestamp": 1588268329342, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "_NOjKvZRid5l", + "outputId": "9c21c6b4-ac96-4683-972c-224c1a840993" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_train), y_train\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Kernel SVM (Training set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SZ-j28aPihZx" + }, + "source": [ + "## Visualising the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 647842, + "status": "ok", + "timestamp": 1588268650632, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qeTjz2vDilAC", + "outputId": "ef991d23-2b7f-4046-88f2-dbfc639d73cc" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_test), y_test\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Kernel SVM (Test set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMARUU4AeVdXSZH1V+VybNB", + "collapsed_sections": [], + "machine_shape": "hm", + "name": "kernel_svm.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Classification/Logistic_Regression/logistic_regression.ipynb b/Classification/Logistic_Regression/logistic_regression.ipynb new file mode 100644 index 0000000..12d5532 --- /dev/null +++ b/Classification/Logistic_Regression/logistic_regression.ipynb @@ -0,0 +1,573 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0MRC0e0KhQ0S" + }, + "source": [ + "# Logistic Regression" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LWd1UlMnhT2s" + }, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YvGPUQaHhXfL" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "K1VMqkGvhc3-" + }, + "source": [ + "## Importing the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "M52QDmyzhh9s" + }, + "outputs": [], + "source": [ + "dataset = pd.read_csv('../../datasets/Social_Network_Ads.csv')\n", + "X = dataset.iloc[:, :-1].values\n", + "y = dataset.iloc[:, -1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YvxIPVyMhmKp" + }, + "source": [ + "## Splitting the dataset into the Training set and Test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AVzJWAXIhxoC" + }, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2163, + "status": "ok", + "timestamp": 1588265315502, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "P3nS3-6r1i2B", + "outputId": "75d6e0cf-d13b-42cf-a353-888682415d37" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2158, + "status": "ok", + "timestamp": 1588265315502, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "8dpDLojm1mVG", + "outputId": "7ae11087-76ab-4027-c94e-9eb18f7573bf" + }, + "outputs": [], + "source": [ + "print(y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2154, + "status": "ok", + "timestamp": 1588265315503, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qbb7i0DH1qui", + "outputId": "94e717d7-fa9a-4e22-9c68-d43421cbfb92" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2149, + "status": "ok", + "timestamp": 1588265315503, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "kj1hnFAR1s5w", + "outputId": "ec9924c4-6d8a-4f20-dbf9-272fbaa24f92" + }, + "outputs": [], + "source": [ + "print(y_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kW3c7UYih0hT" + }, + "source": [ + "## Feature Scaling" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9fQlDPKCh8sc" + }, + "outputs": [], + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "sc = StandardScaler()\n", + "X_train = sc.fit_transform(X_train)\n", + "X_test = sc.transform(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2139, + "status": "ok", + "timestamp": 1588265315503, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "syrnD1Op2BSR", + "outputId": "711172c9-25a5-4c03-e835-6ab94766bdc0" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2133, + "status": "ok", + "timestamp": 1588265315504, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "JUd6iBRp2C3L", + "outputId": "3ed7b1f1-8fb7-48bc-8df8-39b6f65081ae" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bb6jCOCQiAmP" + }, + "source": [ + "## Training the Logistic Regression model on the Training set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 103 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2125, + "status": "ok", + "timestamp": 1588265315505, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "e0pFVAmciHQs", + "outputId": "67f64468-abdb-4fe7-cce9-de0037119610" + }, + "outputs": [], + "source": [ + "from sklearn.linear_model import LogisticRegression\n", + "classifier = LogisticRegression(random_state = 0)\n", + "classifier.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "yyxW5b395mR2" + }, + "source": [ + "## Predicting a new result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2118, + "status": "ok", + "timestamp": 1588265315505, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "f8YOXsQy58rP", + "outputId": "2e1b0063-548e-4924-cf3a-93a79d97e35e" + }, + "outputs": [], + "source": [ + "print(classifier.predict(sc.transform([[30,87000]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vKYVQH-l5NpE" + }, + "source": [ + "## Predicting the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2112, + "status": "ok", + "timestamp": 1588265315506, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "p6VMTb2O4hwM", + "outputId": "a4f03a97-2942-45cd-f735-f4063277a96c" + }, + "outputs": [], + "source": [ + "y_pred = classifier.predict(X_test)\n", + "print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h4Hwj34ziWQW" + }, + "source": [ + "## Making the Confusion Matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2107, + "status": "ok", + "timestamp": 1588265315506, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "D6bpZwUiiXic", + "outputId": "f202fcb3-5882-4d93-e5df-50791185067e" + }, + "outputs": [], + "source": [ + "from sklearn.metrics import confusion_matrix, accuracy_score\n", + "cm = confusion_matrix(y_test, y_pred)\n", + "print(cm)\n", + "accuracy_score(y_test, y_pred)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6OMC_P0diaoD" + }, + "source": [ + "## Visualising the Training set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 23189, + "status": "ok", + "timestamp": 1588265336596, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "_NOjKvZRid5l", + "outputId": "6fa60701-9aa4-46f2-a6aa-0f9b0aad62b3" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_train), y_train\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Logistic Regression (Training set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SZ-j28aPihZx" + }, + "source": [ + "## Visualising the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 43807, + "status": "ok", + "timestamp": 1588265357223, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qeTjz2vDilAC", + "outputId": "00fb10bc-c726-46b8-8eaa-c5c6b584aa54" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_test), y_test\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Logistic Regression (Test set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyOsvB/iqEjYj3VN6C/JbvkE", + "collapsed_sections": [], + "machine_shape": "hm", + "name": "logistic_regression.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Classification/Naive Bayes/naive_bayes.ipynb b/Classification/Naive Bayes/naive_bayes.ipynb new file mode 100644 index 0000000..4e42da6 --- /dev/null +++ b/Classification/Naive Bayes/naive_bayes.ipynb @@ -0,0 +1,573 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0MRC0e0KhQ0S" + }, + "source": [ + "# Naive Bayes" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LWd1UlMnhT2s" + }, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YvGPUQaHhXfL" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "K1VMqkGvhc3-" + }, + "source": [ + "## Importing the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "M52QDmyzhh9s" + }, + "outputs": [], + "source": [ + "dataset = pd.read_csv('../../datasets/Social_Network_Ads.csv')\n", + "X = dataset.iloc[:, :-1].values\n", + "y = dataset.iloc[:, -1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YvxIPVyMhmKp" + }, + "source": [ + "## Splitting the dataset into the Training set and Test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AVzJWAXIhxoC" + }, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2617, + "status": "ok", + "timestamp": 1588494217346, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "P3nS3-6r1i2B", + "outputId": "710f3089-a4d3-40a2-d361-f6706340cc51" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2612, + "status": "ok", + "timestamp": 1588494217346, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "8dpDLojm1mVG", + "outputId": "60265595-b47b-4ce6-ee29-2fdbfd8ee43d" + }, + "outputs": [], + "source": [ + "print(y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2607, + "status": "ok", + "timestamp": 1588494217347, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qbb7i0DH1qui", + "outputId": "9d4d1dfa-7acf-40aa-a77e-8c178dfa9aa3" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2601, + "status": "ok", + "timestamp": 1588494217347, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "kj1hnFAR1s5w", + "outputId": "c9bf748e-5c96-411d-d433-53b90fb38dad" + }, + "outputs": [], + "source": [ + "print(y_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kW3c7UYih0hT" + }, + "source": [ + "## Feature Scaling" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9fQlDPKCh8sc" + }, + "outputs": [], + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "sc = StandardScaler()\n", + "X_train = sc.fit_transform(X_train)\n", + "X_test = sc.transform(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2593, + "status": "ok", + "timestamp": 1588494217348, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "syrnD1Op2BSR", + "outputId": "8e650ae2-fe49-4673-800d-96f19058f2a9" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2588, + "status": "ok", + "timestamp": 1588494217348, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "JUd6iBRp2C3L", + "outputId": "479a69bf-8358-42ab-eaa5-990b6da228b2" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bb6jCOCQiAmP" + }, + "source": [ + "## Training the Naive Bayes model on the Training set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2587, + "status": "ok", + "timestamp": 1588494217349, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "e0pFVAmciHQs", + "outputId": "6882b5ab-26fa-43c5-f9b8-5b117b2dc0b5" + }, + "outputs": [], + "source": [ + "from sklearn.naive_bayes import GaussianNB\n", + "classifier = GaussianNB()\n", + "classifier.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "yyxW5b395mR2" + }, + "source": [ + "## Predicting a new result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2582, + "status": "ok", + "timestamp": 1588494217349, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "f8YOXsQy58rP", + "outputId": "f813965b-988a-4e20-a410-9d5a9c45abc2" + }, + "outputs": [], + "source": [ + "print(classifier.predict(sc.transform([[30,87000]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vKYVQH-l5NpE" + }, + "source": [ + "## Predicting the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2576, + "status": "ok", + "timestamp": 1588494217349, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "p6VMTb2O4hwM", + "outputId": "521c30be-051f-4309-f285-5db338f3c038" + }, + "outputs": [], + "source": [ + "y_pred = classifier.predict(X_test)\n", + "print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h4Hwj34ziWQW" + }, + "source": [ + "## Making the Confusion Matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 2571, + "status": "ok", + "timestamp": 1588494217350, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "D6bpZwUiiXic", + "outputId": "9296fb4c-4d60-4d7a-b04e-35e9fa018321" + }, + "outputs": [], + "source": [ + "from sklearn.metrics import confusion_matrix, accuracy_score\n", + "cm = confusion_matrix(y_test, y_pred)\n", + "print(cm)\n", + "accuracy_score(y_test, y_pred)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6OMC_P0diaoD" + }, + "source": [ + "## Visualising the Training set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 31219, + "status": "ok", + "timestamp": 1588494246003, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "_NOjKvZRid5l", + "outputId": "49f360d2-ab7c-45c2-9795-a9600b24d63b" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_train), y_train\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Naive Bayes (Training set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SZ-j28aPihZx" + }, + "source": [ + "## Visualising the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 56235, + "status": "ok", + "timestamp": 1588494271024, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qeTjz2vDilAC", + "outputId": "a7993e85-a23c-4c51-95c7-979c42039fd5" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_test), y_test\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Naive Bayes (Test set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMskY9N5l+KivrHgi4T7yWW", + "collapsed_sections": [], + "machine_shape": "hm", + "name": "naive_bayes.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Classification/Random Forest Classification/random_forest_classification.ipynb b/Classification/Random Forest Classification/random_forest_classification.ipynb new file mode 100644 index 0000000..28286d2 --- /dev/null +++ b/Classification/Random Forest Classification/random_forest_classification.ipynb @@ -0,0 +1,573 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0MRC0e0KhQ0S" + }, + "source": [ + "# Random Forest Classification" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LWd1UlMnhT2s" + }, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YvGPUQaHhXfL" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "K1VMqkGvhc3-" + }, + "source": [ + "## Importing the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "M52QDmyzhh9s" + }, + "outputs": [], + "source": [ + "dataset = pd.read_csv('../../datasets/Social_Network_Ads.csv')\n", + "X = dataset.iloc[:, :-1].values\n", + "y = dataset.iloc[:, -1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YvxIPVyMhmKp" + }, + "source": [ + "## Splitting the dataset into the Training set and Test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AVzJWAXIhxoC" + }, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1300, + "status": "ok", + "timestamp": 1588269343329, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "P3nS3-6r1i2B", + "outputId": "e4a38929-7ac1-4895-a070-4f241ad247c0" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1294, + "status": "ok", + "timestamp": 1588269343330, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "8dpDLojm1mVG", + "outputId": "2a9b0425-9e6d-480f-b32a-ebae6f413dbe" + }, + "outputs": [], + "source": [ + "print(y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1613, + "status": "ok", + "timestamp": 1588269343657, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qbb7i0DH1qui", + "outputId": "b10e7737-ae02-4c0c-b49f-8d961e2921b4" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1608, + "status": "ok", + "timestamp": 1588269343658, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "kj1hnFAR1s5w", + "outputId": "1f3a92ea-9844-4d4c-ca5f-075fa4ba98e0" + }, + "outputs": [], + "source": [ + "print(y_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kW3c7UYih0hT" + }, + "source": [ + "## Feature Scaling" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9fQlDPKCh8sc" + }, + "outputs": [], + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "sc = StandardScaler()\n", + "X_train = sc.fit_transform(X_train)\n", + "X_test = sc.transform(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1600, + "status": "ok", + "timestamp": 1588269343659, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "syrnD1Op2BSR", + "outputId": "b1fa2925-b7de-4530-b015-01bb51e742b4" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1595, + "status": "ok", + "timestamp": 1588269343659, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "JUd6iBRp2C3L", + "outputId": "48320ca4-33e0-4bfe-92ba-91c06bcf714e" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bb6jCOCQiAmP" + }, + "source": [ + "## Training the Random Forest Classification model on the Training set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 154 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1589, + "status": "ok", + "timestamp": 1588269343659, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "e0pFVAmciHQs", + "outputId": "79719013-2ffa-49f6-b49c-886d9ba19525" + }, + "outputs": [], + "source": [ + "from sklearn.ensemble import RandomForestClassifier\n", + "classifier = RandomForestClassifier(n_estimators = 10, criterion = 'entropy', random_state = 0)\n", + "classifier.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "yyxW5b395mR2" + }, + "source": [ + "## Predicting a new result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1584, + "status": "ok", + "timestamp": 1588269343660, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "f8YOXsQy58rP", + "outputId": "81727e50-9f85-49ad-a41e-5891aa34e6bb" + }, + "outputs": [], + "source": [ + "print(classifier.predict(sc.transform([[30,87000]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vKYVQH-l5NpE" + }, + "source": [ + "## Predicting the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1578, + "status": "ok", + "timestamp": 1588269343660, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "p6VMTb2O4hwM", + "outputId": "f160d9d3-e4cd-4484-db9d-99028dfed42d" + }, + "outputs": [], + "source": [ + "y_pred = classifier.predict(X_test)\n", + "print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h4Hwj34ziWQW" + }, + "source": [ + "## Making the Confusion Matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1898, + "status": "ok", + "timestamp": 1588269343985, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "D6bpZwUiiXic", + "outputId": "b4ab126b-4118-461e-f02a-cfe538ae6a71" + }, + "outputs": [], + "source": [ + "from sklearn.metrics import confusion_matrix, accuracy_score\n", + "cm = confusion_matrix(y_test, y_pred)\n", + "print(cm)\n", + "accuracy_score(y_test, y_pred)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6OMC_P0diaoD" + }, + "source": [ + "## Visualising the Training set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 87793, + "status": "ok", + "timestamp": 1588269429885, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "_NOjKvZRid5l", + "outputId": "7efb744e-3ecb-4303-8543-8fabf49f64bc" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_train), y_train\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Random Forest Classification (Training set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SZ-j28aPihZx" + }, + "source": [ + "## Visualising the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 172477, + "status": "ok", + "timestamp": 1588269514574, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qeTjz2vDilAC", + "outputId": "f1a33b1a-e8b6-4b3e-e98a-a0c7c66fed56" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_test), y_test\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('Random Forest Classification (Test set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyPA7K2PAkEFgaKFIvslUMEc", + "collapsed_sections": [], + "machine_shape": "hm", + "name": "random_forest_classification.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Classification/Support Vector Machine/support_vector_machine.ipynb b/Classification/Support Vector Machine/support_vector_machine.ipynb new file mode 100644 index 0000000..4f4f791 --- /dev/null +++ b/Classification/Support Vector Machine/support_vector_machine.ipynb @@ -0,0 +1,573 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0MRC0e0KhQ0S" + }, + "source": [ + "# Support Vector Machine (SVM)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "LWd1UlMnhT2s" + }, + "source": [ + "## Importing the libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YvGPUQaHhXfL" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "K1VMqkGvhc3-" + }, + "source": [ + "## Importing the dataset" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "M52QDmyzhh9s" + }, + "outputs": [], + "source": [ + "dataset = pd.read_csv('../../datasets/Social_Network_Ads.csv')\n", + "X = dataset.iloc[:, :-1].values\n", + "y = dataset.iloc[:, -1].values" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "YvxIPVyMhmKp" + }, + "source": [ + "## Splitting the dataset into the Training set and Test set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AVzJWAXIhxoC" + }, + "outputs": [], + "source": [ + "from sklearn.model_selection import train_test_split\n", + "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1137, + "status": "ok", + "timestamp": 1588267335709, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "P3nS3-6r1i2B", + "outputId": "c9d82a73-9c13-4cac-e5f2-a7c7803f1819" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 171 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1133, + "status": "ok", + "timestamp": 1588267335710, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "8dpDLojm1mVG", + "outputId": "a3d03ccc-37c0-40b8-92c7-232abd3240a7" + }, + "outputs": [], + "source": [ + "print(y_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1128, + "status": "ok", + "timestamp": 1588267335710, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qbb7i0DH1qui", + "outputId": "ae89dad9-0dfb-4612-f88a-828fb9f95836" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1591, + "status": "ok", + "timestamp": 1588267336179, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "kj1hnFAR1s5w", + "outputId": "948c3b43-2282-400f-9f0e-e9f397b65047" + }, + "outputs": [], + "source": [ + "print(y_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kW3c7UYih0hT" + }, + "source": [ + "## Feature Scaling" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9fQlDPKCh8sc" + }, + "outputs": [], + "source": [ + "from sklearn.preprocessing import StandardScaler\n", + "sc = StandardScaler()\n", + "X_train = sc.fit_transform(X_train)\n", + "X_test = sc.transform(X_test)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1585, + "status": "ok", + "timestamp": 1588267336180, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "syrnD1Op2BSR", + "outputId": "cd5ad357-7763-4894-d894-76fbe781fcd8" + }, + "outputs": [], + "source": [ + "print(X_train)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1579, + "status": "ok", + "timestamp": 1588267336180, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "JUd6iBRp2C3L", + "outputId": "6661e6f4-9c33-42af-d9c7-ca552603de1e" + }, + "outputs": [], + "source": [ + "print(X_test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bb6jCOCQiAmP" + }, + "source": [ + "## Training the SVM model on the Training set" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 86 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1578, + "status": "ok", + "timestamp": 1588267336181, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "e0pFVAmciHQs", + "outputId": "2456d6a2-0437-42b3-fbe1-e75a23b26148" + }, + "outputs": [], + "source": [ + "from sklearn.svm import SVC\n", + "classifier = SVC(kernel = 'linear', random_state = 0)\n", + "classifier.fit(X_train, y_train)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "yyxW5b395mR2" + }, + "source": [ + "## Predicting a new result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1573, + "status": "ok", + "timestamp": 1588267336181, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "f8YOXsQy58rP", + "outputId": "46dd75b3-1359-4f2a-8978-5ea65c8a52e9" + }, + "outputs": [], + "source": [ + "print(classifier.predict(sc.transform([[30,87000]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vKYVQH-l5NpE" + }, + "source": [ + "## Predicting the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1569, + "status": "ok", + "timestamp": 1588267336182, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "p6VMTb2O4hwM", + "outputId": "3621a714-16d0-4c4a-dfc1-ae223f3cfc1d" + }, + "outputs": [], + "source": [ + "y_pred = classifier.predict(X_test)\n", + "print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h4Hwj34ziWQW" + }, + "source": [ + "## Making the Confusion Matrix" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1563, + "status": "ok", + "timestamp": 1588267336182, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "D6bpZwUiiXic", + "outputId": "f72110a8-b97b-43e8-9adf-14673886ccab" + }, + "outputs": [], + "source": [ + "from sklearn.metrics import confusion_matrix, accuracy_score\n", + "cm = confusion_matrix(y_test, y_pred)\n", + "print(cm)\n", + "accuracy_score(y_test, y_pred)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6OMC_P0diaoD" + }, + "source": [ + "## Visualising the Training set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 155558, + "status": "ok", + "timestamp": 1588267490181, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "_NOjKvZRid5l", + "outputId": "ac9cc7c4-d0db-4fb1-bca7-779ff68cbfd4" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_train), y_train\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('SVM (Training set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "SZ-j28aPihZx" + }, + "source": [ + "## Visualising the Test set results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 349 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 307655, + "status": "ok", + "timestamp": 1588267642283, + "user": { + "displayName": "Hadelin de Ponteves", + "photoUrl": "https://lh3.googleusercontent.com/a-/AOh14GhEuXdT7eQweUmRPW8_laJuPggSK6hfvpl5a6WBaA=s64", + "userId": "15047218817161520419" + }, + "user_tz": -240 + }, + "id": "qeTjz2vDilAC", + "outputId": "08413d38-f94b-4100-bfc3-19c1b5d5efe4" + }, + "outputs": [], + "source": [ + "from matplotlib.colors import ListedColormap\n", + "X_set, y_set = sc.inverse_transform(X_test), y_test\n", + "X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),\n", + " np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))\n", + "plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),\n", + " alpha = 0.75, cmap = ListedColormap(('red', 'green')))\n", + "plt.xlim(X1.min(), X1.max())\n", + "plt.ylim(X2.min(), X2.max())\n", + "for i, j in enumerate(np.unique(y_set)):\n", + " plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)\n", + "plt.title('SVM (Test set)')\n", + "plt.xlabel('Age')\n", + "plt.ylabel('Estimated Salary')\n", + "plt.legend()\n", + "plt.show()" + ] + } + ], + "metadata": { + "colab": { + "authorship_tag": "ABX9TyMH6PiqxoH4J/SZjlaPzxhf", + "collapsed_sections": [], + "machine_shape": "hm", + "name": "support_vector_machine.ipynb", + "provenance": [], + "toc_visible": true + }, + "kernelspec": { + "display_name": "Python 3", + "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.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/datasets/Social_Network_Ads.csv b/datasets/Social_Network_Ads.csv new file mode 100644 index 0000000..38819f0 --- /dev/null +++ b/datasets/Social_Network_Ads.csv @@ -0,0 +1,401 @@ +Age,EstimatedSalary,Purchased +19,19000,0 +35,20000,0 +26,43000,0 +27,57000,0 +19,76000,0 +27,58000,0 +27,84000,0 +32,150000,1 +25,33000,0 +35,65000,0 +26,80000,0 +26,52000,0 +20,86000,0 +32,18000,0 +18,82000,0 +29,80000,0 +47,25000,1 +45,26000,1 +46,28000,1 +48,29000,1 +45,22000,1 +47,49000,1 +48,41000,1 +45,22000,1 +46,23000,1 +47,20000,1 +49,28000,1 +47,30000,1 +29,43000,0 +31,18000,0 +31,74000,0 +27,137000,1 +21,16000,0 +28,44000,0 +27,90000,0 +35,27000,0 +33,28000,0 +30,49000,0 +26,72000,0 +27,31000,0 +27,17000,0 +33,51000,0 +35,108000,0 +30,15000,0 +28,84000,0 +23,20000,0 +25,79000,0 +27,54000,0 +30,135000,1 +31,89000,0 +24,32000,0 +18,44000,0 +29,83000,0 +35,23000,0 +27,58000,0 +24,55000,0 +23,48000,0 +28,79000,0 +22,18000,0 +32,117000,0 +27,20000,0 +25,87000,0 +23,66000,0 +32,120000,1 +59,83000,0 +24,58000,0 +24,19000,0 +23,82000,0 +22,63000,0 +31,68000,0 +25,80000,0 +24,27000,0 +20,23000,0 +33,113000,0 +32,18000,0 +34,112000,1 +18,52000,0 +22,27000,0 +28,87000,0 +26,17000,0 +30,80000,0 +39,42000,0 +20,49000,0 +35,88000,0 +30,62000,0 +31,118000,1 +24,55000,0 +28,85000,0 +26,81000,0 +35,50000,0 +22,81000,0 +30,116000,0 +26,15000,0 +29,28000,0 +29,83000,0 +35,44000,0 +35,25000,0 +28,123000,1 +35,73000,0 +28,37000,0 +27,88000,0 +28,59000,0 +32,86000,0 +33,149000,1 +19,21000,0 +21,72000,0 +26,35000,0 +27,89000,0 +26,86000,0 +38,80000,0 +39,71000,0 +37,71000,0 +38,61000,0 +37,55000,0 +42,80000,0 +40,57000,0 +35,75000,0 +36,52000,0 +40,59000,0 +41,59000,0 +36,75000,0 +37,72000,0 +40,75000,0 +35,53000,0 +41,51000,0 +39,61000,0 +42,65000,0 +26,32000,0 +30,17000,0 +26,84000,0 +31,58000,0 +33,31000,0 +30,87000,0 +21,68000,0 +28,55000,0 +23,63000,0 +20,82000,0 +30,107000,1 +28,59000,0 +19,25000,0 +19,85000,0 +18,68000,0 +35,59000,0 +30,89000,0 +34,25000,0 +24,89000,0 +27,96000,1 +41,30000,0 +29,61000,0 +20,74000,0 +26,15000,0 +41,45000,0 +31,76000,0 +36,50000,0 +40,47000,0 +31,15000,0 +46,59000,0 +29,75000,0 +26,30000,0 +32,135000,1 +32,100000,1 +25,90000,0 +37,33000,0 +35,38000,0 +33,69000,0 +18,86000,0 +22,55000,0 +35,71000,0 +29,148000,1 +29,47000,0 +21,88000,0 +34,115000,0 +26,118000,0 +34,43000,0 +34,72000,0 +23,28000,0 +35,47000,0 +25,22000,0 +24,23000,0 +31,34000,0 +26,16000,0 +31,71000,0 +32,117000,1 +33,43000,0 +33,60000,0 +31,66000,0 +20,82000,0 +33,41000,0 +35,72000,0 +28,32000,0 +24,84000,0 +19,26000,0 +29,43000,0 +19,70000,0 +28,89000,0 +34,43000,0 +30,79000,0 +20,36000,0 +26,80000,0 +35,22000,0 +35,39000,0 +49,74000,0 +39,134000,1 +41,71000,0 +58,101000,1 +47,47000,0 +55,130000,1 +52,114000,0 +40,142000,1 +46,22000,0 +48,96000,1 +52,150000,1 +59,42000,0 +35,58000,0 +47,43000,0 +60,108000,1 +49,65000,0 +40,78000,0 +46,96000,0 +59,143000,1 +41,80000,0 +35,91000,1 +37,144000,1 +60,102000,1 +35,60000,0 +37,53000,0 +36,126000,1 +56,133000,1 +40,72000,0 +42,80000,1 +35,147000,1 +39,42000,0 +40,107000,1 +49,86000,1 +38,112000,0 +46,79000,1 +40,57000,0 +37,80000,0 +46,82000,0 +53,143000,1 +42,149000,1 +38,59000,0 +50,88000,1 +56,104000,1 +41,72000,0 +51,146000,1 +35,50000,0 +57,122000,1 +41,52000,0 +35,97000,1 +44,39000,0 +37,52000,0 +48,134000,1 +37,146000,1 +50,44000,0 +52,90000,1 +41,72000,0 +40,57000,0 +58,95000,1 +45,131000,1 +35,77000,0 +36,144000,1 +55,125000,1 +35,72000,0 +48,90000,1 +42,108000,1 +40,75000,0 +37,74000,0 +47,144000,1 +40,61000,0 +43,133000,0 +59,76000,1 +60,42000,1 +39,106000,1 +57,26000,1 +57,74000,1 +38,71000,0 +49,88000,1 +52,38000,1 +50,36000,1 +59,88000,1 +35,61000,0 +37,70000,1 +52,21000,1 +48,141000,0 +37,93000,1 +37,62000,0 +48,138000,1 +41,79000,0 +37,78000,1 +39,134000,1 +49,89000,1 +55,39000,1 +37,77000,0 +35,57000,0 +36,63000,0 +42,73000,1 +43,112000,1 +45,79000,0 +46,117000,1 +58,38000,1 +48,74000,1 +37,137000,1 +37,79000,1 +40,60000,0 +42,54000,0 +51,134000,0 +47,113000,1 +36,125000,1 +38,50000,0 +42,70000,0 +39,96000,1 +38,50000,0 +49,141000,1 +39,79000,0 +39,75000,1 +54,104000,1 +35,55000,0 +45,32000,1 +36,60000,0 +52,138000,1 +53,82000,1 +41,52000,0 +48,30000,1 +48,131000,1 +41,60000,0 +41,72000,0 +42,75000,0 +36,118000,1 +47,107000,1 +38,51000,0 +48,119000,1 +42,65000,0 +40,65000,0 +57,60000,1 +36,54000,0 +58,144000,1 +35,79000,0 +38,55000,0 +39,122000,1 +53,104000,1 +35,75000,0 +38,65000,0 +47,51000,1 +47,105000,1 +41,63000,0 +53,72000,1 +54,108000,1 +39,77000,0 +38,61000,0 +38,113000,1 +37,75000,0 +42,90000,1 +37,57000,0 +36,99000,1 +60,34000,1 +54,70000,1 +41,72000,0 +40,71000,1 +42,54000,0 +43,129000,1 +53,34000,1 +47,50000,1 +42,79000,0 +42,104000,1 +59,29000,1 +58,47000,1 +46,88000,1 +38,71000,0 +54,26000,1 +60,46000,1 +60,83000,1 +39,73000,0 +59,130000,1 +37,80000,0 +46,32000,1 +46,74000,0 +42,53000,0 +41,87000,1 +58,23000,1 +42,64000,0 +48,33000,1 +44,139000,1 +49,28000,1 +57,33000,1 +56,60000,1 +49,39000,1 +39,71000,0 +47,34000,1 +48,35000,1 +48,33000,1 +47,23000,1 +45,45000,1 +60,42000,1 +39,59000,0 +46,41000,1 +51,23000,1 +50,20000,1 +36,33000,0 +49,36000,1 \ No newline at end of file