A Blockchain-Based Collaborative Analysis Method for Federated Random Forest Electricity Data
By employing a blockchain-based federated random forest approach, the problem of secure collaboration of structured data in power data analysis is solved, achieving high-accuracy model collaborative training and user privacy protection, thus ensuring the security and privacy of power data.
Patent Information
- Application Number
- CN202211562855.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-07
- Publication Date
- 2025-12-02
- Estimated Expiration
- 2042-12-07
AI Technical Summary
Existing technologies face challenges in secure collaborative analysis of structured data in power data analysis, particularly in protecting privacy data and ensuring the security of data aggregation. Furthermore, existing solutions primarily focus on unstructured data, lacking a blockchain-based collaborative analysis solution for structured power data.
By employing a blockchain-based federated random forest approach, secure collaborative data analysis is achieved through key generation, initial node model deployment, local CART decision tree training, competitive block uploading and message broadcasting, new block generation, decision tree reading, decryption, and random forest aggregation, combined with two-layer encryption and smart contracts.
It achieves high-accuracy model co-training and good user privacy protection, preventing errors and malicious tampering during random forest merging, and ensuring the security and privacy of power data.
Smart Images

Figure CN116186754B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of federated learning and aggregation algorithms, specifically a distributed federated random forest aggregation method for blockchain. Background Technology
[0002] Currently, the power industry is experiencing explosive growth in data, and power data analysis plays an indispensable supporting role in green environmental protection. It is crucial for reducing carbon emissions and achieving carbon neutrality and development, analyzing the rationality of electricity consumption by various enterprises, and green electricity trading. However, these new data-driven tasks involve a large amount of critical enterprise data and user privacy data. How to achieve collaborative analysis of power-related data while ensuring the security of various types of data has become one of the most important research challenges. Currently, the optimal technology for multi-party data collaborative analysis is federated learning, but most other approaches focus on deep learning. This is because the parameters of neural network training models are additive; by weighted summing of models trained by multiple participants, global model aggregation can be easily achieved. However, in actual power-related data analysis, structured data is often encountered, and there are not many business analysis models based on machine learning. Therefore, it is essential to implement a federated machine learning model for power data. Random forest is a representative machine learning algorithm that contains multiple decision trees as classifiers, and its output class is determined by the mode of the classes output by individual trees. It is widely used in classification and regression tasks for power data. On the other hand, since new power data-driven businesses involve multiple industries, there is no distinction in status among the participants. As a peer-to-peer structure, the introduction of blockchain technology is essential to establishing mutual trust.
[0003] Challenges exist in secure collaborative analysis of power data. Yin et al. proposed a secure sharing scheme combining blockchain and federated deep learning, using function encryption to ensure the security of on-chain data. However, this scheme cannot handle the structured data, which constitutes the largest portion of power-related data. Ahmed et al. proposed an energy-saving security system that aggregates data from the IoT layer using fuzzy algorithms, optimizes edge nodes and servers, and integrates blockchain within cloud servers to provide data protection. However, they did not consider the security and privacy of data aggregation.
[0004] In summary, the problems with existing technologies are: 1) When analyzing power-related data, we often face structured data, but most existing solutions focus on business analysis solutions for unstructured data; 2) There is currently no structured power data collaborative analysis solution based on blockchain. Uploading data directly to the blockchain poses a risk of privacy leakage, and security measures need to be implemented for the data on the chain. Summary of the Invention
[0005] This invention overcomes the shortcomings of existing technologies and provides a new method for fine-grained assessment of rural population hollowing-out. The objective of this invention is achieved through the following technical solution:
[0006] This invention provides a blockchain-based collaborative analysis method for federated random forest electricity data, comprising:
[0007] S1: Generate key;
[0008] S2: The initial node publishes the initial model;
[0009] S3: Train a local CART decision tree model;
[0010] S4: Competing blocks are added to the chain and the message is broadcast;
[0011] S5: Generate a new block;
[0012] S6: Decision tree reading;
[0013] S7: Decrypt;
[0014] S8: Random Forest Aggregation;
[0015] S9: Parameter update;
[0016] S10: The central aggregation node publishes the final random forest model, which participants can use to analyze local business power data.
[0017] Preferably, in step S1, the key management authority generates a public-private key pair PK for encryption for each user i. i SK i All public keys are published to all users; symmetric encryption keys are generated by the users themselves and stored on the blockchain in the form of public key encryption, and nodes holding the corresponding private keys can obtain the symmetric encryption keys.
[0018] Preferably, in step S2, the initial random forest model and model parameters are provided, including the Gini threshold and the number of randomly selected features; the initial random forest model and model parameters are written into the genesis block and broadcast to all nodes.
[0019] Preferably, in step S4, each node will execute a proof-of-work mechanism to compete for the right to generate a new block. Before being added to the blockchain, each node will test the decision tree model using a public test set. If the accuracy of the test set exceeds the contribution threshold, it will be eligible to be added to the blockchain and will generate a block according to the first-come, first-served principle. When a node obtains the right to generate a new block, it will treat its candidate block as a new block and broadcast it to all nodes.
[0020] Preferably, in step S5, after broadcasting the new block to the blockchain network and obtaining the approval of all nodes, a new block will be officially created.
[0021] Preferably, in step S6, when user i uploads the CART decision tree to the blockchain, the participants can jointly negotiate the designated trusted node to perform aggregation calculation. The aggregation node will read the data from the block, store it in the aggregation node, and then perform the decryption operation.
[0022] Preferably, in step S7, a specific node decrypts the double-layer onion encryption method using its own private key: in the second layer of encryption, it encrypts the symmetric encryption key K with its own public key to obtain the symmetric encryption key K used to decrypt the first layer of encryption; it then decrypts the decision tree T encrypted with the symmetric encryption key K in the first layer of encryption of the double-layer onion encryption method using the symmetric encryption key to obtain the decision tree T used to aggregate the random forest.
[0023] Preferably, in step S8, after decrypting the decision tree T, the aggregation node will aggregate the CART decision tree.
[0024] Preferably, in step S9, after the aggregation node decrypts the CART decision tree and aggregates it into a random forest, the smart contract calculates the out-of-bag (OOB) error rate of the random forest, which is calculated as follows:
[0025] For each unselected sample, calculate its classification using the CART decision tree as an OOB sample. Then, use a simple majority vote as the classification result for that sample; finally, use the ratio of misclassified samples to the total number of samples as the OOB misclassification rate of the random forest.
[0026] D i T represents the actual training sample set used. i Let H be the base classifier of the decision tree, y be the prediction result obtained after sample x passes through the decision tree, and Y be the prediction result set. oob () represents out-of-package prediction for the sample, and we have:
[0027]
[0028] The out-of-package estimate of the generalization error of the random forest is:
[0029]
[0030] Where D represents the training set, the aggregation node adjusts the Gini index threshold by comparing the OOB misclassification rate and the performance of the random forest model and then distributes it to each node. The node re-builds the CART decision tree based on the newly released Gini index threshold and the number of features Y, encrypts it, and then uploads it to the blockchain; this process is repeated until the random forest model achieves the expected results.
[0031] The present invention has the following advantages over the prior art:
[0032] 1. Excellent model accuracy: After the random forest is aggregated through a smart contract, the smart contract will evaluate the model performance of the random forest model. The co-training of the random forest model will be iterated multiple times until the final model accuracy reaches the expected level.
[0033] 2. Excellent User Privacy Protection: This invention utilizes the tamper-proof mechanism of blockchain to prevent errors and malicious tampering during random forest merging. Double-layer encryption and smart contracts are used to hide user-uploaded data among numerous participants, protecting the privacy of user training data. Attached Figure Description
[0034] The present invention will be further described with reference to the accompanying drawings, but the embodiments in the drawings do not constitute any limitation on the present invention. For those skilled in the art, other drawings can be obtained based on the following drawings without creative effort.
[0035] Figure 1 This is a flowchart of a blockchain-based collaborative analysis method for federated random forest power data.
[0036] Figure 2 This is a framework diagram of the blockchain-based federated random forest scheme of this invention. Detailed Implementation
[0037] The following detailed description of a blockchain-based federated random forest power data collaborative analysis method, with reference to specific embodiments, is provided. These embodiments are for comparison and explanation purposes only, and the present invention is not limited to these embodiments.
[0038] like Figure 1 and Figure 2 As shown, this invention provides a blockchain-based collaborative analysis method for federated random forest electricity data, comprising:
[0039] This invention provides a blockchain-based collaborative analysis method for federated random forest electricity data, comprising:
[0040] S1: Generate key;
[0041] The key management authority generates a public-private key pair (PK) for encryption for each user i or node i. i SK i The system publishes all public keys to all users. Symmetric encryption keys are generated by the users themselves and stored on the blockchain using public key encryption. Nodes holding the corresponding private keys can obtain the symmetric encryption keys.
[0042] S2: The initial node publishes the initial model;
[0043] The initial node is typically the initiator of collaborative power data analysis, such as the power management department of a central city. Before collaborative training, the initial node creates a genesis block, uses a public dataset to train an initial random forest model, and then writes the initial random forest model and its parameters (Gini threshold, number of randomly selected features) into the genesis block and broadcasts it to all nodes.
[0044] S3: Train a local CART decision tree model;
[0045] Each node downloads the initial random forest model from the initial block and sends it to its associated device. The device trains a local CART decision tree model using its local data and published model parameters, partitioning the local data using the Gini index, assuming that the proportion of samples in the k-th class in the current sample set D is P. k = (1,2,…,|y|), then the Gini index of set D is:
[0046]
[0047] The Gini index of feature attribute a can be expressed as:
[0048]
[0049] In the set of all candidate attributes A, the attribute that minimizes the Gini index after splitting is selected as the optimal splitting attribute, i.e., a = argmin Gini_index(D, a). Training stops when the Gini index in the dataset is less than the Gini threshold. Then, the local model is sent to its associated node. The node validates the model, and if validation is successful, it writes the model into the candidate block.
[0050] S4: Competing blocks are added to the chain and the message is broadcast;
[0051] Each node will use a Proof-of-Work (PoW) mechanism to compete for the right to generate new blocks. Before being added to the blockchain, each node will test its decision tree model using a public test set. If the accuracy of the test set exceeds a contribution threshold (the threshold filters out models that contribute to improving the accuracy of the overall model, and can be manually set), it will be eligible to be added to the blockchain and will generate blocks according to a first-come, first-served principle. Assuming node 1 wins the right to generate a new block, node 1 will treat its candidate block as a new block and broadcast it to all nodes.
[0052] S5: Generate a new block;
[0053] A new block is officially created after it is broadcast to the blockchain network and approved by all nodes. To ensure that the CART decision tree model uploaded by users to the blockchain is only available to specific nodes (i.e., aggregation nodes), a two-layer encryption scheme is used. The first layer of encryption uses classic symmetric encryption, directly encrypting the decision tree with a locally generated symmetric encryption key. The second layer uses the public keys of multiple specific nodes to encrypt the symmetric encryption key separately. Users store the symmetrically encrypted decision tree and multiple ciphertexts (each encrypted with a separate symmetric encryption key using multiple public keys) together on the blockchain.
[0054] S6: Decision tree reading;
[0055] When a user uploads a CART decision tree to the blockchain, the participants can jointly negotiate a designated trusted node to perform aggregate calculations. The aggregate node will read the data from the block, store it in the aggregate node, and then perform the decryption operation.
[0056] S7: Decrypt;
[0057] A specific node i uses its own private key SK i Decrypting the double-layer onion encryption method involves using the user's own public key to perform a PK operation in the second layer of encryption. i Encrypt the symmetric encryption key K to obtain the symmetric encryption key K used to decrypt the first layer of encryption; use the symmetric encryption key to decrypt the decision tree T encrypted with the symmetric encryption key K in the first layer of the double-layer onion encryption method to obtain the decision tree T used to aggregate the random forest.
[0058] S8: Random Forest Aggregation;
[0059] After decrypting the CART decision tree, the aggregation node will aggregate the CART decision trees. Assume the aggregation contains n CART decision trees {T1, T2, ..., T...}. n}, where T i (x) represents the output on example x. Each CART decision tree T i From the category tag set {C1, C2, ... C n A label is predicted from T. The combination strategy in this paper is to use a voting method. i The predicted output on sample x is represented as an m-dimensional vector. in It is T i In category label C j The output above. The final prediction result of the random forest is obtained by absolute majority voting, which can be expressed as:
[0060]
[0061] k and i are both indexes, m is because there is an m-dimensional vector, n is the number of n decision trees, and T(x) represents the output prediction result of the decision trees; that is, if a certain category label receives more than half of the votes, the final prediction result of the random forest is that label; otherwise, the prediction is rejected.
[0062] S9: Parameter update;
[0063] After the aggregation node decrypts the CART decision trees and aggregates them into a random forest, the smart contract calculates the out-of-bag (OOB) error rate of the random forest. This is done as follows: for each unselected sample, the classification of the decision tree for that sample as an OOB sample is calculated. Then, a simple majority vote is used as the classification result for that sample; finally, the ratio of misclassified samples to the total number of samples is used as the OOB misclassification rate of the random forest. The OOB misclassification rate is an unbiased estimate of the generalization error of the random forest, and its result approximates that of K-fold cross-validation, which requires a large amount of computation. Assume D... i Let H represent the actual training sample set used. oob (x) represents the out-of-bag prediction for sample x, that is, only considering the predictions of CART decision trees that were not trained on x, and we have:
[0064]
[0065] The out-of-package estimate of the generalization error of the random forest is:
[0066]
[0067] The aggregation node adjusts the Gini index threshold by comparing the OOB misclassification rate and the performance of the random forest model before distributing it to each node. Each node then rebuilds the CART decision tree based on the newly released Gini index threshold and the number of features Y, encrypts it, and uploads it to the blockchain. This process is repeated until the random forest model achieves the expected results.
[0068] S10: The central aggregation node publishes the final random forest model, which is then used to analyze local business power data. Business departments can use the final random forest model to perform classification or regression tasks on power data, further optimizing the power business layout and improving the efficiency of power resource utilization.
[0069] In one embodiment, a municipal administrative department decides to collect daily electricity consumption data from residents of various subdistricts for collaborative analysis. Directly providing users' electricity consumption data may infringe on their privacy. To ensure the data and privacy security of users in each subdistrict, each subdistrict uploads its trained decision tree to the blockchain locally, encrypts the decision tree using a two-layer encryption mechanism, and securely aggregates it through smart contracts to achieve the classification and regression tasks of structured electricity-related data. The specific implementation process is as follows:
[0070] 1. The key management authority generates a public-private key pair for encryption for each participant and publishes all public keys to all nodes. The symmetric encryption key is generated by each participant and stored on the blockchain in the form of public key encryption. The participant holding the corresponding private key can obtain the symmetric encryption key.
[0071] 2. The municipal administrative department, as the initial node, creates a genesis block before collaborative training, uses a public dataset to train an initial random forest model, and then writes the initial random forest model and model parameters into the genesis block and broadcasts it to all participating nodes.
[0072] 3. Each subdistrict office downloads an initial random forest model from the initial block and sends it to its associated device. The device trains a local CART decision tree model using local resident data and published model parameters. The local model is then sent to its associated node. The node verifies the model; if successful, it writes the model into the candidate block using double-layer onion encryption.
[0073] 4. Each node will execute a Proof-of-Work (PoW) mechanism to compete for the right to generate new blocks. Before being added to the blockchain, each node will test its decision tree model using a public test set. If the accuracy of the test set exceeds a contribution threshold (the threshold filters out models that contribute to improving the accuracy of the overall model; this threshold can be manually set), it will be eligible to be added to the blockchain and will generate blocks according to a first-come, first-served principle. Assuming node 1 wins the right to generate a new block, node 1 will treat its candidate block as a new block and broadcast it to all nodes.
[0074] 5. Node 1 broadcasts the new block to the blockchain network, and after obtaining the approval of all nodes, it will officially create a new block.
[0075] 6. When the number of decision tree models submitted by participants to the blockchain network reaches n, the execution conditions of the smart contract will be triggered. Participants can jointly negotiate a designated trusted node for aggregation computation. The smart contract will evaluate the performance of the random forest model, adjust parameters to allow the node to rebuild the decision tree, encrypt it, and then upload it to the blockchain network. The collaborative training of the random forest model will be iterated multiple times until the final model accuracy reaches the expected level.
[0076] 7. The municipal administrative department will publish the final random forest model, and each subdistrict office can analyze the electricity data of its residents based on the published model.
[0077] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit the scope of protection of the present invention. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the essence and scope of the technical solutions of the present invention.
Claims
1. A blockchain-based collaborative analysis method for federated random forest electricity data, characterized in that, include: S1: Generate key; S2: The initial node publishes the initial model; S3: Train a local CART decision tree model; S4: Competing blocks are added to the chain and the message is broadcast; S5: Generate a new block; S6: Decision tree reading; S7: Decrypt; S8: Random Forest Aggregation; S9: Parameter update; S10: The central aggregation node publishes the final random forest model; In steps S7-S8, after the aggregation node decrypts the CART decision tree and aggregates it into a random forest, the smart contract will calculate the out-of-bag (OOB) error rate of the random forest. The calculation method is as follows: For each unselected sample, calculate its classification as an OOB sample using the CART decision tree, and then use a simple majority vote as the classification result for that sample; finally, use the ratio of misclassified samples to the total number of samples as the OOB misclassification rate of the random forest. This represents the actual training sample set used. Let be the base classifier of the decision tree, y be the prediction result obtained after sample x passes through the decision tree, and Y be the prediction result set. Let be the base classifier of the decision tree. To represent out-of-bag predictions for a sample, we have: The out-of-package estimate of the generalization error of the random forest is: Where D represents the training set, the aggregation node adjusts the Gini index threshold by comparing the OOB misclassification rate and the performance of the random forest model and then distributes it to each node. The node re-builds the CART decision tree based on the newly released Gini index threshold and the number of features Y, encrypts it, and then uploads it to the blockchain; this process is repeated until the random forest model achieves the expected results. In S6, when user i uploads the CART decision tree to the blockchain, the participants can jointly negotiate the designated trusted node to perform aggregation calculation. The aggregation node will read the data from the block, store it in the aggregation node, and then perform the decryption operation. In step S8, after decrypting the decision tree T, the aggregation node will aggregate the CART decision tree.
2. The blockchain-based collaborative analysis method for federated random forest power data as described in claim 1, characterized in that, In step S1, the key management authority generates a public-private key pair for encryption for each user i. , All public keys are published to all users; symmetric encryption keys are generated by the users themselves and stored on the blockchain in the form of public key encryption, and nodes holding the corresponding private keys can obtain the symmetric encryption keys.
3. The blockchain-based collaborative analysis method for federated random forest power data as described in claim 1, characterized in that, In step S2, the initial random forest model and model parameters are prepared, including the Gini threshold and the number of randomly selected features. The initial random forest model and model parameters are written into the genesis block and broadcast to all nodes.
4. The blockchain-based collaborative analysis method for federated random forest power data as described in claim 1, characterized in that, In S4, each node will execute a proof-of-work mechanism to compete for the qualification to generate new blocks. Before going on the chain, each node will use a public test set to test the decision tree model. If the accuracy of the test set exceeds the contribution threshold, it will be qualified to go on the chain and generate blocks according to the first-come, first-served principle. When a node obtains the right to generate new blocks, it will treat its candidate blocks as new blocks and broadcast them to all nodes.
5. The blockchain-based collaborative analysis method for federated random forest power data as described in claim 1, characterized in that, In step S5, the new block is broadcast to the blockchain network and, after being recognized by all nodes, the new block is officially created.
Citation Information
Patent Citations
User electricity stealing behavior detection method and system based on alliance chain and federal learning
CN115270145A
Federal random forest model modeling method based on block chain
CN115375425A