{ "cells": [ { "cell_type": "markdown", "id": "cd6a338a-9a00-45f4-ac13-9ed131c9049e", "metadata": {}, "source": [ "### Loading data (2023 year) " ] }, { "cell_type": "code", "execution_count": 1, "id": "2e8de3f1-6812-4c0d-bd56-32459911000e", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "import plotly.express as px" ] }, { "cell_type": "code", "execution_count": 2, "id": "ad45c437-7720-445e-8fa1-27d2b14b7bb5", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/tmp/ipykernel_9929/219708379.py:1: DtypeWarning: Columns (16) have mixed types. Specify dtype option on import or set low_memory=False.\n", " df = pd.read_csv('./complaints.csv')\n" ] } ], "source": [ "df = pd.read_csv('./complaints.csv')\n", "df['Date received'] = pd.to_datetime(df['Date received'])\n", "\n", "cols_to_consider = ['Product','Sub-product','Issue','Sub-issue','Consumer complaint narrative','Company public response','Company',\n", " 'State', 'ZIP code', 'Date received']\n", "df_new = df[cols_to_consider]\n", "\n", "df_new = df_new.dropna()" ] }, { "cell_type": "code", "execution_count": 3, "id": "6df32835-7186-4c57-bffa-536f779636fe", "metadata": {}, "outputs": [], "source": [ "df_2023 = df_new[df_new['Date received'].dt.year.isin([2023])].reset_index(drop=True)\n", "\n", "product_map = {'Credit reporting or other personal consumer reports' : 'Credit Reporting',\n", " 'Credit reporting, credit repair services, or other personal consumer reports' : 'Credit Reporting',\n", " 'Payday loan, title loan, personal loan, or advance loan' : 'Loans / Mortgage',\n", " 'Payday loan, title loan, or personal loan' : 'Loans / Mortgage',\n", " 'Student loan' : 'Loans / Mortgage',\n", " 'Vehicle loan or lease' : 'Loans / Mortgage',\n", " 'Debt collection' : 'Debt collection',\n", " 'Credit card or prepaid card' : 'Credit/Prepaid Card',\n", " 'Credit card' : 'Credit/Prepaid Card',\n", " 'Prepaid card' : 'Credit/Prepaid Card',\n", " 'Mortgage' : 'Loans / Mortgage',\n", " 'Checking or savings account' : 'Checking or savings account' \n", " }\n", "\n", "df_2023.loc[:,'Product'] = df_2023['Product'].map(product_map)" ] }, { "cell_type": "code", "execution_count": 4, "id": "679ffbe3-a6ba-4f4d-bf65-0690794fb4e1", "metadata": {}, "outputs": [ { "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", "
ProductSub-productIssueSub-issueConsumer complaint narrativeCompany public responseCompanyStateZIP codeDate received
0Checking or savings accountOther banking product or serviceOpening an accountAccount opened without my consent or knowledgeDate : XXXX XXXXo : XXXX XXXX XXXX / XXXX XXXX...Company has responded to the consumer and the ...WELLS FARGO & COMPANYNC275132023-12-29
1Credit ReportingCredit reportingProblem with a company's investigation into an...Investigation took more than 30 daysI have previously disputed this item with you ...Company has responded to the consumer and the ...Experian Information Solutions Inc.MN551242023-12-29
2Debt collectionOther debtAttempts to collect debt not owedDebt was result of identity theftI kindly request that you update my credit rep...Company has responded to the consumer and the ...Experian Information Solutions Inc.IL606212023-12-28
3Debt collectionOther debtAttempts to collect debt not owedDebt was result of identity theftI implore you to conduct a comprehensive inves...Company has responded to the consumer and the ...Experian Information Solutions Inc.NJ087232023-12-28
4Credit ReportingCredit reportingIncorrect information on your reportInformation belongs to someone elseIn accordance with the Fair Credit Reporting A...Company has responded to the consumer and the ...TRANSUNION INTERMEDIATE HOLDINGS, INC.TX773772023-11-27
\n", "
" ], "text/plain": [ " Product Sub-product \\\n", "0 Checking or savings account Other banking product or service \n", "1 Credit Reporting Credit reporting \n", "2 Debt collection Other debt \n", "3 Debt collection Other debt \n", "4 Credit Reporting Credit reporting \n", "\n", " Issue \\\n", "0 Opening an account \n", "1 Problem with a company's investigation into an... \n", "2 Attempts to collect debt not owed \n", "3 Attempts to collect debt not owed \n", "4 Incorrect information on your report \n", "\n", " Sub-issue \\\n", "0 Account opened without my consent or knowledge \n", "1 Investigation took more than 30 days \n", "2 Debt was result of identity theft \n", "3 Debt was result of identity theft \n", "4 Information belongs to someone else \n", "\n", " Consumer complaint narrative \\\n", "0 Date : XXXX XXXXo : XXXX XXXX XXXX / XXXX XXXX... \n", "1 I have previously disputed this item with you ... \n", "2 I kindly request that you update my credit rep... \n", "3 I implore you to conduct a comprehensive inves... \n", "4 In accordance with the Fair Credit Reporting A... \n", "\n", " Company public response \\\n", "0 Company has responded to the consumer and the ... \n", "1 Company has responded to the consumer and the ... \n", "2 Company has responded to the consumer and the ... \n", "3 Company has responded to the consumer and the ... \n", "4 Company has responded to the consumer and the ... \n", "\n", " Company State ZIP code Date received \n", "0 WELLS FARGO & COMPANY NC 27513 2023-12-29 \n", "1 Experian Information Solutions Inc. MN 55124 2023-12-29 \n", "2 Experian Information Solutions Inc. IL 60621 2023-12-28 \n", "3 Experian Information Solutions Inc. NJ 08723 2023-12-28 \n", "4 TRANSUNION INTERMEDIATE HOLDINGS, INC. TX 77377 2023-11-27 " ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_2023.head()" ] }, { "cell_type": "code", "execution_count": 5, "id": "a85ec9b1-5de7-47f9-b204-4d42c8880bbb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Index(['Product', 'Sub-product', 'Issue', 'Sub-issue',\n", " 'Consumer complaint narrative', 'Company public response', 'Company',\n", " 'State', 'ZIP code', 'Date received'],\n", " dtype='object')" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_2023.columns" ] }, { "cell_type": "markdown", "id": "0487636d-9663-4fdb-b219-f9e6be257b51", "metadata": {}, "source": [ "### Complaint pre-processing" ] }, { "cell_type": "code", "execution_count": 6, "id": "e35208c6-020a-4fb9-8c9f-13fdeee44935", "metadata": {}, "outputs": [], "source": [ "df_2023['complaint length'] = df_2023['Consumer complaint narrative'].apply(lambda x : len(x))" ] }, { "cell_type": "code", "execution_count": 7, "id": "63deb9bb-d48a-460b-8edb-f66575ec1eaf", "metadata": {}, "outputs": [], "source": [ "df_2023 = df_2023[df_2023['complaint length'] > 20]\n", "\n", "complaints_to_exclude = ['See document attached', 'See the attached documents.', 'Incorrect information on my credit report', 'incorrect information on my credit report',\n", "'please see attached file','Please see documents Attached','Incorrect information on my credit report.', 'Please see attached file', 'see attached',\n", "'See attached', 'SEE ATTACHED DOCUMENTS', 'See Attached', 'SEE ATTACHMENT', 'SEE ATTACHMENTS', \n", "'XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX XXXX']\n", "\n", "df_2023 = df_2023[~df_2023['Consumer complaint narrative'].isin(complaints_to_exclude)]" ] }, { "cell_type": "markdown", "id": "492f8261-3e01-41d5-8f24-82bd289ee229", "metadata": {}, "source": [ "### Categories consideration" ] }, { "cell_type": "code", "execution_count": 8, "id": "0be9e1f3-61aa-494a-bd0c-a6afeab5aacd", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(264968, 5)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_2023_subset = df_2023[['Consumer complaint narrative','Product','Sub-product','Issue','Sub-issue']]\n", "df_2023_subset.shape" ] }, { "cell_type": "code", "execution_count": 9, "id": "33e4e7e3-6661-48aa-aec2-b706fa64338d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Product\n", "Credit Reporting 213403\n", "Credit/Prepaid Card 16319\n", "Checking or savings account 15143\n", "Debt collection 11767\n", "Loans / Mortgage 8336\n", "Name: count, dtype: int64" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df_2023_subset['Product'].value_counts()" ] }, { "cell_type": "code", "execution_count": 10, "id": "dbc49ba8-f15a-4a4b-b018-d9d2273620ba", "metadata": {}, "outputs": [], "source": [ "sub_issues_to_consider = df_2023_subset['Sub-issue'].value_counts()[df_2023_subset['Sub-issue'].value_counts() > 500].index" ] }, { "cell_type": "code", "execution_count": 11, "id": "746db565-e6ff-4ab2-bf92-d56088c0f2da", "metadata": {}, "outputs": [], "source": [ "reduced_subissues = df_2023_subset[df_2023_subset['Sub-issue'].isin(sub_issues_to_consider)]" ] }, { "cell_type": "code", "execution_count": 12, "id": "0f786b1d-b139-40b5-ad53-639d8687d3b4", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(248065, 5)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "reduced_subissues.shape" ] }, { "cell_type": "code", "execution_count": 13, "id": "f64515e8-ac65-4041-a201-a8576a86d7ad", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Sub-issue\n", "Information belongs to someone else 57877\n", "Reporting company used your report improperly 48781\n", "Their investigation did not fix an error on your report 45407\n", "Credit inquiries on your report that you don't recognize 13150\n", "Account status incorrect 10271\n", "Account information incorrect 9307\n", "Was not notified of investigation status or results 9201\n", "Investigation took more than 30 days 8937\n", "Personal information incorrect 5900\n", "Debt is not yours 2821\n", "Deposits and withdrawals 2626\n", "Credit card company isn't resolving a dispute about a purchase on your statement 2289\n", "Didn't receive enough information to verify debt 1816\n", "Debt was result of identity theft 1761\n", "Old information reappears or never goes away 1716\n", "Difficulty submitting a dispute or getting information about a dispute over the phone 1709\n", "Company closed your account 1517\n", "Problem using a debit or ATM card 1503\n", "Public record information inaccurate 1389\n", "Transaction was not authorized 1378\n", "Problem with personal statement of dispute 1361\n", "Other problem getting your report or credit score 1112\n", "Debt was paid 969\n", "Card was charged for something you did not purchase with the card 964\n", "Banking errors 958\n", "Funds not handled or disbursed as instructed 955\n", "Overdrafts and overdraft fees 951\n", "Attempted to collect wrong amount 885\n", "Information is missing that should be on the report 881\n", "Problem during payment process 840\n", "Fee problem 764\n", "Problem with fees 749\n", "Received bad information about your loan 710\n", "Other problem 701\n", "Threatened or suggested your credit would be damaged 687\n", "Funds not received from closed account 673\n", "Trouble with how payments are being handled 650\n", "Didn't receive notice of right to dispute 644\n", "Can't close your account 598\n", "Problem accessing account 561\n", "Account opened as a result of fraud 561\n", "Problem canceling credit monitoring or identify theft protection service 521\n", "Card opened as result of identity theft or fraud 511\n", "Billing problem 503\n", "Name: count, dtype: int64" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "reduced_subissues['Sub-issue'].value_counts()" ] }, { "cell_type": "code", "execution_count": 14, "id": "6204eb53-1a5b-457f-ab67-957d73f568af", "metadata": {}, "outputs": [], "source": [ "sub_products_to_consider = reduced_subissues['Sub-product'].value_counts()[reduced_subissues['Sub-product'].value_counts() > 100].index\n", "final_df_2023 = reduced_subissues[reduced_subissues['Sub-product'].isin(sub_products_to_consider)]" ] }, { "cell_type": "code", "execution_count": 15, "id": "781850e8-cd50-4d08-87aa-8d86715cc2ef", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(247517, 5)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df_2023.shape" ] }, { "cell_type": "markdown", "id": "563955e5-8b1b-4d67-a552-5d1b69ff8891", "metadata": {}, "source": [ "### Issue categories grouping" ] }, { "cell_type": "code", "execution_count": 16, "id": "8cb41375-d72e-4f90-bde1-6ff13af37082", "metadata": {}, "outputs": [], "source": [ "issues_to_subissues = {}\n", "for issue in final_df_2023['Issue'].value_counts().index:\n", " issues_to_subissues[issue] = list(final_df_2023[final_df_2023['Issue'] == issue]['Sub-issue'].value_counts().to_dict().keys())\n", "\n", "one_subissue = {key : value for key,value in issues_to_subissues.items() if len(issues_to_subissues[key]) == 1}\n", "more_than_one_subissue = {key : value for key,value in issues_to_subissues.items() if len(issues_to_subissues[key]) > 1}\n", "\n", "existing_issue_mapping = {issue : issue for issue in more_than_one_subissue}\n", "\n", "issue_renaming = {\n", " 'Problem with a lender or other company charging your account': 'Account Operations and Unauthorized Transaction Issues',\n", " 'Opening an account': 'Account Operations and Unauthorized Transaction Issues',\n", " 'Getting a credit card': 'Account Operations and Unauthorized Transaction Issues',\n", "\n", " 'Unable to get your credit report or credit score': 'Credit Report and Monitoring Issues',\n", " 'Credit monitoring or identity theft protection services': 'Credit Report and Monitoring Issues',\n", " 'Identity theft protection or other monitoring services': 'Credit Report and Monitoring Issues',\n", " \n", " 'Problem caused by your funds being low': 'Payment and Funds Management',\n", " 'Problem when making payments': 'Payment and Funds Management',\n", " 'Managing the loan or lease': 'Payment and Funds Management',\n", "\n", " 'False statements or representation': 'Disputes and Misrepresentations',\n", " 'Fees or interest': 'Disputes and Misrepresentations',\n", " 'Other features, terms, or problems': 'Disputes and Misrepresentations',\n", "\n", " 'Took or threatened to take negative or legal action': 'Legal and Threat Actions'\n", "}\n", "\n", "issues_mapping = {**issue_renaming, **existing_issue_mapping}\n", "\n", "final_df_2023.loc[:,'Issue'] = final_df_2023['Issue'].apply(lambda x : issues_mapping[x])" ] }, { "cell_type": "markdown", "id": "0ab4f91f-c938-4093-a299-b895ea13121a", "metadata": {}, "source": [ "### Value counts" ] }, { "cell_type": "code", "execution_count": 17, "id": "17ddf55c-f824-4b2c-8059-07d02597a1cb", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Product\n", "Credit Reporting 211695\n", "Checking or savings account 12285\n", "Credit/Prepaid Card 11975\n", "Debt collection 9380\n", "Loans / Mortgage 2182\n", "Name: count, dtype: int64" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df_2023['Product'].value_counts()" ] }, { "cell_type": "code", "execution_count": 18, "id": "eae2d688-f706-4c31-9228-1ae7eadbf228", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Sub-product\n", "Credit reporting 210735\n", "General-purpose credit card or charge card 10668\n", "Checking account 10409\n", "Other debt 3041\n", "I do not know 2316\n", "Credit card debt 1652\n", "Federal student loan servicing 1344\n", "Store credit card 1307\n", "Medical debt 1053\n", "Savings account 989\n", "Other personal consumer report 960\n", "Loan 732\n", "Other banking product or service 725\n", "Auto debt 581\n", "Telecommunications debt 419\n", "Rental debt 179\n", "CD (Certificate of Deposit) 162\n", "Mortgage debt 139\n", "Conventional home mortgage 106\n", "Name: count, dtype: int64" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df_2023['Sub-product'].value_counts()" ] }, { "cell_type": "code", "execution_count": 19, "id": "61179ec3-f49f-4d2a-adde-738a0ff89371", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Issue\n", "Incorrect information on your report 87200\n", "Improper use of your report 61868\n", "Problem with a credit reporting company's investigation into an existing problem 45371\n", "Problem with a company's investigation into an existing problem 20985\n", "Managing an account 7367\n", "Attempts to collect debt not owed 5453\n", "Problem with a purchase shown on your statement 3253\n", "Account Operations and Unauthorized Transaction Issues 2450\n", "Written notification about debt 2404\n", "Disputes and Misrepresentations 2311\n", "Payment and Funds Management 2259\n", "Closing an account 1975\n", "Credit Report and Monitoring Issues 1630\n", "Dealing with your lender or servicer 1293\n", "Closing your account 813\n", "Legal and Threat Actions 662\n", "Problem with a company's investigation into an existing issue 223\n", "Name: count, dtype: int64" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df_2023['Issue'].value_counts()" ] }, { "cell_type": "code", "execution_count": 20, "id": "928750bb-7324-480f-aaa1-a4438841399c", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Sub-issue\n", "Information belongs to someone else 57850\n", "Reporting company used your report improperly 48732\n", "Their investigation did not fix an error on your report 45395\n", "Credit inquiries on your report that you don't recognize 13136\n", "Account status incorrect 10208\n", "Account information incorrect 9267\n", "Was not notified of investigation status or results 9200\n", "Investigation took more than 30 days 8928\n", "Personal information incorrect 5900\n", "Debt is not yours 2785\n", "Deposits and withdrawals 2626\n", "Credit card company isn't resolving a dispute about a purchase on your statement 2289\n", "Didn't receive enough information to verify debt 1777\n", "Debt was result of identity theft 1727\n", "Old information reappears or never goes away 1714\n", "Difficulty submitting a dispute or getting information about a dispute over the phone 1704\n", "Company closed your account 1517\n", "Problem using a debit or ATM card 1503\n", "Public record information inaccurate 1384\n", "Transaction was not authorized 1378\n", "Problem with personal statement of dispute 1352\n", "Other problem getting your report or credit score 1109\n", "Card was charged for something you did not purchase with the card 964\n", "Banking errors 958\n", "Funds not handled or disbursed as instructed 955\n", "Overdrafts and overdraft fees 951\n", "Debt was paid 941\n", "Information is missing that should be on the report 877\n", "Attempted to collect wrong amount 861\n", "Problem during payment process 840\n", "Fee problem 764\n", "Problem with fees 749\n", "Other problem 701\n", "Received bad information about your loan 677\n", "Funds not received from closed account 673\n", "Threatened or suggested your credit would be damaged 662\n", "Didn't receive notice of right to dispute 627\n", "Trouble with how payments are being handled 616\n", "Can't close your account 598\n", "Problem accessing account 561\n", "Account opened as a result of fraud 561\n", "Problem canceling credit monitoring or identify theft protection service 521\n", "Card opened as result of identity theft or fraud 511\n", "Billing problem 468\n", "Name: count, dtype: int64" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df_2023['Sub-issue'].value_counts()" ] }, { "cell_type": "markdown", "id": "fd91e57e-766c-4c4b-92c1-4b61469be9b4", "metadata": {}, "source": [ "### Unique categories" ] }, { "cell_type": "code", "execution_count": 21, "id": "028803cd-86c0-4c8a-9fab-8f05ba6793a1", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Unique Product offerings: 5\n", "Unique Sub-product offerings: 19\n", "Unique Issue offerings: 17\n", "Unique Sub-issue offerings: 44\n" ] } ], "source": [ "print(f\"Unique Product offerings: {final_df_2023['Product'].nunique()}\")\n", "print(f\"Unique Sub-product offerings: {final_df_2023['Sub-product'].nunique()}\")\n", "print(f\"Unique Issue offerings: {final_df_2023['Issue'].nunique()}\")\n", "print(f\"Unique Sub-issue offerings: {final_df_2023['Sub-issue'].nunique()}\")" ] }, { "cell_type": "markdown", "id": "06ea0454-ed84-450a-90f7-e7552ffc181f", "metadata": {}, "source": [ "### Preparing the train and test splits" ] }, { "cell_type": "code", "execution_count": 22, "id": "267b771c-f944-443a-8048-c2f0097f4f29", "metadata": {}, "outputs": [], "source": [ "from sklearn.model_selection import train_test_split" ] }, { "cell_type": "code", "execution_count": 23, "id": "eebed808-66b4-4fa8-a0ce-872b70d18106", "metadata": {}, "outputs": [ { "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", "
Consumer complaint narrativeProductSub-productIssueSub-issue
1I have previously disputed this item with you ...Credit ReportingCredit reportingProblem with a company's investigation into an...Investigation took more than 30 days
2I kindly request that you update my credit rep...Debt collectionOther debtAttempts to collect debt not owedDebt was result of identity theft
3I implore you to conduct a comprehensive inves...Debt collectionOther debtAttempts to collect debt not owedDebt was result of identity theft
4In accordance with the Fair Credit Reporting A...Credit ReportingCredit reportingIncorrect information on your reportInformation belongs to someone else
5In accordance with Fair c=Credit Reporting Act...Credit ReportingCredit reportingImproper use of your reportReporting company used your report improperly
\n", "
" ], "text/plain": [ " Consumer complaint narrative Product \\\n", "1 I have previously disputed this item with you ... Credit Reporting \n", "2 I kindly request that you update my credit rep... Debt collection \n", "3 I implore you to conduct a comprehensive inves... Debt collection \n", "4 In accordance with the Fair Credit Reporting A... Credit Reporting \n", "5 In accordance with Fair c=Credit Reporting Act... Credit Reporting \n", "\n", " Sub-product Issue \\\n", "1 Credit reporting Problem with a company's investigation into an... \n", "2 Other debt Attempts to collect debt not owed \n", "3 Other debt Attempts to collect debt not owed \n", "4 Credit reporting Incorrect information on your report \n", "5 Credit reporting Improper use of your report \n", "\n", " Sub-issue \n", "1 Investigation took more than 30 days \n", "2 Debt was result of identity theft \n", "3 Debt was result of identity theft \n", "4 Information belongs to someone else \n", "5 Reporting company used your report improperly " ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "final_df_2023.head()" ] }, { "cell_type": "code", "execution_count": 24, "id": "da025cda-f04e-4822-b100-855e981d632a", "metadata": {}, "outputs": [], "source": [ "X = final_df_2023['Consumer complaint narrative']\n", "y = final_df_2023[['Product','Sub-product','Issue','Sub-issue']]\n", "\n", "X_train, X_test, y_train, y_test = train_test_split(X,y,stratify=y['Product'],test_size=0.25,random_state=42)" ] }, { "cell_type": "code", "execution_count": 25, "id": "d291102d-7136-4512-84c2-ba970b169cbf", "metadata": {}, "outputs": [], "source": [ "train_df = pd.concat([X_train,y_train],axis = 1).reset_index(drop = True)\n", "test_df = pd.concat([X_test,y_test],axis = 1).reset_index(drop = True)" ] }, { "cell_type": "code", "execution_count": 26, "id": "0006636f-24cf-41dd-98cd-dc3a2b65432f", "metadata": {}, "outputs": [ { "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", "
Consumer complaint narrativeProductSub-productIssueSub-issue
0The credit bureaus keep disrespecting the laws...Credit ReportingCredit reportingProblem with a company's investigation into an...Their investigation did not fix an error on yo...
1I sent in a complaint in XXXX of 2021 about so...Credit ReportingCredit reportingIncorrect information on your reportInformation belongs to someone else
2I ordered a copy of my report and I found out ...Credit ReportingCredit reportingProblem with a credit reporting company's inve...Their investigation did not fix an error on yo...
3It appears that my credit file has been compro...Credit ReportingCredit reportingIncorrect information on your reportInformation belongs to someone else
4I have never authorized, consented to nor bene...Credit ReportingCredit reportingIncorrect information on your reportInformation belongs to someone else
\n", "
" ], "text/plain": [ " Consumer complaint narrative Product \\\n", "0 The credit bureaus keep disrespecting the laws... Credit Reporting \n", "1 I sent in a complaint in XXXX of 2021 about so... Credit Reporting \n", "2 I ordered a copy of my report and I found out ... Credit Reporting \n", "3 It appears that my credit file has been compro... Credit Reporting \n", "4 I have never authorized, consented to nor bene... Credit Reporting \n", "\n", " Sub-product Issue \\\n", "0 Credit reporting Problem with a company's investigation into an... \n", "1 Credit reporting Incorrect information on your report \n", "2 Credit reporting Problem with a credit reporting company's inve... \n", "3 Credit reporting Incorrect information on your report \n", "4 Credit reporting Incorrect information on your report \n", "\n", " Sub-issue \n", "0 Their investigation did not fix an error on yo... \n", "1 Information belongs to someone else \n", "2 Their investigation did not fix an error on yo... \n", "3 Information belongs to someone else \n", "4 Information belongs to someone else " ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_df.head()" ] }, { "cell_type": "code", "execution_count": 27, "id": "724b3508-7e79-4526-a20f-3797250f9cf9", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(185637, 5)" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "train_df.shape" ] }, { "cell_type": "code", "execution_count": 28, "id": "06972769-eddd-4ee7-9ebc-e6f587ad5366", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(61880, 5)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "test_df.shape" ] }, { "cell_type": "code", "execution_count": 29, "id": "de358d80-fd59-4f9c-83ee-2264659f4b0f", "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "directory_to_save = './data_splits/'\n", "\n", "if not os.path.exists(directory_to_save):\n", " os.makedirs(directory_to_save)\n", "\n", "train_df.to_csv(directory_to_save + 'train-data-split.csv',index = False)\n", "test_df.to_csv(directory_to_save + 'test-data-split.csv',index = False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.19" } }, "nbformat": 4, "nbformat_minor": 5 }