diff --git a/Text_20Classification_20Keras.ipynb b/Text_20Classification_20Keras.ipynb new file mode 100644 index 0000000..3523ad5 --- /dev/null +++ b/Text_20Classification_20Keras.ipynb @@ -0,0 +1,988 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Text%20Classification%20Keras.ipynb", + "version": "0.3.2", + "provenance": [] + }, + "kernelspec": { + "name": "python2", + "display_name": "Python 2" + }, + "accelerator": "GPU" + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "[View in Colaboratory](https://colab.research.google.com/github/dhanaji/Machine-Learning-with-Python/blob/master/Text_20Classification_20Keras.ipynb)" + ] + }, + { + "metadata": { + "id": "pD1O9N7CB2e3", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "c4eeeb46-ad0f-4083-d015-0c2c23a1153f" + }, + "cell_type": "code", + "source": [ + "from __future__ import absolute_import\n", + "from __future__ import division\n", + "from __future__ import print_function" + ], + "execution_count": 1, + "outputs": [] + }, + { + "metadata": { + "id": "DVejgpQuB2fA", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 52 + }, + "outputId": "06a92fef-1c3b-4735-f40a-33d97db1f1ee" + }, + "cell_type": "code", + "source": [ + "import itertools\n", + "import os\n", + "\n", + "%matplotlib inline\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", + "import tensorflow as tf\n", + "\n", + "from sklearn.preprocessing import LabelBinarizer, LabelEncoder\n", + "from sklearn.metrics import confusion_matrix\n", + "\n", + "from tensorflow import keras\n", + "from keras.models import Sequential\n", + "from keras.layers import Dense, Activation, Dropout\n", + "from keras.preprocessing import text, sequence\n", + "from keras import utils\n", + "\n", + "# This code was tested with TensorFlow v1.4\n", + "print(\"You have TensorFlow version\", tf.__version__)" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "You have TensorFlow version 1.8.0\n" + ], + "name": "stdout" + }, + { + "output_type": "stream", + "text": [ + "Using TensorFlow backend.\n" + ], + "name": "stderr" + } + ] + }, + { + "metadata": { + "id": "8AqFhj7RDEZt", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "e87b4567-2fa2-4769-cb07-d75c9ee3e06e" + }, + "cell_type": "code", + "source": [ + "import urllib\n", + "urllib.urlretrieve('https://data.consumerfinance.gov/api/views/s6ew-h6mp/rows.csv?accessType=DOWNLOAD','Consumer_Complaints.csv')" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "('Consumer_Complaints.csv', )" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 3 + } + ] + }, + { + "metadata": { + "id": "kvxHRvZTB2fG", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 569 + }, + "outputId": "946f6088-ce1a-4a26-acb7-07368700ab46" + }, + "cell_type": "code", + "source": [ + "df = pd.read_csv('Consumer_Complaints.csv', encoding='latin-1')\n", + "df.head()" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Date receivedProductSub-productIssueSub-issueConsumer complaint narrativeCompany public responseCompanyStateZIP codeTagsConsumer consent provided?Submitted viaDate sent to companyCompany response to consumerTimely response?Consumer disputed?Complaint ID
003/12/2014MortgageOther mortgageLoan modification,collection,foreclosureNaNNaNNaNM&T BANK CORPORATIONMI48382NaNNaNReferral03/17/2014Closed with explanationYesNo759217
110/01/2016Credit reportingNaNIncorrect information on credit reportAccount statusI have outdated information on my credit repor...Company has responded to the consumer and the ...TRANSUNION INTERMEDIATE HOLDINGS, INC.AL352XXNaNConsent providedWeb10/05/2016Closed with explanationYesNo2141773
210/17/2016Consumer LoanVehicle loanManaging the loan or leaseNaNI purchased a new car on XXXX XXXX. The car de...NaNCITIZENS FINANCIAL GROUP, INC.PA177XXOlder AmericanConsent providedWeb10/20/2016Closed with explanationYesNo2163100
306/08/2014Credit cardNaNBankruptcyNaNNaNNaNAMERICAN EXPRESS COMPANYID83854Older AmericanNaNWeb06/10/2014Closed with explanationYesYes885638
409/13/2014Debt collectionCredit cardCommunication tacticsFrequent or repeated callsNaNNaNCITIBANK, N.A.VA23233NaNNaNWeb09/13/2014Closed with explanationYesYes1027760
\n", + "
" + ], + "text/plain": [ + " Date received Product Sub-product \\\n", + "0 03/12/2014 Mortgage Other mortgage \n", + "1 10/01/2016 Credit reporting NaN \n", + "2 10/17/2016 Consumer Loan Vehicle loan \n", + "3 06/08/2014 Credit card NaN \n", + "4 09/13/2014 Debt collection Credit card \n", + "\n", + " Issue Sub-issue \\\n", + "0 Loan modification,collection,foreclosure NaN \n", + "1 Incorrect information on credit report Account status \n", + "2 Managing the loan or lease NaN \n", + "3 Bankruptcy NaN \n", + "4 Communication tactics Frequent or repeated calls \n", + "\n", + " Consumer complaint narrative \\\n", + "0 NaN \n", + "1 I have outdated information on my credit repor... \n", + "2 I purchased a new car on XXXX XXXX. The car de... \n", + "3 NaN \n", + "4 NaN \n", + "\n", + " Company public response \\\n", + "0 NaN \n", + "1 Company has responded to the consumer and the ... \n", + "2 NaN \n", + "3 NaN \n", + "4 NaN \n", + "\n", + " Company State ZIP code Tags \\\n", + "0 M&T BANK CORPORATION MI 48382 NaN \n", + "1 TRANSUNION INTERMEDIATE HOLDINGS, INC. AL 352XX NaN \n", + "2 CITIZENS FINANCIAL GROUP, INC. PA 177XX Older American \n", + "3 AMERICAN EXPRESS COMPANY ID 83854 Older American \n", + "4 CITIBANK, N.A. VA 23233 NaN \n", + "\n", + " Consumer consent provided? Submitted via Date sent to company \\\n", + "0 NaN Referral 03/17/2014 \n", + "1 Consent provided Web 10/05/2016 \n", + "2 Consent provided Web 10/20/2016 \n", + "3 NaN Web 06/10/2014 \n", + "4 NaN Web 09/13/2014 \n", + "\n", + " Company response to consumer Timely response? Consumer disputed? \\\n", + "0 Closed with explanation Yes No \n", + "1 Closed with explanation Yes No \n", + "2 Closed with explanation Yes No \n", + "3 Closed with explanation Yes Yes \n", + "4 Closed with explanation Yes Yes \n", + "\n", + " Complaint ID \n", + "0 759217 \n", + "1 2141773 \n", + "2 2163100 \n", + "3 885638 \n", + "4 1027760 " + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 5 + } + ] + }, + { + "metadata": { + "id": "mj-jNbabB2fR", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 202 + }, + "outputId": "40f5a29f-b3a7-48d1-cd2d-e83ead585a93" + }, + "cell_type": "code", + "source": [ + "col = ['Consumer complaint narrative', 'Product']\n", + "df = df[col]\n", + "df = df[pd.notnull(df['Consumer complaint narrative'])]\n", + "df.head()" + ], + "execution_count": 6, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Consumer complaint narrativeProduct
1I have outdated information on my credit repor...Credit reporting
2I purchased a new car on XXXX XXXX. The car de...Consumer Loan
7An account on my credit report has a mistaken ...Credit reporting
12This company refuses to provide me verificatio...Debt collection
16This complaint is in regards to Square Two Fin...Debt collection
\n", + "
" + ], + "text/plain": [ + " Consumer complaint narrative Product\n", + "1 I have outdated information on my credit repor... Credit reporting\n", + "2 I purchased a new car on XXXX XXXX. The car de... Consumer Loan\n", + "7 An account on my credit report has a mistaken ... Credit reporting\n", + "12 This company refuses to provide me verificatio... Debt collection\n", + "16 This complaint is in regards to Square Two Fin... Debt collection" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 6 + } + ] + }, + { + "metadata": { + "id": "9MMR-qn6B2fW", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 69 + }, + "outputId": "6fe537cd-3ed7-43d4-96ae-d6a31f9a2658" + }, + "cell_type": "code", + "source": [ + "df.isnull().sum()" + ], + "execution_count": 7, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "Consumer complaint narrative 0\n", + "Product 0\n", + "dtype: int64" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 7 + } + ] + }, + { + "metadata": { + "id": "9B98hydvB2fe", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 347 + }, + "outputId": "3ddfabae-4b03-4ea4-a0ee-2aa6c1cdbe47" + }, + "cell_type": "code", + "source": [ + "df['Product'].value_counts()" + ], + "execution_count": 8, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "Debt collection 65791\n", + "Credit reporting, credit repair services, or other personal consumer reports 53057\n", + "Mortgage 44793\n", + "Credit reporting 31593\n", + "Credit card 18842\n", + "Student loan 17167\n", + "Bank account or service 14887\n", + "Credit card or prepaid card 11736\n", + "Consumer Loan 9474\n", + "Checking or savings account 7071\n", + "Money transfer, virtual currency, or money service 3393\n", + "Vehicle loan or lease 3055\n", + "Payday loan, title loan, or personal loan 2364\n", + "Payday loan 1748\n", + "Money transfers 1497\n", + "Prepaid card 1450\n", + "Other financial service 293\n", + "Virtual currency 16\n", + "Name: Product, dtype: int64" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 8 + } + ] + }, + { + "metadata": { + "id": "ss7XpBvTB2fl", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 52 + }, + "outputId": "b8f5b73c-19ca-4dab-a114-722d44d270b4" + }, + "cell_type": "code", + "source": [ + "# Split data into train and test\n", + "train_size = int(len(df) * .8)\n", + "print (\"Train size: %d\" % train_size)\n", + "print (\"Test size: %d\" % (len(df) - train_size))" + ], + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Train size: 230581\n", + "Test size: 57646\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "3cYjZ3p-B2fy", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "466ae873-9521-4692-cf7f-6f2592271969" + }, + "cell_type": "code", + "source": [ + "train_narrative = df['Consumer complaint narrative'][:train_size]\n", + "train_product = df['Product'][:train_size]\n", + "\n", + "test_narrative = df['Consumer complaint narrative'][train_size:]\n", + "test_product = df['Product'][train_size:]" + ], + "execution_count": 10, + "outputs": [] + }, + { + "metadata": { + "id": "sb4Bg6BbB2f1", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "0dc0188d-512b-476d-a1cd-ed3e7360ca11" + }, + "cell_type": "code", + "source": [ + "max_words = 1000\n", + "tokenize = text.Tokenizer(num_words=max_words, char_level=False)" + ], + "execution_count": 11, + "outputs": [] + }, + { + "metadata": { + "id": "3eqwUcmXB2f5", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "de56fcda-c284-4da2-ba06-3acee4813a37" + }, + "cell_type": "code", + "source": [ + "tokenize.fit_on_texts(train_narrative) # only fit on train\n", + "x_train = tokenize.texts_to_matrix(train_narrative)\n", + "x_test = tokenize.texts_to_matrix(test_narrative)" + ], + "execution_count": 12, + "outputs": [] + }, + { + "metadata": { + "id": "QzaHxikbB2gC", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "92c6c947-9ddd-4a58-afa3-07c2cccabf61" + }, + "cell_type": "code", + "source": [ + "# Use sklearn utility to convert label strings to numbered index\n", + "encoder = LabelEncoder()\n", + "encoder.fit(train_product)\n", + "y_train = encoder.transform(train_product)\n", + "y_test = encoder.transform(test_product)" + ], + "execution_count": 13, + "outputs": [] + }, + { + "metadata": { + "id": "dN_Qs6HUB2gK", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "f5ef1288-9c9c-4303-d1c1-1ee75c64dfc3" + }, + "cell_type": "code", + "source": [ + "# Converts the labels to a one-hot representation\n", + "num_classes = np.max(y_train) + 1\n", + "y_train = utils.to_categorical(y_train, num_classes)\n", + "y_test = utils.to_categorical(y_test, num_classes)" + ], + "execution_count": 14, + "outputs": [] + }, + { + "metadata": { + "id": "XRAMqEAAB2gc", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 87 + }, + "outputId": "f0fb7d3e-0fea-4c12-a584-42893770a91c" + }, + "cell_type": "code", + "source": [ + "# Inspect the dimenstions of our training and test data (this is helpful to debug)\n", + "print('x_train shape:', x_train.shape)\n", + "print('x_test shape:', x_test.shape)\n", + "print('y_train shape:', y_train.shape)\n", + "print('y_test shape:', y_test.shape)" + ], + "execution_count": 15, + "outputs": [ + { + "output_type": "stream", + "text": [ + "x_train shape: (230581, 1000)\n", + "x_test shape: (57646, 1000)\n", + "y_train shape: (230581, 18)\n", + "y_test shape: (57646, 18)\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "ECYbwchaB2ht", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "8f347281-96ad-4697-fff4-fa6b699b0bcd" + }, + "cell_type": "code", + "source": [ + "batch_size = 32\n", + "epochs = 5" + ], + "execution_count": 16, + "outputs": [] + }, + { + "metadata": { + "id": "Z2fOdYVvB2h6", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 17 + }, + "outputId": "6b8b86af-aabe-48d3-bb16-0eb7ca50c314" + }, + "cell_type": "code", + "source": [ + "# Build the model\n", + "model = Sequential()\n", + "model.add(Dense(512, input_shape=(max_words,)))\n", + "model.add(Activation('relu'))\n", + "model.add(Dropout(0.5))\n", + "model.add(Dense(num_classes))\n", + "model.add(Activation('softmax'))\n", + "\n", + "model.compile(loss='categorical_crossentropy',\n", + " optimizer='adam',\n", + " metrics=['accuracy'])" + ], + "execution_count": 17, + "outputs": [] + }, + { + "metadata": { + "id": "gvN0sNoLB2iQ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 228 + }, + "outputId": "b31b7c80-818d-4529-f23c-fa89c6c1631e" + }, + "cell_type": "code", + "source": [ + "history = model.fit(x_train, y_train,\n", + " batch_size=batch_size,\n", + " epochs=epochs,\n", + " verbose=1,\n", + " validation_split=0.1)" + ], + "execution_count": 18, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Train on 207522 samples, validate on 23059 samples\n", + "Epoch 1/5\n", + "161248/207522 [======================>.......] - ETA: 10s - loss: 0.9025 - acc: 0.7139" + ], + "name": "stdout" + }, + { + "output_type": "stream", + "text": [ + "207522/207522 [==============================] - 49s 236us/step - loss: 0.8832 - acc: 0.7181 - val_loss: 1.1725 - val_acc: 0.5306\n", + "Epoch 2/5\n", + " 86176/207522 [===========>..................] - ETA: 27s - loss: 0.7538 - acc: 0.7517" + ], + "name": "stdout" + }, + { + "output_type": "stream", + "text": [ + "207522/207522 [==============================] - 48s 232us/step - loss: 0.7584 - acc: 0.7520 - val_loss: 1.2289 - val_acc: 0.5324\n", + "Epoch 3/5\n", + " 58080/207522 [=======>......................] - ETA: 33s - loss: 0.6791 - acc: 0.7751" + ], + "name": "stdout" + }, + { + "output_type": "stream", + "text": [ + "207522/207522 [==============================] - 49s 234us/step - loss: 0.7037 - acc: 0.7691 - val_loss: 1.2679 - val_acc: 0.5286\n", + "Epoch 4/5\n", + " 46560/207522 [=====>........................] - ETA: 36s - loss: 0.6265 - acc: 0.7917" + ], + "name": "stdout" + }, + { + "output_type": "stream", + "text": [ + "207522/207522 [==============================] - 48s 234us/step - loss: 0.6557 - acc: 0.7842 - val_loss: 1.2291 - val_acc: 0.5548\n", + "Epoch 5/5\n", + " 42272/207522 [=====>........................] - ETA: 37s - loss: 0.5919 - acc: 0.8038" + ], + "name": "stdout" + }, + { + "output_type": "stream", + "text": [ + "207522/207522 [==============================] - 48s 233us/step - loss: 0.6153 - acc: 0.7974 - val_loss: 1.3626 - val_acc: 0.5342\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "knkiqlUtB2ig", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 69 + }, + "outputId": "f3667cd5-c77a-421d-8e1c-08edb0d51de2" + }, + "cell_type": "code", + "source": [ + "# Evaluate the accuracy of our trained model\n", + "score = model.evaluate(x_test, y_test,\n", + " batch_size=batch_size, verbose=1)\n", + "print('Test score:', score[0])\n", + "print('Test accuracy:', score[1])" + ], + "execution_count": 19, + "outputs": [ + { + "output_type": "stream", + "text": [ + "57646/57646 [==============================] - 4s 70us/step\n", + "Test score: 1.4960747232060105\n", + "Test accuracy: 0.499080595353738\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "gn520M-hB2jI", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 745 + }, + "outputId": "e88adb75-8707-492b-9d8b-f0dbf0af5458" + }, + "cell_type": "code", + "source": [ + "# Here's how to generate a prediction on individual examples\n", + "text_labels = encoder.classes_ \n", + "\n", + "for i in range(10,20):\n", + " prediction = model.predict(np.array([x_test[i]]))\n", + " predicted_label = text_labels[np.argmax(prediction)]\n", + " print(test_narrative.iloc[i][:50], \"...\")\n", + " print('Actual label:' + test_product.iloc[i])\n", + " print(\"Predicted label: \" + predicted_label + \"\\n\")" + ], + "execution_count": 22, + "outputs": [ + { + "output_type": "stream", + "text": [ + "I have sent letters making Transunion aware of the ...\n", + "Actual label:Credit reporting, credit repair services, or other personal consumer reports\n", + "Predicted label: Credit reporting, credit repair services, or other personal consumer reports\n", + "\n", + "While flying Spirit, we were presented with the op ...\n", + "Actual label:Credit card or prepaid card\n", + "Predicted label: Credit card\n", + "\n", + "This is my last effort to resolve this matter befo ...\n", + "Actual label:Debt collection\n", + "Predicted label: Debt collection\n", + "\n", + "I had XXXX XXXX XXXX from XX/XX/XXXX-XX/XX/XXXX. I ...\n", + "Actual label:Credit reporting, credit repair services, or other personal consumer reports\n", + "Predicted label: Debt collection\n", + "\n", + "Immense breach of highly sensitive data for a larg ...\n", + "Actual label:Credit reporting, credit repair services, or other personal consumer reports\n", + "Predicted label: Bank account or service\n", + "\n", + "Equifax data breach on XXXX/XXXX/XXXX. \n", + "\n", + "My SSN an ...\n", + "Actual label:Credit reporting, credit repair services, or other personal consumer reports\n", + "Predicted label: Credit reporting, credit repair services, or other personal consumer reports\n", + "\n", + "The company calls repeatedly day after day and thr ...\n", + "Actual label:Debt collection\n", + "Predicted label: Debt collection\n", + "\n", + "To whom it may concern, Please accept this corresp ...\n", + "Actual label:Mortgage\n", + "Predicted label: Mortgage\n", + "\n", + "in correspondence dated XX/XX/XXXX2017, I sent thi ...\n", + "Actual label:Credit reporting, credit repair services, or other personal consumer reports\n", + "Predicted label: Credit reporting, credit repair services, or other personal consumer reports\n", + "\n", + "This card is XXXX and is essentially a XXXX card a ...\n", + "Actual label:Credit card or prepaid card\n", + "Predicted label: Credit card\n", + "\n" + ], + "name": "stdout" + } + ] + }, + { + "metadata": { + "id": "h3_pDYtvKbJX", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 745 + }, + "outputId": "a12f5ea8-58c5-4812-ad3d-641bb542498a" + }, + "cell_type": "code", + "source": [ + "# Here's how to generate a prediction on individual examples\n", + "text_labels1 = encoder.classes_ \n", + "\n", + "#print(text_labels1)\n", + "print(x_test[i])" + ], + "execution_count": 29, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0.\n", + " 1. 1. 1. 0. 1. 1. 1. 1. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 1. 1. 1.\n", + " 1. 1. 0. 1. 1. 1. 0. 1. 0. 1. 0. 1. 0. 0. 1. 1. 1. 1. 1. 0. 1. 0. 0. 1.\n", + " 0. 1. 0. 0. 1. 1. 1. 0. 0. 1. 1. 1. 1. 1. 0. 0. 1. 1. 1. 0. 1. 0. 1. 1.\n", + " 0. 0. 1. 1. 0. 1. 0. 0. 0. 0. 1. 1. 1. 1. 0. 1. 0. 1. 0. 0. 1. 0. 1. 1.\n", + " 1. 0. 1. 1. 1. 1. 1. 0. 0. 0. 0. 0. 0. 1. 0. 0. 1. 1. 0. 0. 0. 0. 1. 0.\n", + " 0. 0. 0. 0. 0. 1. 0. 0. 1. 0. 0. 1. 0. 0. 0. 1. 1. 0. 0. 0. 0. 1. 0. 0.\n", + " 0. 1. 0. 0. 1. 1. 0. 1. 0. 0. 1. 1. 0. 0. 0. 0. 1. 1. 0. 1. 0. 0. 0. 0.\n", + " 1. 0. 0. 0. 1. 0. 1. 0. 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