1. Introduction
Nowadays, in the rapidly developing technological era, artificial intelligence (AI), especially on-device and federated learning concepts, are becoming crucial elements of privacy-aware and adaptive smart environments and autonomous systems in the era of 6G connectivity [
1]. Addressing issues with data privacy, real-time decision-making, and effective computation of resource-constrained edge devices is necessary for integrating AI into smart settings [
2].
Our methodology optimizes computing efficiency for real-time decision-making in smart environments while minimizing data transmission using federated learning and edge AI models. Furthermore, it is supported by dimensionality reduction techniques such as PCA and t-SNE, which enhance real-time adaptability and model simplicity for on-device deployment [
3]. In this paper, we follow an analytical approach for real-time anomaly detection in smart environments through efficient data collection, preprocessing, dimensionality reduction, and selection of an optimized machine learning model for on-device implementation [
3,
4]. The special feature of our method is that it uses standardization and normalization techniques to enhance the robustness of on-device AI models aiming to detect missing values or handle incomplete data, while maintaining computational feasibility and low latency of resource-constrained edge devices.
The integration of the implemented methods promises a high rate of accuracy and computational efficiency in detecting fraudulent activities within smart environments, optimizing AI-driven security solutions while maintaining low-latency performance [
5]. Additionally, our implementation is consistent with the demand for adaptive and future proof AI solutions designed for edge computing and on-device security applications [
6]. Apart from emphasizing the algorithm’s technical concept, this creative architecture indicates the importance of applying AI models directly on edge devices for privacy-preserving data processing, real-time analytics, and decentralized decision-making in smart environments. As a result, it is extremely significant for ensuring trust based on artificial intelligence security measures for smart environments, especially in privacy-sensitive applications such as healthcare monitoring, industrial automation, digital transactions, and smart city infrastructures [
7]. Businesses can also decrease losses, reduce risks, boost customer satisfaction, and allocate resources more effectively when they make use of accurate and reliable fraud detection techniques [
8].
We aim not only to provide practical insights and prove the effectiveness of our technique to real-world problems, but also to make significant contributions to the field of privacy-preserving machine learning and edge AI for smart applications [
9,
10]. Our objective is to provide inspiration for innovations in AI-driven smart environments, enabling adaptive on-device intelligence for next-generation applications. Combining federated learning (FL) with reinforcement learning (RL) creates a strong framework that allows effective decision-making in real time while protecting data privacy and encouraging continuous learning and adaptability for future-proofing AI-driven security measures [
11].
Compared to the aforementioned models, our proposed work additionally contains the following features to solve the open problems:
For FL methods for fraud detection (data remains decentralized), but in traditional fraud detection systems, centralized data was required and caused privacy and security issues.
Combination of machine learning and reinforcement learning provides a dual approach to fraud detection with high accuracy and an adaptive RL agent that learns easily.
Dimensionality reduction for visualization and insights with techniques such as PCA and t-SNE, highlighting the separation between fraudulent and non-fraudulent transactions.
Comprehensive model evaluation with multiple metrics (accuracy, precision, recall, F-score) with visualization of training and validation loss.
In other words, this paper addresses the challenge of detecting real-time fraudulent activities in decentralized AI-driven systems using novel and state-of-the-art techniques. We present a comprehensive methodology that integrates three AI techniques, such as machine learning, reinforcement learning, and FL in order to handle a specific and highly unbalanced public dataset typically found in distributed edge computing systems. We developed sophisticated models such as Random Forest and RL agent to evaluate their effectiveness using specific performance. Furthermore, we have integrated common dimensionality reduction techniques, like t-SNE and PCA, for data visualization and analysis in real-time decision-making processes.
Our proposed mechanism includes steps for data acquisition, pre-processing, and model selection and evaluation, ensuring data privacy through FL. The experimental results demonstrate a high accuracy of the Random Forest model, highlighting its ability to effectively classify transactions, identify fraudulent transactions, and contribute to secure, efficient, and intelligent edge computing environments.
The rest of this paper is structured as follows:
Section 2 includes the literature review with the state-of-the-art technologies involved in the proposed model;
Section 3 presents our proposed approach and mechanism;
Section 4 provides the experimental results in diagrams;
Section 5 discusses the benefits, challenges, and limitations of the proposed approach; and finally,
Section 6 concludes the paper giving some potential future directions.
3. Proposed Approach
In this section, we present a sophisticated mechanism that is based on the aforementioned cutting-edge technologies and can detect frauds in credit card transactions (Algorithm 1), such as an online transaction fraud detection system [
28]. The provided mechanism faces credit card fraud detection, since it can separate the transactions using an accurate classifier to identify the fraudulent procedures from the non-fraudulent ones. This mechanism follows the following six steps: data acquisition, data preprocessing, data splitting, exploratory data analysis, model selection and training, and model testing, thanks to the AI methods presented above.
Specifically, the proposed AI mechanism uses a relevant dataset for anomaly detection in smart environments from Kaggle called Credit Card Fraud Detection (creditcard.csv) [
29], which performs methods for cleaning data like handling missing values and outliers. Then, the data is divided into testing, validation, and training sets to optimize model learning for real-time anomaly detection in edge devices. Furthermore, other methods like Principal Component Analysis (PCA) focus on the reduction in dimensionality, assisting in the visualization of the data particularly in resource-constrained edge environments [
3]. Specifically, we used Principal Component Analysis (PCA) to reduce our dataset’s features to two dimensions and identify patterns and the variance analysis while optimizing real-time data processing in smart environments. By providing help to visualize data trends and relationships across transactions, this dimensionality reduction technique is essential for anomaly detection in smart environments, where identifying unusual patterns in sensor data, device activity, or network behavior can improve security and prevent potential system failures.
Furthermore, by visualizing high-dimensional data in a lower-dimensional space, t-Distributed Stochastic Neighbor Embedding (t-SNE) [
30] was utilized to investigate the clustering of transactions in more detail. In contrast to PCA, which emphasizes preserving global structure, t-SNE is excellent in exposing local patterns and highlighting groups within decentralized, on-device AI systems, such as groups of related transactions. This is important for fraud detections since fraudulent transactions tend to create tight, small clusters that might not be immediately apparent in greater dimensions. We offer a more detailed perspective of transaction behaviors by identifying these hidden groups, which facilitates the isolation of possible fraudulent activities.
The main operation of this mechanism is to train a specific machine learning model, Random Forest, in order to identify fraudulent transactions based on features like transaction amount and location and frequency patterns to distinguish them in dynamic, distributed AI environments [
31]. It emphasizes evaluating different models in a validation set before choosing the best performing one for final testing on unseen data. More details about this process are described in Algorithm 1. The proposed approach includes a RL agent additionally to the Random Forest classifier, so as to investigate adaptive decision-making behavior in dynamic transactions. In order to examine how sequential learning strategies react to changing transaction patterns under risk, the RL agent is trained and assessed separately from the Random Forest model. The RL agent offers additional insights into behavioral learning and flexibility, which are especially relevant for future intelligent systems operating in dynamic environments. Moreover, the Random Forest classifier operates as the basic mechanism for fraud detection due to its superior classification performance. A more detailed integration of RL into the federated optimization process could be a potential approach for future research.
| Algorithm 1. Credit Card Fraud Detection Mechanism |
- 1.
Begin - 2.
Data acquisition - 3.
Install libraries: scikit-learn, pandas, tensorflow, tensorflow_federated. - 4.
Create and import a Kaggle API (extended) object for authentication with specific credentials. - 5.
Download a specific dataset from Kaggle (‘creditcard.csv’). - 6.
! Data preprocessing - 7.
Read the csv file into a pandas data frame. - 8.
Define a specific target column from the csv file (‘Class’). - 9.
! Data inspection - 10.
Print initial dataset statistics and unique target values. - 11.
! Handle missing and inconsistent data - 12.
Create a SimpleImputer with strategy ‘mean’ to replace NaN values in features with the mean. - 13.
If the target is categorical (not numerical, 0 or 1), use appropriate encoding techniques. - 14.
Replace negative values in the target variable with 0 and ensure all values are either 0 or 1. - 15.
Replace non-0, 1 values with the mode if any exist. - 16.
! Standardization and normalization - 17.
Create a StandardScaler object and normalize features to have zero mean and unit variance. - 18.
! Data splitting - 19.
Use train_test_split function from sklearn.model_selection to divide data into training, validation, and test sets. - 20.
! Exploratory data analysis - 21.
Select a smaller sample of data for faster visualization. - 22.
Perform PCA and t-SNE using umap library for faster execution to visualize data in a 2D space. - 23.
Use sns.kdeplot from seaborn to analyze distributions of features for fraudulent and non-fraudulent transactions. - 24.
! Model selection and training - 25.
Create a list of candidate models: Random Forest and Logistic Regression. - 26.
Use a loop to iterate through each model in the list and fit it to the training data. - 27.
Train each model using the training data. - 28.
! Model evaluation - 29.
Iterate through each trained model. - 30.
Predict on validation data and calculate accuracy, precision, recall, and F1-score using functions from sklearn.metrics. - 31.
Print the evaluation metrics for each model. - 32.
Compare the evaluation metrics for all models. - 33.
Choose the model with the best overall performance. - 34.
! Model testing and evaluation - 35.
Test the chosen model on unseen test data and evaluate performance metrics. - 36.
Analyze the results using specific metrics and visualizations. - 37.
! Client-side data preparation - 38.
Function preprocess: Define a function to prepare client data for federated learning. - 39.
The data is shuffled, batched, and formatted, ready for distributed model training on each client. - 40.
Function make_federated_data: Create federated datasets by distributing data across multiple clients (using ClientData). - 41.
Simulate decentralized data held by individual clients. - 42.
! Federated Model Definition - 43.
Function create_keras_model: Create a standard Keras model (e.g., with dense layers and softmax activation for binary classification). - 44.
Function model_fn: Define a model setup function compatible with federated learning. - 45.
The create_keras_model is wrapped using tff.learning.models.from_keras_model, enabling it to train across distributed clients without centralizing individual client data. - 46.
! Federated Training Process Setup - 47.
Iterative process definition: Use tff.learning.algorithms.build_weighted_fed_avg to define an iterative federated averaging (FedAvg) process. - 48.
Initialize a model training state. - 49.
Use a stochastic gradient descent (SGD) client optimizer for distributed updates). - 50.
! Federated Training Execution - 51.
Iterate through rounds: Run multiple rounds of training (e.g., for round_num in range(1, 11)). - 52.
For each round: Update the model state by aggregating updates from each client. - 53.
For each round: Print metrics to monitor training progress. - 54.
End.
|
Our work implements FL in the final segment of the code, structuring all components to emphasize data privacy through decentralization, particularly suited for sensitive consumer transaction data. The model begins by preparing client-side data using two primary functions: preprocess and make_federated_data. The preprocess function organizes each client’s data by batching, shuffling, and formatting it to make it ready for model training which is particularly important for detecting patterns in fraud detection models without affecting data privacy.
The make_federated_data function then uses a ClientData object to generate federated datasets for every client. This decentralized data preparation step supports FL’s privacy-preserving objectives by providing that each client retains full control over its data which is crucial in the context of consumer transaction security.
Furthermore, our work defines the federated model using model_fn which uses create_keras_model to build a standard Keras model which initializes the FL model. After that, this model is contained in tff.learning.models.from_keras_model to enable its use within the FL framework and allowing clients to collaboratively enhance the model while protecting privacy and consumer data security.
We use an iterative federated averaging approach to optimize the training process which is initialized using tff.learning.algorithms.build_weighted_fed_avg. This method sets up the training state and controls federated training rounds using SGD optimizer and the model_fn function. Individual model updates from every client are averaged inside each cycle to create a single global update, which minimizes privacy issues and removes the need to transfer raw data. Unlike traditional centralized methods, often seen on platforms like Kaggle, our FL approach preserves on-device privacy essential in consumer transactions.
To carry out this federated training, a loop iterates over several rounds, aggregating client model updates, modifying the global model state, and recording metrics like accuracy to measure progress. This iterative technique allows for continuous model improvement while retaining the client data locally, future-proofing consumer data privacy by protecting sensitive transaction information according to the federated learning principles.
4. Experiments
Our model was tested and evaluated in real time on the Colab Research platform provided by Google, using the Tesla T4 GPU to ensure reproducibility and stable evaluation conditions [
32]. Although the Tesla T4 is optimized for low-latency inference, it provides higher computational resources than typical edge devices deployed in smart environments. The performance evaluation of our model was based on three cases using the known metrics of accuracy, precision, recall, and F-score.
Although the experiments were performed on a cloud-based platform to ensure reproducibility and manage the evaluation settings, the proposed architecture is designed with the perspective of deployment on devices. Specifically, the inference phase of the Random Forest classifier requires less memory and lightweight processing complexity, which makes it better for use on edge devices with limited resources, such as mobile systems or IoT devices. The difference between the real edge hardware-based and cloud-based acceleration technologies is recognized, and a detailed assessment of physical edge devices, including their latency, memory footprint, and energy consumption, is regarded to be a crucial area for further research.
We first visualize the data using Principal Component Analysis (PCA) and t-SNE to provide insight into the patterns of the data (
Figure 1,
Figure 2,
Figure 3 and
Figure 4). In resource-constrained contexts, our model minimizes computational overhead while ensuring effective, real-time fraud detection by utilizing federated learning, dimensionality reduction, and on-device AI acceleration. The PCA plot, which captures variance along the two principal components, displays the distribution of transactions in two dimensions in
Figure 1. As assumed when reducing a high-dimensional dataset to two dimensions, PCA (
Figure 1), captures the general structure of data but is difficult to distinguish between the clusters of fraudulent and non-fraudulent transactions. A more detailed perspective of the local correlations between transactions is then shown by the t-SNE plot (
Figure 2). Finding groups of related transactions is made simpler by t-SNE’s remarkable characteristic of capturing non-linear structures. It is easier to identify suspicious patterns in the dataset, like unusual frequency or transaction amounts that significantly from a typical spending pattern, because it highlights tighter clusters of fraudulent transactions than PCA (
Figure 1).
In contrast,
Figure 3 and
Figure 4 display the same visualizations with color coding based on the transaction class. The colored PCA plot (
Figure 3) highlights more distinct clustering, making the visual separation of fraudulent and non-fraudulent transactions clearer. Fraudulent transactions are frequently scattered at the cluster borders, which indicates possible anomalies or outliers. This visualization is very useful for detecting fraud behavior in consumer transactions.
Similarly, the colored t-SNE plot (
Figure 4) improves upon the uncolored version by emphasizing the fine-grained structure of the data and the relationships between fraudulent and non-fraudulent transactions.
Here the two classes are clearly separated, with fraudulent transactions creating discrete groupings that correspond to consumer behaviors. Both colored versions help us to have a better understanding of fraudulent activity in various consumer base categories, such as sudden spikes in transaction frequency or unusual spending patterns at high-risk merchants that can indicate possible fraud. This is important because the predictive security measures for future-proof consumer applications can be improved.
It should be mentioned that this research only uses t-SNE and PCA for offline exploratory analysis and visualization. Although these methods are not a part of the on-device inference pipeline, they have no impact on the accuracy of classification or the performance of real-time fraud detection. PCA was selected to reduce complexity while preserving overall data variance, although t-SNE was utilized to highlight local transaction clusters. A quantitative comparison with alternative dimensionality reduction techniques, such as Uniform Manifold Approximation and Projection (UMAP) or Linear Discriminant Analysis (LDA), as well as the use of quantitative clustering metrics, is beyond the scope of this study and could be a potential area for future research.
At this point, we define the following meanings: True Positives (TPs) show that fraudulent transactions are correctly detected as fraudulent; True Negatives (TNs) show that non-fraudulent transactions are correctly detected as non-fraudulent; False Positives (FPs) show that non-fraudulent transactions are falsely detected as fraudulent; and False Negatives (FNs) show that fraudulent transactions are not detected and labeled falsely as a non-fraudulent.
Thus, we can estimate the effectiveness of our proposed model using the following predictive performance metrics [
33]:
Accuracy is the number of samples that a classifier correctly detects, divided by the number of all fraudulent and non-fraudulent transactions. It is defined as follows:
- 2.
Precision
Precision is the ratio of predicted fraudulent samples that are correctly labeled as fraudulent. It is defined as follows:
- 3.
Recall
Recall is the ratio of samples that are correctly predicted. It is defined as follows:
- 4.
F-score
F-score is the harmonic an of precision and recall. The closer F-score is to 1, the better it is. It is defined as follows:
Table 1 shows the confusion matrix which represents the actual and the corresponding predicted values in terms of the four values TN, FN, FP, and TP.
In real-world fraud detection, the FN metric is very common because the data is usually unbalanced. In our study, a few fraudulent transactions were wrongly labeled as ‘normal’. This happened because their behavior, such as the money spent or how often they occurred, was very similar to regular shopping habits. This shows the difficult balance between being accurate (precision) and catching all fraud (recall), especially since we did not use special methods to fix the data imbalance. In the future, we may create better features and use specific tools to reduce these missed cases.
As shown in
Figure 5, the accuracy of our proposed model is 0.9996 in all cases using 50, 100, and 200 estimators, respectively. The precision is in the range 0.9744 to 0.9870. The recall is in the range 0.7755 to 0.7959. The F-score is in the range 0.8636 to 0.8764.
It is obvious that the implemented the Random Forest model achieved very high accuracy, consistently exceeding 0.999, indicating a strong ability to correctly classify transactions. However, a deeper look reveals a trade-off between precision and recall. Precision, hovering around 0.97–0.98, suggests that the models capture most flagged transactions as actual fraud (low false positives). However, the recall scores, ranging from 0.77 to 0.80, indicate that the models might miss a portion of actual fraudulent transactions (false negatives). This trade-off requires consideration based on the cost of each type of error. If missing fraudulent transactions is more critical (e.g., financial loss), focusing on improving recall might be necessary. In addition, in
Figure 5 we observe that in case 2 using 100 estimators the metrics are the best compared to the two other cases. Thus, we tested and compared the Random Forest (RF) classifier using 100 estimators with the reinforcement learning agent (RL agent-RLA).
Figure 6 illustrates the performance of the RL agent trained on the CartPole (AI environment) part of the Open AI Gym toolkit over 100 episodes. First, the performance is inconsistent, indicating a lack of stability in developing a reliable strategy. A significant increase around episode 30 shows a brief successful strategy, then the further fluctuations around lower scores reveals the continuous process of exploration and exploitation of the RL agent. We should note that the CartPole environment is chosen as a standard benchmark for evaluating the stability and learning dynamics of the RL agent and does not simulate the fraud detection process.
Table 2 presents the experimental results for the aforementioned evaluation metrics that show low divergence between performance and computational efficiency. As is clearly presented in
Table 2, the Random Forest classifier outperforms the reinforcement learning agent across all metrics. Specifically, although both classifiers show very high accuracy, Random Forest slightly outperforms the RL agent.
In addition, the Random Forest model has a higher precision, meaning it has fewer false positives compared to the RL agent, while it has also a higher recall, indicating it successfully identifies a greater number of actual fraudulent transactions compared to the RL agent. Last but not least, the Random Forest model has a higher F-score, providing a better trade-off between precision and recall than the RL agent.
The observed recall value of about 0.79 suggests that some fraudulent transactions remain undetected even though the recommended Random Forest classifier achieves almost perfect accuracy and precision. These FNs are critical in real-world situations because they result in financial harm and delayed reactions. Therefore, recall is an essential parameter for assessing fraud detection systems.
This trade-off helps the trained classifier’s approach, which puts fewer false alarms ahead of effectively recognizing fraudulent transactions. In fact, in high-risk financial applications, a higher recall could be preferable, but in cases where a large amount of false positives takes away from the user experience, this type of behavior might be acceptable.
By adjusting the classifier’s decision threshold or combining the Random Forest with adaptive decision processes, such as post-classification rules based on reinforcement learning, recall could be increased without significantly reducing precision. Future research on these tactics is thought to be essential, especially when it comes to real-time fraud detection for smart consumer applications.
It should be mentioned that this study’s federated learning setup is not a fully optimized federated deployment, but instead an experiment for decentralized and privacy-preserving model training. During the federated aggregation process, no specific procedures were used to address class imbalance or non-independent and identically distributed data distributions at the client level. Certain edge devices may observe highly skewed local transaction distributions as well as the lack of fraudulent samples in real smart environments. Future research should focus on addressing these scenarios using client-aware weighting, dynamic aggregation methods, or data balancing techniques.
6. Conclusions
In conclusion, a machine learning approach for credit card fraud detection was presented. The procedure was based on a relevant dataset and a thorough cleaning of the data to deal with missing values and outliers. The data were divided into training, validation, and test sets. By using dimensional reduction techniques, valuable insights into the data’s underlying structure were provided, while the core focus remained on training a robust model to distinguish fraudulent transactions.
The implemented model was evaluated on a validation set to ensure optimal performance before the final testing on unseen data. The Random Forest model achieved a very high accuracy, consistently exceeding 0.999, indicating a strong ability to correctly classify transactions. Precision, hovering around 0.97–0.98, recommends that the model captures most flagged transactions as actual fraud (low false positives). However, the recall scores, ranging from 0.77 to 0.80, indicate that the model might miss a portion of actual fraudulent transactions (false negatives). Furthermore, compared to the RL agent, the proposed RF classifier achieves better scores in terms of accuracy, precision, recall, and F-score.
For future work, there are some perspectives that could improve our proposed model, especially in terms of the false negatives. These perspectives include feature engineering, hyperparameter tuning, and Convolutional Neural Network (CNN) integration. Feature engineering can be used to develop new features from existing ones. For example, in the dataset used in the proposed approach, the transaction amount could be divided by the average transaction amount, creating a new feature for performance evaluation. Hyperparameter tuning can be used to potentially optimize the performance of our proposed model. Finally, some more advanced and sophisticated machine and deep learning models, such as CNN, can be integrated into our model for a potentially better accuracy level, especially for application in data with more complex patterns.