Credit Card Fraud
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    Credit Card Fraud

    This dataset consists of credit card transactions in the western United States. It includes information about each transaction including customer details, the merchant and category of purchase, and whether or not the transaction was a fraud.

    Not sure where to begin? Scroll to the bottom to find challenges!

    import pandas as pd 
    
    pd.read_csv('credit_card_fraud.csv') 
    

    Data Dictionary

    transdatetrans_timeTransaction DateTime
    merchantMerchant Name
    categoryCategory of Merchant
    amtAmount of Transaction
    cityCity of Credit Card Holder
    stateState of Credit Card Holder
    latLatitude Location of Purchase
    longLongitude Location of Purchase
    city_popCredit Card Holder's City Population
    jobJob of Credit Card Holder
    dobDate of Birth of Credit Card Holder
    trans_numTransaction Number
    merch_latLatitude Location of Merchant
    merch_longLongitude Location of Merchant
    is_fraudWhether Transaction is Fraud (1) or Not (0)

    Source of dataset. The data was partially cleaned and adapted by DataCamp.

    Don't know where to start?

    Challenges are brief tasks designed to help you practice specific skills:

    • πŸ—ΊοΈ Explore: What types of purchases are most likely to be instances of fraud? Consider both product category and the amount of the transaction.
    • πŸ“Š Visualize: Use a geospatial plot to visualize the fraud rates across different states.
    • πŸ”Ž Analyze: Are older customers significantly more likely to be victims of credit card fraud?

    Scenarios are broader questions to help you develop an end-to-end project for your portfolio:

    A new credit card company has just entered the market in the western United States. The company is promoting itself as one of the safest credit cards to use. They have hired you as their data scientist in charge of identifying instances of fraud. The executive who hired you has have provided you with data on credit card transactions, including whether or not each transaction was fraudulent.

    The executive wants to know how accurately you can predict fraud using this data. She has stressed that the model should err on the side of caution: it is not a big problem to flag transactions as fraudulent when they aren't just to be safe. In your report, you will need to describe how well your model functions and how it adheres to these criteria.

    You will need to prepare a report that is accessible to a broad audience. It will need to outline your motivation, analysis steps, findings, and conclusions.


    ✍️ If you have an idea for an interesting Scenario or Challenge, or have feedback on our existing ones, let us know! You can submit feedback by pressing the question mark in the top right corner of the screen and selecting "Give Feedback". Include the phrase "Content Feedback" to help us flag it in our system.

    cc_fraud=pd.read_csv('credit_card_fraud.csv') 
    cc_fraud.head()
    cc_fraud_is=cc_fraud[cc_fraud['is_fraud']==1]
    
    more_1=cc_fraud_is.groupby('dob').merchant.value_counts()
    more_1=more_1[more_1>1]
    df=pd.DataFrame(more_1,)
    double_fraud=df.rename(columns={'merchant':'fraud_cnt'})
    double_fraud=double_fraud.reset_index()
    double_fraud=double_fraud[['merchant','dob','fraud_cnt']]
    double_fraud
    cc_fraud_is.loc[(cc_fraud_is['dob']=='1928-10-01') & (cc_fraud_is['merchant']=='Welch Inc')]
    
    lynch_moh=cc_fraud_is[cc_fraud_is['merchant'].str.contains('Romaguera, Cruickshank and Greenholt')]
    
    lynch_moh
    import matplotlib.pyplot as plt
    import seaborn as sns
    %matplotlib inline
    #Calculating fraud count by purchase category
    
    cc_fraud_by_cat=cc_fraud.groupby('category').is_fraud.sum()
    cc_fraud_by_cat
    #Plotting fraud count distribution by purchase catogory
    
    plt.bar(x=cc_fraud_by_cat.index,height=cc_fraud_by_cat)
    plt.xticks(rotation=90)
    plt.ylabel('Fraud count')
    plt.show()
    
    is_fraud=cc_fraud[cc_fraud['is_fraud']==1]
    is_fraud_sorted=is_fraud.groupby('category').amt.sum().sort_values()
    is_fraud_sorted
    #Calculating fraud count per state 
    
    cc_fraud_by_st=cc_fraud.groupby('state').is_fraud.sum()
    
    cc_fraud_by_st
    β€Œ
    β€Œ
    β€Œ