{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# ML and Credit Card Fraud Detection\n","metadata":{}},{"cell_type":"markdown","source":"<a id = \"table-of-content\"></a>\n# Table of Content\n\n- [Introduction](#intro)\n- [Detecting Credit Card Fraud](#detecting_credit_card_fraud)\n- [Best Practices](#best_practices)\n- [Conclusion](#conclusion)\n- [References](#references)","metadata":{}},{"cell_type":"markdown","source":"<a id = \"intro\"></a>\n# Introduction","metadata":{}},{"cell_type":"markdown","source":"Research shows the increase in card usage by 25% between 2018 - 2019 in South Africa has meant increased traction in the e-commerce space. Conversely, there was a 53% increase in credit card fraud between 2019 - 2021 (Makatjane et al, 2022). In the wake of card fraud banks can use Artificial Intelligence (AI) algorithms to proactively monitor transactions, reduce and hopefully prevent credit card fraud; use AI to augment the loan recommndation processes, and AI in investment portfolio management. African Banks are adapting to the new security threats to secure, retaining and gaining the trust of their clients, and augment their business processes to stay competetive.\n\nEquity Bank has intergrated chatbot named Equity Virtual Assistant (EVA) into their whatsapp, facebook messenger and telegram accounts to improve their customer jourey and experience.\n\n\nAI algorithms types include but are not limited to supervised, unsupervised and semi-supervised learning. All the algorithm types mentioned above either take in data that has a number of features as input the only difference is that supervised algorithms require that the output is known beforehand and it is provided with the data; supervised learning or unsupervised algorithms do not need the labels to derive meaning ful patterns and semi-supervised algorithms have a mix of labeled and unlabeled data; each has its own pros and cons -- we will have a look at this later; we will also go through the application of AI in the security, loans and investment departments. \n\nThere are a number of AI algorithms that can be used, from neural networks to decision trees that can be applied to solve challenges such as detecting credit card fraud. ","metadata":{}},{"cell_type":"markdown","source":"<a id = \"detecting_credit_card_fraud\"></a>\n# Detecting Credit Card Fraud  \nDetecting fraudulent transactions involves looking at the client’s previous transaction e.g. 6 months and recognizing patterns of transactions that are consistent with the user’s past transactions using AI models. When a new transaction is initiated by the user’s account our AI model will classify the new transaction and gauge whether it is an outlier and flag it as a possible fraudulent transaction or it fits within the client’s transactional behaviours. An example of a class of AI models that can be used in the process are neural networks. \n\nNeural networks such as Restricted Boltzman Machine (RBM) which is an unsupervised algorithm that uses a two-layer neural network (visible and hidden) that works by reconstructing the input using forward and backward passes. In card fraud it is one of the most performant ML algorithms; it outperforms other unsupervised algorithms such as One-Class SVM (OCSVM) and Generative Adversarial Networks (Pumsirirat et al, 2018; Niu et al, 2019). \n\nIn addition to that, supervised large neural networks that are with a depth of several layers have exhibited skills that can be used to address challenges such as credit card fraud detection; which is a form of classification and as part of a recommendation system (Gao et al., 2023). On one hand, large neural networks have a challenge in terms of utilizing a large number of resources when training. On the other hand, Frantar  & Alistarh (2022) also show that Sparse GPT can be used to prune GPT class models that are neural networks using the transformer architecture. After pruning models such as OPT-175B and BLOOM-176B that have billions of parameters in under 4.5 hours they can reach 50% – 60% sparsity and removing more than 100 billion weights that can be ignored at inference times with insignificant losses in accuracy. Sparse GPT can be applied to neural networks improving both inference times and potentially interpretability of the models. Neural networks can be explained with tools like LIME; which is a technique to explain predictions by narrowing the scope from global to local where there are fewer varibles to consider and Shap values to address the challenge of them being black boxes (Peres et al, 2020). ","metadata":{}},{"cell_type":"markdown","source":"\nSupervised learning is where a statistical model learns from features and labelled data -- an example of a supervised model is K-Nearest Neighbour (KNN). Conversely, unsupervised learning is also statistical in nature, they process unlabeled features to find significantly meaningful patterns (Bhavsar & Ganatra, 2019; Niu et al, 2019).  \n\n\n\nOn one hand, supervised learning has inherent crests and troughs to it; since most of the algorithms in supervised learning are eager learners they are computationally intensive during training. On the other hand, they have faster inference times (Bhavsar & Ganatra, 2019). \n\n  \n\nUnsupervised learning has its own difficulties and the upper hand. Most unsupervised models are easier to train but have slower inference times – an example of an unsupervised model is Restricted Boltzmann Machine (RBM) (Pumsirirat et al, 2018; Niu et al, 2019). Most unsupervised learners are lazy learners, on one side of the scale lazy learners like KNN are less computationally demanding during training compared to their counterparts eager learners. On the other side of the scale, they do have slower inference times compared to Decision Trees which are eager learners (Bhavsar & Ganatra, 2019). ","metadata":{}},{"cell_type":"markdown","source":"<a id = \"best_bractices\"></a>\n# Best Practices","metadata":{}},{"cell_type":"markdown","source":"TODO (Improve on this): Supervised models perform better and seem to have higher recall and precision -- although overfitting is a challenge for supervised algorithms.See below the Receiver Operating characteristic Curve below in figure 2 and 3 for supervised and unsupervised models.","metadata":{}},{"cell_type":"code","source":"from IPython.display import Image\nfrom IPython.core.display import HTML \nImage(url= \"https://i.ibb.co/Jv8wmD4/Screenshot-2023-07-07-at-15-30-08.png\",width=600, height=600)","metadata":{"execution":{"iopub.status.busy":"2023-09-02T22:20:10.813478Z","iopub.execute_input":"2023-09-02T22:20:10.814085Z","iopub.status.idle":"2023-09-02T22:20:10.825081Z","shell.execute_reply.started":"2023-09-02T22:20:10.814047Z","shell.execute_reply":"2023-09-02T22:20:10.823534Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Figure 2: ROC of unsupervised clasifiers (Niu et al., 2019)","metadata":{}},{"cell_type":"code","source":"from IPython.display import Image\nfrom IPython.core.display import HTML \nImage(url= \"https://i.ibb.co/FbdMK9b/Screenshot-2023-07-07-at-15-29-58.png\",width=600, height=600)","metadata":{"execution":{"iopub.status.busy":"2023-09-02T22:20:10.828213Z","iopub.execute_input":"2023-09-02T22:20:10.828780Z","iopub.status.idle":"2023-09-02T22:20:10.844007Z","shell.execute_reply.started":"2023-09-02T22:20:10.828741Z","shell.execute_reply":"2023-09-02T22:20:10.842764Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Figure 3: ROC of unsupervised clasifiers (Niu et al., 2019)","metadata":{}},{"cell_type":"markdown","source":"Data collection and data understanding is an important ascpect of the AI model creation process; the banks need to make sure to reduce or omit biased data which will be used to train the model. Imbalances in the data must also be investigates during data exploration to see the distribution of the data and what issues it might cause and use statistical tools to address the challenges.\nWe can also see below in Figure 4 when selecting an AI model to solve your business problem you should consider the strengths and weaknesses of the model. ","metadata":{}},{"cell_type":"code","source":"from IPython.display import Image\nfrom IPython.core.display import HTML \nhtml_image = '<img src=\"https://i.ibb.co/LpnSjYn/Screenshot-2023-07-07-at-14-04-00.png\" width=\"600\" height=\"600\" align=\"left\"/>'\nHTML(html_image)","metadata":{"execution":{"iopub.status.busy":"2023-09-02T22:20:10.846152Z","iopub.execute_input":"2023-09-02T22:20:10.847042Z","iopub.status.idle":"2023-09-02T22:20:10.862305Z","shell.execute_reply.started":"2023-09-02T22:20:10.846992Z","shell.execute_reply":"2023-09-02T22:20:10.861070Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Figure 4: Comparative study of commonly used Classification Techniques (Bhavsar, H. & Ganatra, A. 2012)","metadata":{}},{"cell_type":"markdown","source":"<a id = \"conclusion\"></a>\n# Conclusion \n\nA mix of supervised and unsupervised approaches has been shown to yield significantly more accurate results in use cases such as network traffic classification (Erman et al, 2007); which might be able to fix such issue in countries like South Africa. The Semi-supervised approach addresses the challenges in supervised (overfitting) and unsupervised learning mentioned above. However, Semi-supervised classification has a scaling challenge when there is a large amount of data (Padmanabha et al, 2018); it might be a challenge if banks have heavy traffic -- perhaps container orchestration with platforms like Kubernetes and leaner models using tools like Deep Sparse and languages like JAX can address the hurdle. Also, adversarial attacks need to be studied to find effective defenses for recommender systems. In addition to that, care should be taken throughout the process of creating an AI model where monetary value can be lost and banks’ reputations can be tainted; from business problem formulation, data gathering where data poisoning can occur, legal where issues can arise if some or all actors are not able to explain how an AI model reached a result, AI model training and deployment where adversarial attacks can occur when the model is in the wild (Leslie, 2019). \n\n# References: \n\nBhavsar, H. & Ganatra, A. (2012) A Comparative Study of Training Algorithms for Supervised Machine Learning. International Journal of Soft Computing and Engineering (IJSCE) 2(4): 74. Available from: https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&doi=18ca69ec35a0ab52922cb8a81d5041ac99005f3a [Accessed 25 Jun 2023] \n\n \n\nBhaskar, T. & Subramanian, G. (2011). Loan recommender system for microfinance loans: Increasing efficiency to assist growth. Journal of Financial Services Marketing, 15(4), pp.334–345. DOI: https://doi.org/10.1057/fsm.2010.27 \n\nDarangwa, V. P. (2021) Exploring artificial intelligence in the South African banking industry. Available from: https://repository.nwu.ac.za/bitstream/handle/10394/38832/Darangwa%20VP%2026565153.pdf?sequence=1&isAllowed=y [Accessed 15 June 2023] \n\n  \n\nErman, J., Mahanti, A., Arlitt, M., Cohen, I., & Williamson, C. (2007). Offline/realtime traffic classification using semi-supervised learning. Performance Evaluation, 64 (9-12): 1194-1213. DOI: https://doi.org/10.1016/j.peva.2007.06.014 \n\n \n\nFrantar E., Alistarh D. (2022) SparseGPT: Massive Language Models Can be Accurately Pruned in One-Shot. Available from: https://arxiv.org/pdf/2301.00774.pdf [Accessed 03 July2023] \n\n \n\nFrostig, R., Brain, G., Johnson, M. &Leary Google, C. 2023 Compiling machine learning programs via high-level tracing. [online] Available from: https://mlsys.org/Conferences/doc/2018/146.pdf [Accessed 5 Jul. 2023] \n\n \n\nGao, Y., Sheng, T., Xiang, Y., Xiong, Y., Wang, H. and Zhang, J. (2023) Chat-REC: Towards Interactive and Explainable LLMs-Augmented Recommender System. DOI: https://doi.org/10.48550/arxiv.2303.14524. \n \n\nLeslie, D. (2019) Understanding artificial intelligence ethics and safety: A guide for the responsible design and implementation of AI systems in the public sector.The Alan Turing Institute. DOI: https://doi.org/10.5281/zenodo.3240529 \n\n \n\nMakatjane, K., & Moroke, N. D. (2022). Detecting Bank Financial Fraud in South Africa Using a Logistic Model Tree. In Applications of Machine Learning and Deep Learning for Privacy and Cybersecurity (pp. 27). DOI: https://10.4018/978-1-7998-9430-8.ch008  \n\n \n\nMarkowitz, H. (1952) Portfolio Selection. The Journal of Finance, 7(1): 77–91. DOI: https://doi.org/10.2307/2975974 \n\n \n\nNiu, X., Wang, L., & Yang, X. (2019). A Comparison Study of Credit Card Fraud Detection: Supervised versus Unsupervised. Available from: https://arxiv.org/pdf/1904.10604v1.pdf [Accessed 24 June 2023].  \n\n \n\nPatel S., Bhattacharya P., Tanwar S. & N. Kumar (2021) \"KiRTi: A Blockchain-Based Credit Recommender System for Financial Institutions,\". IEEE Transactions on Network Science and Engineering 8(2): 1044-1054 DOI: https://doi.org/10.1109/TNSE.2020.3005678 \n\n \n\nPumsirirat, A., & Yan, L. (2018). Credit Card Fraud Detection using Deep Learning based on Auto-Encoder and Restricted Boltzmann Machine.  (IJACSA) International Journal of Advanced Computer Science and Applications 9(1): 18. Available from: https://pdfs.semanticscholar.org/01be/7624aa0e0251182593350a984411c2e5128a.pdf [Accessed 14 June 2023].  \n\n  \n\nPadmanabha, R., Viswanath P., & Eswara R. (2018) Semi-supervised learning: a brief review. International Journal of Soft Computing and Engineering (IJSCE) 7(1.8): 81-85. Available from: https://www.researchgate.net/profile/Eswara-B/publication/324050146_Semi-supervised_learning_a_brief_review/links/5b5c02f8458515c4b24e2b15/Semi-supervised-learning-a-brief-review.pdf [Accessed 25 Jun 2023] \n\n \n\nPeres R., X. Jia, J. Lee, K. Sun, A. W. Colombo and J. Barata (2020), \"Industrial Artificial Intelligence in Industry 4.0 - Systematic Review, Challenges and Outlook,\" in IEEE Access, vol. 8: 220121-220139, 2020, DOI: https://doi.org/10.1109/ACCESS.2020.3042874 \n\n \n\nRudin, C. (2019) Stop Explaining Black Box Machine Learning Models for High Stakes Decisions and Use Interpretable Models Instead. Nature Machine Intelligence 1(5): 206-215 DOI: https://doi.org/10.48550/arXiv.1811.10154 \n\n \n\nXue, F., Fu, Y., Zhou, W., Zheng, Z. and You, Y. (2023) To Repeat or Not To Repeat: Insights from Scaling LLM under Token-Crisis. DOI: https://doi.org/10.48550/arXiv.2305.13230. \n\n  \n\nZibriczky, D. (2016). Recommender Systems meet Finance: A literature review Recommender Systems meet Finance: A literature review. DOI: https://doi.org/10.13140/RG.2.1.1249.2405 ","metadata":{}},{"cell_type":"code","source":"import csv\n\na= [[\"type\",\"value\"],[\"essay_category\",\"Other\"],[\"essay_url\",\"https://www.kaggle.com/bensonwamae/finance-modern-uses-for-artificial-intelligence\"],[\"feedback1_url\",\"https://www.kaggle.com/code/gvyshnya/cybersecurity-ai-in-2022-2023/comments#2334177\"],[\"feedback2_url\",\"https://www.kaggle.com/code/luckypen/actionable-ai-ethics/comments#2334189\"],[\"feedback3_url\",\"feedback_url\"]]\n\nwith open(\"submission.csv\", \"w\") as f:\n    writer = csv.writer(f)\n    writer.writerows(a)","metadata":{"execution":{"iopub.status.busy":"2023-09-02T22:20:10.863853Z","iopub.execute_input":"2023-09-02T22:20:10.865489Z","iopub.status.idle":"2023-09-02T22:20:10.874671Z","shell.execute_reply.started":"2023-09-02T22:20:10.865434Z","shell.execute_reply":"2023-09-02T22:20:10.873249Z"},"trusted":true},"execution_count":null,"outputs":[]}],"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}}