Random forest training method and device based on directed association relationship of sample features
By constructing a directed acyclic graph (DAG) and extracting directed association paths to train decision trees, the problem of insufficient generalization ability in existing decision tree training methods is solved, and the overall training effect and prediction accuracy of decision trees are improved.
Patent Information
- Application Number
- CN202210741054.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-27
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2042-06-27
AI Technical Summary
Existing decision tree training methods only consider the data purity of the current part of the training samples when dividing feature attributes, resulting in weak generalization ability of the decision tree and poor overall effect.
Through structural learning based on the full amount of training samples and sample features, a directed acyclic graph (DAG) is constructed to extract directed association paths to train decision trees, and integrate global knowledge to improve the decision tree training effect.
By integrating global knowledge, the training effect of the decision tree is improved, and its generalization ability and prediction accuracy are enhanced.
Smart Images

Figure CN115034330B_ABST
Abstract
Description
Technical Field
[0001] The embodiments of this specification relate to the field of artificial intelligence technology, and specifically, to a random forest training method and a random forest training device based on a directed association relationship of sample features. Background Art
[0002] Decision tree is a common prediction model in machine learning, which represents a mapping relationship between object attributes and object values. Each internal node represents a test on an attribute, each branch represents a test output, and each leaf node represents a category.
[0003] Random forest is a classification model composed of multiple decision trees. Since the classification results of random forest are obtained by combining the classification results of multiple decision trees, random forest can solve the problem of weak generalization ability of decision trees.
[0004] At present, a greedy algorithm can be used for training decision trees. The node segmentation attributes of each layer are selected in order from top to bottom according to the tree structure of the decision tree until the leaf node of the last layer is reached, thereby completing the construction of the decision tree. Summary of the invention
[0005] In view of the above, the embodiments of this specification provide a random forest training method and a random forest training device based on a directed association relationship of sample features. Through the technical solution of the embodiments of this specification, a DAG is obtained by learning based on all training samples and all sample features, so that the DAG incorporates the global knowledge of the training samples, so that the decision tree trained by using the DAG is also obtained based on the global knowledge of the training samples, thereby improving the training effect of the decision tree as a whole.
[0006] According to one aspect of an embodiment of the present specification, a random forest training method based on a directed association relationship of sample features is provided, comprising: performing structural learning on sample features based on a plurality of labeled training samples to obtain a DAG consisting of sample features and sample labels of the plurality of training samples as nodes; extracting a directed association path consisting of sample feature nodes from the DAG according to the sample label nodes in the DAG, wherein each sample feature node in the directed association path is sequentially and directedly connected; training a decision tree based on the extracted directed association path; and constructing a random forest based on the trained decision tree.
[0007] According to another aspect of the embodiments of this specification, a random forest training device based on a directed association relationship of sample features is also provided, including: a DAG learning unit, which performs structural learning on sample features based on multiple labeled training samples to obtain a DAG composed of sample features and sample labels of the multiple training samples as nodes; a path extraction unit, which extracts a directed association path composed of sample feature nodes from the DAG according to the sample label nodes in the DAG, and each sample feature node in the directed association path is sequentially and directedly connected; a decision tree training unit, which trains a decision tree based on the extracted directed association path; and a random forest construction unit, which constructs a random forest based on the trained decision tree.
[0008] According to another aspect of the embodiments of this specification, an electronic device is also provided, comprising: at least one processor, a memory coupled to the at least one processor, and a computer program stored on the memory, wherein the at least one processor executes the computer program to implement any of the random forest training methods based on directed association relationships of sample features as described above.
[0009] According to another aspect of the embodiments of this specification, a computer-readable storage medium is also provided, which stores a computer program, and when the computer program is executed by a processor, the random forest training method based on the directed association relationship of sample features as described above is implemented.
[0010] According to another aspect of the embodiments of this specification, a computer program product is also provided, including a computer program, which, when executed by a processor, implements any of the random forest training methods based on directed association relationships of sample features as described above. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] A further understanding of the nature and advantages of the embodiments of the present specification can be achieved by referring to the following drawings. In the drawings, similar components or features may have the same reference numerals.
[0012] Figure 1 A flowchart of an example of a random forest training method based on a directed association relationship of sample features according to an embodiment of this specification is shown.
[0013] Figure 2 A schematic diagram showing an example of a DAG in an anti-fraud scenario according to an embodiment of this specification.
[0014] Figure 3 A schematic diagram showing an example of an adjacency matrix W according to an embodiment of the present specification.
[0015] Figure 4A flowchart of an example of a method for executing each round of training process according to an embodiment of this specification is shown.
[0016] Figure 5 A flowchart of an example of a decision tree training method for each directed association path according to an embodiment of this specification is shown.
[0017] Figure 6 A schematic diagram showing an example of a decision tree constructed corresponding to directed association paths according to an embodiment of this specification is shown.
[0018] Figure 7 A block diagram showing an example of a random forest training device based on a directed association relationship of sample features according to an embodiment of this specification.
[0019] Figure 8 A block diagram showing an example of a decision tree training unit according to an embodiment of this specification.
[0020] Fig. 9 A block diagram showing an example of a decision tree training module according to an embodiment of this specification.
[0021] Fig.10 A block diagram of an electronic device for implementing a random forest training method based on a directed association relationship of sample features according to an embodiment of the present specification is shown. DETAILED DESCRIPTION
[0022] The subject matter described herein will be discussed below with reference to example implementations. It should be understood that the discussion of these implementations is only to enable those skilled in the art to better understand and implement the subject matter described herein, and is not a limitation of the scope of protection, applicability or examples set forth in the claims. The functions and arrangements of the elements discussed may be changed without departing from the scope of protection of the embodiments of this specification. Various processes or components may be omitted, substituted or added to each example as needed. In addition, the features described relative to some examples may also be combined in other examples.
[0023] As used herein, the term "including" and its variations represent open terms, meaning "including but not limited to". The term "based on" means "based at least in part on". The terms "one embodiment" and "an embodiment" mean "at least one embodiment". The term "another embodiment" means "at least one other embodiment". The terms "first", "second", etc. may refer to different or the same objects. Other definitions may be included below, whether explicit or implicit. Unless the context clearly indicates otherwise, the definition of a term is consistent throughout the specification.
[0024] Decision tree is a common prediction model in machine learning, which represents a mapping relationship between object attributes and object values. Each internal node represents a test on an attribute, each branch represents a test output, and each leaf node represents a category.
[0025] Random forest is a classification model composed of multiple decision trees. Since the classification results of random forest are obtained by combining the classification results of multiple decision trees, random forest can solve the problem of weak generalization ability of decision trees.
[0026] At present, a greedy algorithm can be used for training decision trees. The node segmentation attributes of each layer are selected in order from top to bottom according to the tree structure of the decision tree until the leaf node of the last layer is reached, thereby completing the construction of the decision tree.
[0027] However, in the greedy algorithm, when dividing the feature attributes for each layer, only the case where the data purity of the current part of the training samples is the highest is considered, and the feature attribute with the highest data purity is used as the split point. In this way, each time the feature attribute is divided, only a part of the training samples and sample features are considered, which is one-sided and cannot be considered from the overall perspective, resulting in poor overall effect of the trained decision tree.
[0028] In view of the above, the embodiments of this specification provide a random forest training method and device based on a directed association relationship of sample features. In the random forest training method, structural learning for sample features is performed based on multiple labeled training samples to obtain a DAG consisting of sample features and sample labels of the multiple training samples as nodes; a directed association path consisting of sample feature nodes is extracted from the DAG according to the sample label nodes in the DAG, and each sample feature node in the directed association path is sequentially and directedly connected; a decision tree is trained based on the extracted directed association path; and a random forest is constructed based on the decision tree obtained through training. Through the technical solution of the embodiments of this specification, a DAG is obtained by learning based on all training samples and all sample features, so that the DAG integrates the global knowledge of the training samples, so that the decision tree trained using the DAG is also obtained based on the global knowledge of the training samples, thereby improving the training effect of the decision tree as a whole.
[0029] The following is an explanation of the random forest training method and random forest training device based on the directed association relationship of sample features provided in the embodiments of this specification in conjunction with the accompanying drawings.
[0030] Figure 1 A flowchart of an example 100 of a random forest training method based on a directed association relationship of sample features according to an embodiment of the present specification is shown.
[0031] like Figure 1As shown, at 1100, structure learning for sample features is performed based on a plurality of labeled training samples to obtain a DAG (Directed Acyclic Graph).
[0032] In the embodiment of the present specification, the labeled multiple training samples may include a sample feature part and a sample tag part, and the multiple training samples used for structure learning may be a training sample set including several training samples. In one example, the training samples may include data of anti-fraud scenarios, and the anti-fraud scenarios may include multiple types of scenarios, such as O2O (Online To Offline) anti-fraud scenarios, money collection code anti-fraud scenarios, etc. The sample features of training samples under different types of anti-fraud scenarios may be different. For example, the sample features under the O2O anti-fraud scenario may include the transaction amount, the number of online orders on the same day, the amount of online orders on the same day, the average transaction amount of online orders in the last n days, the average number of transactions of online orders in the last n days, etc. The sample features under the money collection code anti-fraud scenario may include money collection code information, money collection amount, money collection amount on the same day, number of money collection on the same day, the average amount of money collected by the money collection code in the last n days, and the average number of money collection by the money collection code in the last n days. Wherein, n is a positive integer greater than 1.
[0033] The training samples used in the embodiments of this specification may include data of various types of anti-fraud scenarios, and the data in the anti-fraud scenarios may include transaction data, and the transaction data may include transaction amount, transaction amount of the day, number of transactions of the day, average transaction amount of the last n days, average number of transactions of the last n days, risk score, etc., so that the sample features of the training samples in the anti-fraud scenarios may include transaction amount, transaction amount of the day, number of transactions of the day, average transaction amount of the last n days, average number of transactions of the last n days, risk score, etc. Among them, the risk score can be used to measure the degree of risk.
[0034] In the embodiment of the present specification, the DAG may be composed of sample features and sample labels in the training sample as nodes. Each sample feature may constitute a sample feature node, and each sample label may constitute a sample label node. In the DAG, there may be a directed connection between two nodes, and the existence of a directed connection between two nodes indicates that there is an association relationship between the objects represented by the two nodes (i.e., sample features or sample labels). Each directed connection has a direction, and the direction of each directed connection is from the node at one end of the directed connection to the node at the other end.
[0035] Figure 2 FIG. 1 is a schematic diagram showing an example of a DAG in an anti-fraud scenario according to an embodiment of this specification. Figure 2As shown, the nodes in DAG include sample feature nodes and sample tag nodes, and each sample feature node represents a sample feature. Sample feature node 1 represents the transaction amount, sample feature node 2 represents the transaction amount of the day, sample feature node 3 represents the risk score, sample feature node 4 represents the number of transactions of the day, sample feature node 5 represents the average transaction amount of the last 3 days, and sample feature node 8 represents the average number of transactions of the last 3 days. Node 9 is a sample tag node, which is used to represent the tag "fraud". The connection between two nodes in DAG is a directed connection, and the direction of the arrow of each connection is the direction of the directed connection.
[0036] In one example, the directionality of a directed connection can represent a causal relationship, where the node at the beginning of the directed connection represents the cause, and the node at the end to which the directed connection points represents the effect. That is, the sample feature or sample label represented by the node to which the directed connection points can be obtained because of the sample feature represented by the node at the beginning of the directed connection. Figure 2 For example, sample feature node 1 points to sample feature node 3 through a directed connection, then the risk score represented by sample feature node 3 as the tail end of the directed connection can be obtained because of the transaction amount represented by sample feature node 2 as the starting end of the directed connection.
[0037] In the embodiments of the present specification, the structural learning used for sample features may be Bayesian network structural learning. Through Bayesian network structural learning, the sample features in the training samples and the association between sample labels can be learned based on given training samples, and the learned associations can be presented in the form of DAG.
[0038] DAG can be derived through the adjacency matrix W, which can be used to represent the association between each sample feature. W∈{0,1} d×d , that is, the adjacency matrix W can be composed of weight values 0 and 1, d represents the number of rows and columns of the adjacency matrix W, for the adjacency matrix W, each row in the d rows can represent a sample feature, each column in the d columns can also represent a sample feature, the sample features represented by the d rows and d columns are the same, and the sample features represented by the i-th column and the i-th row are the same, where i is a positive integer not greater than d. In the adjacency matrix W, the weight value W ij =1 indicates that sample feature i is associated with sample feature j, and the node corresponding to sample feature i points to the node corresponding to sample feature j. ij =0 means that there is no correlation between sample feature i and sample feature j.
[0039] Figure 3 FIG. 2 is a schematic diagram showing an example of an adjacency matrix W according to an embodiment of the present specification. Figure 3 The adjacency matrix shown is used to derive Figure 2 For the DAG shown in the adjacency matrix W, each row is used to represent a sample feature, and each column is also used to represent a sample feature. Among them, ① represents the transaction amount, ② represents the transaction amount of the day, ③ represents the risk score, ④ represents the number of transactions on the day, ⑤ represents the average transaction amount in the past 3 days, ⑧ represents the average number of transactions in the past 3 days, and ⑨ represents the sample label "fraud". The weight values in the adjacency matrix W include 0 and 1. The weight value 1 can be used to represent a directed connection between two objects (i.e., sample features or sample labels) that intersect at the weight value, and in the two objects, the node corresponding to the object represented by the intersecting row points to the node corresponding to the object represented by the intersecting column. For example, the weight value W 13 =1 is used to indicate that there is a directed connection between sample feature 1 and sample feature 3, and sample feature node 1 corresponding to sample feature 1 points to sample feature node 3 corresponding to sample feature 3.
[0040] In an example of deriving DAG from the adjacency matrix, each sample feature and sample label in the adjacency matrix can be represented by a corresponding node, and then, it is checked whether there is a correlation between each sample feature and sample label in the adjacency matrix, that is, the corresponding weight value W between two sample features or between a sample feature and a sample label is checked. ij Is it equal to 1. When it is equal to 1, it can be determined that the nodes corresponding to the two sample features are associated, or the sample feature and the node corresponding to the sample tag are associated.
[0041] In addition, the objects (i.e., sample features or sample labels) represented by the rows and columns that intersect at the position of the weight value in the adjacency matrix can be determined, and the direction of the directed connection between the nodes corresponding to the two objects can be further determined, and then the two nodes corresponding to the two objects can be connected in a directed connection manner according to the direction. After all the associated sample features and sample labels in the adjacency matrix are presented in a directed connection manner between the corresponding nodes, the resulting node directed connection graph is the DAG.
[0042] Based on the relationship between DAG and adjacency matrix, the adjacency matrix can be calculated before constructing DAG.
[0043] In an example of finding the adjacency matrix W, based on the linear relationship between the sample features of the training samples, the reconstruction loss can be obtained as:
[0044]
[0045] Where l represents the reconstruction loss, X represents the sample features, n represents the number of samples, and F represents the Frobenius norm (i.e., F-norm). To minimize the above reconstruction loss, the structure graph corresponding to the adjacency matrix W is a directed acyclic graph. This is equivalent to solving the following equation to minimize F(W) and ensure that the structure graph corresponding to the adjacency matrix W is a directed acyclic graph.
[0046]
[0047]
[0048] Among them, λ represents the penalty term coefficient, R d×d Represents a continuous space that satisfies a directed acyclic graph. On the basis that the structure graph corresponding to the adjacency matrix W is a directed acyclic graph, the above formula F(W) is minimized, so that the adjacency matrix W can be obtained.
[0049] Back to Figure 1 ,After constructing the DAG, at 1200, directed association paths can be extracted from the DAG based on the sample labeled nodes in the DAG.
[0050] In the embodiment of this specification, the extracted directed association path is composed of multiple sample feature nodes in the DAG, and each sample feature node constituting the directed association path is sequentially connected in a directed manner. The sequence formed by each sample feature node is unidirectional and has no forks, that is, each sample feature node in the directed association path has at most one directed connection pointing to its own node, and at most one directed connection pointing to other nodes. Figure 2 For example, if the sample labeled node is node 9, then a directed association path extracted can be: 1→3→5→8.
[0051] In an example of extracting a path, the sample marked node in the DAG can be used as the target node, and the sample feature node at the other end of the directed connection pointing to the target node can be determined. Then, the sample feature node at the other end of the directed connection pointing to the sample feature node can be determined, and each sample feature node associated through each directed connection can be found in the DAG in this way. Then, the sample feature nodes found can be associated in a directed connection manner according to the association relationship in the DAG, and a directed association path can be obtained.
[0052] In one example, in the process of searching for sample feature nodes in the above manner, when the sample feature node found does not have a directed connection pointing to itself, the search can be stopped and the sample feature node without a directed connection pointing to itself can be determined as the starting node of the directed association path.
[0053] In the DAG, each sample labeled node can generate one or more directed association paths according to the number of directed connections pointing to itself. In one example, all directed association paths in the DAG can be extracted for subsequent decision tree training.
[0054] At 1300, a decision tree is trained based on the extracted directed association paths.
[0055] In the training process of the decision tree, each decision tree used to form the random forest can be trained separately. The same training operation can be performed for the training of each decision tree. The model training for the random forest may include multiple rounds of training, each round of training is used to train a decision tree in the random forest, and multiple decision trees can be trained accordingly after multiple rounds of training, and the trained multiple decision trees can be used to construct the random forest.
[0056] Figure 4 A flowchart of an example 400 of a method for executing each round of training process according to an embodiment of this specification is shown.
[0057] At 1310 , during each round of training, a specified number of directed association paths may be randomly obtained from the extracted directed association paths.
[0058] In this example, the specified number can be much smaller than the number of directed association paths extracted from the DAG. For example, if 100 directed association paths are extracted from the DAG, the specified number can be set to 20, that is, in each round of training, 20 directed association paths can be randomly obtained from the 100 directed association paths for the current round of decision tree training.
[0059] In each round of training, a specified number of directed association paths are obtained in a random manner, so that the directed association paths used in each round of training are different. Therefore, the decision trees trained in each round of training are random, and the individual decision trees that constitute the random forest are also random, which makes the trained random forest random.
[0060] In one example, after randomly acquiring a specified number of directed association paths, all of the acquired specified number of directed association paths may be used to train a corresponding decision tree.
[0061] In another example, after randomly acquiring a specified number of directed association paths, similar directed association paths among the specified number of directed association paths may be cleaned up using a Levenshtein-Distance algorithm.
[0062] In this example, the edit distance can be used to compare the similarities between multiple directed association paths. The edit distance can be used to quantify the similarity by the minimum number of edit operations required to convert one directed association path into another directed association path between two directed association paths. The larger the edit distance between the two directed association paths, the more different the two directed association paths are, and the lower the similarity. Here, the edit operations for the directed association paths can include operations such as insertion, replacement, and deletion.
[0063] For any two directed association paths, the edit distance, i.e., the similarity, between the two directed association paths can be calculated by the edit distance algorithm, and then the edit distance can be compared with a specified threshold. When the edit distance is less than the specified threshold, it can be determined that the two directed association paths are similar; when the edit distance is not less than the specified threshold, it can be determined that the two directed association paths are not similar.
[0064] When similar directed associated paths exist in a specified number of directed associated paths, the similar multiple directed associated paths may be cleaned up, and the cleaning method may be to retain only one directed associated path among the multiple directed associated paths and delete the other directed associated paths. In one example, a directed associated path may be randomly selected from the multiple directed associated paths as a retained directed associated path. In another example, a directed associated path with the longest path among the multiple directed associated paths may be determined as a retained directed associated path. In one example, when there are at least two longest directed associated paths, a longest directed associated path may be randomly selected from the at least two longest directed associated paths and used as a retained directed associated path.
[0065] When there are similar directed association paths in the specified number of directed association paths, the number of directed association paths after cleaning will decrease, and the cleaned directed association paths can be used for subsequent training decision trees. By using the edit distance algorithm to clean similar directed association paths, it is avoided to repeatedly train similar directed association paths to obtain similar decision trees, thereby avoiding wasting computing resources. In addition, after cleaning similar directed association paths, only one directed association path is retained for subsequent decision tree training, which can save computing power and improve training efficiency.
[0066] At 1320 , each of the obtained directed association paths is used to train a corresponding decision tree.
[0067] In one example, after similar directed association paths in the acquired directed association paths are cleaned up using an edit distance algorithm, each directed association path in the cleaned directed association paths may be used to train a corresponding decision tree.
[0068] In the embodiment of the present specification, each directed association path may be trained corresponding to a decision tree, and the training process of each directed association path may be performed independently, so that each directed association path may be used for training separately.
[0069] Figure 5 A flowchart of an example 500 of a decision tree training method for each directed association path according to an embodiment of the present specification is shown.
[0070] At 1312, for each directed association path used to train the decision tree, the characteristic attributes of the sample feature nodes corresponding to the decision tree structure layer can be divided in turn in each decision tree structure layer according to the order of each sample feature node in the directed association path, based on the sample features corresponding to the decision tree structure layer and the training sample group to be processed, so as to obtain classification attribute nodes belonging to the decision tree structure layer with the divided characteristic attributes.
[0071] In the embodiment of the present specification, each sample feature node in the directed association path is based on the directed connection between each other, so that the each sample feature node has an arrangement order. Figure 6 FIG. 1 is a schematic diagram showing an example of a decision tree constructed by directed association paths according to an embodiment of the present specification. Figure 6 As shown, the directed association path used to train the decision tree includes sample feature nodes 1, 3, 5 and 8, and the formed path is: 1→3→5→8, so the order of the four sample feature nodes is: 1, 3, 5, 8.
[0072] A decision tree can be composed of multiple decision tree structure layers, which are arranged in order from top to bottom. Each decision tree structure layer corresponds to a sample feature, and different decision tree structure layers correspond to different sample features, so that each decision tree structure layer can be classified based on the characteristic attributes of the corresponding sample feature. Figure 6 For example, Figure 6 The decision tree shown is composed of four decision tree structure layers, each of which corresponds to a sample feature.
[0073] The number of each sample feature node in the directed association path is consistent with the number of decision tree structure layers of the corresponding trained decision tree, and each sample feature node corresponds to the decision tree structure layer one by one. Specifically, each sample feature node in the directed association path corresponds to the decision tree structure layer in the order of the sample feature nodes in the order from top to bottom of the decision tree, so that the sample features corresponding to each decision tree structure layer are the sample features represented by the sample feature nodes corresponding to the decision tree structure layer.
[0074] by Figure 6 For example, Figure 6 As shown, sample feature node 1 corresponds to the decision tree structure layer located at the first layer of the decision tree (hereinafter referred to as the first decision tree structure layer), so that the first decision tree structure layer corresponds to the sample feature represented by sample feature node 1. Sample feature node 3 corresponds to the decision tree structure layer located at the second layer of the decision tree (hereinafter referred to as the second decision tree structure layer), so that the second decision tree structure layer corresponds to the sample feature represented by sample feature node 3. Sample feature node 5 corresponds to the decision tree structure layer located at the third layer of the decision tree (hereinafter referred to as the third decision tree structure layer), so that the third decision tree structure layer corresponds to the sample feature represented by sample feature node 5. Sample feature node 8 corresponds to the decision tree structure layer located at the fourth layer of the decision tree (hereinafter referred to as the fourth decision tree structure layer), so that the fourth decision tree structure layer corresponds to the sample feature represented by sample feature node 8.
[0075] In one example, the decision tree trained in the embodiment of this specification is a binary tree, so that at each decision tree structure layer of the decision tree, each training sample group can be classified according to the characteristic attributes of the sample features corresponding to the decision tree structure layer to be divided into two training sample subgroups.
[0076] In the training for each directed association path, the first sample feature node is processed first according to the order of each sample feature node in the directed association path. The first sample feature node corresponds to the first decision tree structure layer of the decision tree, and in the first decision tree structure layer, the training samples to be processed can be all training samples as a whole. Thus, based on the first sample feature corresponding to the first sample feature node and the characteristic attribute of all training samples, the first sample feature is divided into two characteristic attributes, and a classification attribute node with the two characteristic attributes is obtained accordingly. Then, all training samples are classified according to the two divided characteristic attributes to divide all training samples into two training sample subgroups, and each training sample subgroup corresponds to an attribute classification in the characteristic attributes.
[0077] by Figure 6 For example, the sample feature node 1 corresponding to the first decision tree structure layer is the transaction amount. By dividing the feature attributes of the transaction amount, the two feature attributes that can be obtained are the transaction amount less than 5000 and the transaction amount not less than 5000. Therefore, the training sample data can be divided into two training sample subgroups, one is the training sample subgroup with a transaction amount less than 5000, and the other is the training sample subgroup with a transaction amount not less than 5000.
[0078] After completing the processing of the first decision tree structure layer, the two training sample subgroups divided by the first decision tree structure layer can be used as the training sample groups to be processed in the next decision tree structure layer. The second decision tree structure layer corresponds to the second sample feature node in the directed association path, and in the second decision tree structure layer, each training sample group is processed separately.
[0079] For each training sample group, based on the second sample feature corresponding to the second sample feature node and the characteristic attribute of the second sample feature node of the training sample group, the second sample feature node is divided into two characteristic attributes, and a classification attribute node having the two characteristic attributes is correspondingly obtained. A classification attribute node is generated for each training sample group. Then, the training sample group is classified according to the two divided characteristic attributes, so as to further divide the training sample group into two training sample subgroups.
[0080] After the above processing, two training sample groups to be processed in the second decision tree structure layer are input, and four training sample subgroups are obtained after classification. The four training sample subgroups can be used as the training sample groups to be processed in the next layer (i.e., the third decision tree structure layer). And so on, until the feature attribute division of the last decision tree structure layer in the decision tree is completed, and the corresponding classification attribute nodes are generated.
[0081] Each classification attribute node in each decision tree structure layer may have two different characteristic attributes, which may be used to classify the corresponding training sample group to divide the training sample group into training sample subgroups corresponding to the two characteristic attributes.
[0082] For each training sample group to be processed in each decision tree structure layer, in one example, the attribute partition point for the training sample group can be determined according to the specified feature attribute partition criterion and the sample features corresponding to the decision tree structure layer.
[0083] In one example, the specified feature attribute division criterion may include at least one of an information entropy criterion, an information gain criterion, a gain rate criterion, and a Gini index criterion. Different criteria correspond to different index values, and the attribute division point is determined by calculating the index value and according to the size of the index value.
[0084] In the information entropy criterion, the index value is information entropy. The smaller the information entropy value, the higher the purity of the training samples in the training sample population, so the corresponding feature attribute with the smallest information entropy can be used as the feature attribute to be divided. In the information gain criterion, the index value is information gain. The larger the information gain, the greater the purity of the training samples obtained by classifying the corresponding feature attributes. In the gain rate criterion, the index value is the information gain rate. The feature attributes with information gain lower than the average level can be eliminated first, and then the feature attributes with the highest information gain rate can be selected from the feature attributes higher than the average level. In the Gini index criterion, the index value is the Gini index. The Gini index represents the probability that two training samples are randomly selected from the training sample population and that the two training samples belong to different classes. The smaller the probability, the higher the purity of the training sample population. Therefore, the feature attribute with the smallest Gini index can be selected.
[0085] In this example, the feature attribute to be divided can be discrete or continuous. For example, the sample feature is the transaction amount, and the feature attribute of the transaction amount can include two continuous feature attributes: less than 5000 and not less than 5000. The following takes the continuous feature attribute as an example for explanation.
[0086] For the training sample group to be processed and the continuous characteristic attribute a, the training samples in the training sample group can be arranged from small to large according to the value of the characteristic attribute a, and the set of the training sample group is {a1, a2, …, a k}, where a1, a2, …, a k All represent training samples. For any two adjacent training samples a in the set i and a i+1 , the dividing point can take any value between the two training samples. In one example, the dividing point can take the average value of the two training samples, that is, Here, i can be equal to 1, 2, 3, …, k-1. In this way, we can get the set of partition points {a′1, a′2, …, a′ k-1}. For each division point, the specified feature attribute division criterion is used to calculate to obtain the corresponding index value, and then the attribute division point for the training sample group is determined by comparing the index values of each division point. For example, if the specified feature attribute division criterion is the Gini index criterion, the Gini index corresponding to each division point can be calculated, and then the division point with the smallest Gini index is determined as the attribute division point for the training sample group.
[0087] After determining the attribute division point, the characteristic attributes of the sample characteristic nodes corresponding to the decision tree structure layer can be divided according to the attribute division point to obtain the classification attribute node with the divided characteristic attributes belonging to the decision tree structure layer. The classification attribute node can classify the training sample group according to the multiple characteristic attributes it has.
[0088] In one example, the attribute division points that can be determined include one attribute division point, so that the characteristic attributes of the sample feature node corresponding to the decision tree structure layer can be divided into two characteristic attributes based on the one attribute division point, and the generated classification attribute node has the two characteristic attributes, so that the classification attribute node can divide the training sample group into two types of training sample sub-groups corresponding to the two characteristic attributes.
[0089] Back to Figure 5 After completing the feature attribute division of each decision tree structure layer and generating the classification attribute nodes, at 1314, a decision tree corresponding to the directed association path can be constructed based on the classification attribute nodes of each decision tree structure layer.
[0090] For the classification attribute node in each decision tree structure layer, when the decision tree structure layer has a decision tree structure layer located in the previous layer, the classification attribute node can be connected with the classification attribute node of the training sample group targeted by the classification attribute node in the decision tree structure layer located in the previous layer. Figure 6 For example, for the leftmost classification attribute node ⑤ in the third decision tree structure layer, the training sample group targeted by this classification attribute node ⑤ comes from the training sample sub-group generated by classification of the leftmost classification attribute node ③ in the second decision tree structure layer. Therefore, when constructing the decision tree, the leftmost classification attribute node ⑤ in the third decision tree structure layer can be connected with the leftmost classification attribute node ③ in the second decision tree structure layer.
[0091] When the decision tree structure layer has a decision tree structure layer located in the next layer, the classification attribute node can be connected with the classification attribute node in the decision tree structure layer located in the next layer for classifying the training sample group generated by the classification attribute node. Figure 6 For example, for the leftmost classification attribute node ⑤ in the third decision tree structure layer, the training sample subgroup generated by classification of the classification attribute node ⑤ serves as the training sample group for the first and second classification attribute nodes ⑧ on the leftmost side in the fourth decision tree structure layer. Therefore, when constructing the decision tree, the leftmost classification attribute node ⑤ in the third decision tree structure layer can be connected to the first and second classification attribute nodes ⑧ on the leftmost side in the fourth decision tree structure layer, respectively.
[0092] Back to Figure 4By using a specified number of directed association paths, a specified number of decision trees can be trained. At 1330, a decision tree with the best training effect can be selected from the trained specified number of decision trees as the decision tree outputted in this round of training.
[0093] In the embodiments of the present specification, the training effect measurement criteria of the decision tree may include at least one of a confusion matrix, precision and recall, F-measure, ROC curve (receiver operating characteristic curve) and AUC (Area Under Curve).
[0094] In one example, the trained decision trees can be tested using test samples, and the classification accuracy of each decision tree can be obtained according to the test results. Then, the decision tree with the best training effect can be determined according to the classification accuracy of each decision tree.
[0095] Back to Figure 1 After multiple rounds of training to obtain multiple decision trees, at 1400, a random forest is constructed based on the trained decision trees.
[0096] The constructed random forest includes each decision tree obtained through training. When the random forest model is used to classify input data, each decision tree in the random forest can classify the input data separately to obtain corresponding classification results, and then the classification results of each decision tree can be combined to serve as the output result of the random forest. In one way of combining the classification results, the classification results of each decision tree can be averaged, and the obtained mean value can be used as the output result of the random forest.
[0097] Through the technical solution of the embodiments of this specification, DAG is obtained by learning based on all training samples and all sample features, so that DAG integrates the global knowledge of the training samples, so that the decision tree trained by DAG is also obtained based on the global knowledge of the training samples, thereby improving the overall training effect of the decision tree.
[0098] Figure 7 A block diagram of an example of a random forest training device 7000 based on a directed association relationship of sample features according to an embodiment of this specification is shown.
[0099] like Figure 7 As shown, the random forest training device 7000 includes a DAG learning unit 7100, a path extraction unit 7200, a decision tree training unit 7300 and a random forest construction unit 7400.
[0100] The DAG learning unit 7100 is configured to perform structural learning on sample features based on a plurality of labeled training samples, and obtain a DAG consisting of sample features and sample labels of the plurality of training samples as nodes.
[0101] The path extraction unit 7200 is configured to extract a directed association path consisting of sample feature nodes from the DAG according to the sample label nodes in the DAG, and each sample feature node in the directed association path is sequentially and directedly connected.
[0102] The decision tree training unit 7300 is configured to train a decision tree based on the extracted directed association paths.
[0103] The random forest construction unit 7400 is configured to construct a random forest based on the trained decision tree.
[0104] Figure 8 A block diagram of an example of a decision tree training unit 7300 according to an embodiment of this specification is shown.
[0105] like Figure 8 As shown, the decision tree training unit 7300 may include a path acquisition module 7310 , a decision tree training module 7320 and a decision tree output module 7330 .
[0106] The path acquisition module 7310 is configured to randomly acquire a specified number of directed associated paths from the extracted directed associated paths during each round of training.
[0107] The decision tree training module 7320 is configured to train a corresponding decision tree using each directed association path in the obtained directed association paths.
[0108] The decision tree output module 7330 is configured to select a decision tree with the best training effect from the designated number of trained decision trees as the decision tree outputted in this round of training.
[0109] In one example, the decision tree training unit 7300 may further include an edit distance algorithm module 7340, which is configured to: use an edit distance algorithm to clean up similar directed association paths in the obtained directed association paths. The decision tree training module 7320 may also be configured to: use each directed association path in the cleaned directed association paths to train the corresponding decision tree.
[0110] Fig. 9 A block diagram showing an example of a decision tree training module 7320 according to an embodiment of the present specification is shown.
[0111] like Fig. 9As shown, the decision tree training module 7320 may include a feature attribute division submodule 7321 and a decision tree construction submodule 7323 .
[0112] The feature attribute division submodule 7321 is configured to, for each directed association path, in the order of each sample feature node in the directed association path, divide the feature attributes of the sample feature nodes corresponding to the decision tree structure layer in each decision tree structure layer in turn based on the sample features corresponding to the decision tree structure layer and the training sample group to be processed, so as to obtain the classification attribute nodes with the divided feature attributes belonging to the decision tree structure layer, wherein each sample feature node corresponds one-to-one to the decision tree structure layer of the corresponding trained decision tree.
[0113] The decision tree construction submodule 7323 is configured to construct a decision tree corresponding to the directed association path based on the classification attribute nodes of each decision tree structure layer.
[0114] In one example, the feature attribute division submodule 7321 can also be configured to: for each training sample group to be processed in each decision tree structure layer, execute in the following manner: determine the attribute division point for the training sample group according to the specified feature attribute division criterion and the sample characteristics corresponding to the decision tree structure layer; and divide the feature attributes of the sample feature nodes corresponding to the decision tree structure layer according to the attribute division point to obtain the classification attribute nodes belonging to the decision tree structure layer with the divided feature attributes.
[0115] Reference above Figures 1 to 9 , an embodiment of a random forest training method and a random forest training device based on a directed association relationship of sample features according to an embodiment of this specification is described.
[0116] The random forest training device based on the directed association relationship of sample features in the embodiment of this specification can be implemented by hardware, or by software or a combination of hardware and software. Taking software implementation as an example, as a device in a logical sense, it is formed by the processor of the device in which it is located reading the corresponding computer program instructions in the memory into the memory and running them. In the embodiment of this specification, the random forest training device based on the directed association relationship of sample features can be implemented, for example, using an electronic device.
[0117] Fig.10 A block diagram of an electronic device 1000 for implementing a random forest training method based on a directed association relationship of sample features according to an embodiment of the present specification is shown.
[0118] like Fig.10As shown, the electronic device 1000 may include at least one processor 1010, a memory (e.g., a non-volatile memory) 1020, a memory 1030, and a communication interface 1040, and the at least one processor 1010, the memory 1020, the memory 1030, and the communication interface 1040 are connected together via a bus 1050. At least one processor 1010 executes at least one computer-readable instruction stored or encoded in the memory (i.e., the above-mentioned element implemented in the form of software).
[0119] In one embodiment, computer executable instructions are stored in a memory, which, when executed, cause at least one processor 1010 to: perform structural learning on sample features based on multiple labeled training samples to obtain a DAG consisting of sample features and sample labels of the multiple training samples as nodes; extract a directed association path consisting of sample feature nodes from the DAG according to the sample label nodes in the DAG, wherein each sample feature node in the directed association path is sequentially and directedly connected; train a decision tree based on the extracted directed association path; and construct a random forest based on the trained decision tree.
[0120] It should be understood that the computer executable instructions stored in the memory, when executed, cause at least one processor 1010 to perform the above combined operations in various embodiments of this specification. Figure 1-9 Describes the various operations and functions.
[0121] According to one embodiment, a program product such as a machine-readable medium is provided. The machine-readable medium may have instructions (i.e., the above-mentioned elements implemented in the form of software), which, when executed by a machine, causes the machine to perform the above-mentioned combination of various embodiments of this specification. Figure 1-9 Describes the various operations and functions.
[0122] Specifically, a system or device equipped with a readable storage medium can be provided, on which software program codes that implement the functions of any of the above-mentioned embodiments are stored, and a computer or processor of the system or device can read and execute instructions stored in the readable storage medium.
[0123] In this case, the program code itself read from the machine-readable medium can realize the function of any one of the above-mentioned embodiments, and thus the machine-readable code and the machine-readable storage medium storing the machine-readable code constitute a part of the present invention.
[0124] The computer program code required for the operation of each part of this specification can be written in any one or more programming languages, including object-oriented programming languages, such as Java, Scala, Smalltalk, Eiffel, JADE, Emerald, C++, C#, VB, NET and Python, conventional procedural programming languages such as C language, Visual Basic 2003, Perl, COBOL2002, PHP and ABAP, dynamic programming languages such as Python, Ruby and Groovy, or other programming languages. The program code can be run on the user's computer, or run on the user's computer as an independent software package, or run partly on the user's computer and another part on the remote computer, or all on the remote computer or server. In the latter case, the remote computer can be connected to the user's computer through any network form, such as a local area network (LAN) or a wide area network (WAN), or connected to an external computer (e.g., via the Internet), or in a cloud computing environment, or used as a service, such as software as a service (SaaS).
[0125] Examples of readable storage media include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD-RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code may be downloaded from a server computer or a cloud via a communication network.
[0126] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0127] Not all steps and units in the above-mentioned processes and system structure diagrams are necessary, and some steps or units can be ignored according to actual needs. The execution order of each step is not fixed and can be determined according to needs. The device structure described in the above-mentioned embodiments can be a physical structure or a logical structure, that is, some units may be implemented by the same physical entity, or some units may be implemented by multiple physical entities, or some components in multiple independent devices may be implemented together.
[0128] The term "exemplary" as used throughout this specification means "serving as an example, instance, or illustration" and does not imply "preferred" or "advantageous" over other embodiments. The detailed description includes specific details for the purpose of providing an understanding of the described techniques. However, the techniques may be implemented without these specific details. In some instances, in order to avoid obscuring the concepts of the described embodiments, well-known structures and devices are shown in block diagram form.
[0129] The optional implementation modes of the embodiments of the present specification are described in detail above in conjunction with the accompanying drawings. However, the embodiments of the present specification are not limited to the specific details in the above implementation modes. Within the technical concept of the embodiments of the present specification, various simple modifications can be made to the technical solutions of the embodiments of the present specification, and these simple modifications all belong to the protection scope of the embodiments of the present specification.
[0130] The above description of the contents of this specification is provided to enable any person of ordinary skill in the art to implement or use the contents of this specification. Various modifications to the contents of this specification will be apparent to those of ordinary skill in the art, and the general principles defined herein may be applied to other variations without departing from the scope of protection of the contents of this specification. Therefore, the contents of this specification are not limited to the examples and designs described herein, but are consistent with the widest range of principles and novel features disclosed herein.
Claims
1. A random forest training method based on the directed association relationship of sample features, include: Performing structural learning on sample features based on the labeled training samples to obtain a DAG consisting of sample features and sample labels of the training samples as nodes; Extracting a directed association path composed of sample feature nodes from the DAG according to the sample label nodes in the DAG, wherein each sample feature node in the directed association path is sequentially and directedly connected; Training a decision tree based on the extracted directed association paths; as well as Build a random forest based on the trained decision tree. Among them, training a decision tree based on the extracted directed association path includes: For each directed association path, training is performed as follows: According to the order of each sample feature node in the directed association path, in each decision tree structure layer, based on the sample features corresponding to the decision tree structure layer and the training sample group to be processed, the feature attributes of the sample feature node corresponding to the decision tree structure layer are divided to obtain classification attribute nodes with the divided feature attributes belonging to the decision tree structure layer, wherein each sample feature node corresponds to the decision tree structure layer of the corresponding trained decision tree one by one; and Based on the classification attribute nodes of each decision tree structure layer, a decision tree corresponding to the directed association path is constructed. The training samples include transaction data in anti-fraud scenarios, and the sample features of the training samples include transaction amount, transaction amount on the day, number of transactions on the day, average transaction amount in the last n days, average number of transactions in the last n days and risk score.
2. The random forest training method according to claim 1, in, Training a decision tree based on the extracted directed association paths includes: Each round of training is performed as follows: Randomly obtain a specified number of directed association paths from the extracted directed association paths; Using each of the obtained directed association paths to train a corresponding decision tree; and A decision tree with the best training effect is selected from the designated number of trained decision trees as the decision tree outputted in this round of training.
3. The random forest training method according to claim 1, in, Based on the sample features corresponding to the decision tree structure layer and the training sample group to be processed, the characteristic attributes of the sample feature nodes corresponding to the decision tree structure layer are divided to obtain the classification attribute nodes with the divided characteristic attributes belonging to the decision tree structure layer, including: For each group of training samples to be processed in each tree structure layer, execute as follows: Determining attribute division points for the training sample group according to a specified feature attribute division criterion and sample features corresponding to the decision tree structure layer; and The characteristic attributes of the sample characteristic nodes corresponding to the decision tree structure layer are divided according to the attribute division points to obtain classification attribute nodes with the divided characteristic attributes belonging to the decision tree structure layer.
4. The random forest training method according to claim 3, in, The specified feature attribute division criterion includes at least one of an information entropy criterion, an information gain criterion, a gain rate criterion, and a Gini index criterion.
5. The random forest training method according to claim 2, in, Before using each of the obtained directed association paths to train the corresponding decision tree, the method further includes: Using an edit distance algorithm to clean up similar directed association paths among the obtained directed association paths; and Using each of the obtained directed association paths to train a corresponding decision tree includes: Each directed association path in the cleaned directed association paths is used to train the corresponding decision tree.
6. The random forest training method according to claim 1, in, The training samples include data of anti-fraud scenarios.
7. A random forest training device based on the directed association relationship of sample features, include: A DAG learning unit performs structural learning on sample features based on a plurality of labeled training samples to obtain a DAG consisting of sample features and sample labels of the plurality of training samples as nodes; A path extraction unit extracts a directed association path consisting of sample feature nodes from the DAG according to the sample label nodes in the DAG, wherein each sample feature node in the directed association path is sequentially and directionally connected; A decision tree training unit, which trains a decision tree based on the extracted directed association paths; as well as Random forest construction unit, which builds a random forest based on the trained decision tree. Wherein, for each directed association path, the decision tree training unit performs training in the following manner: According to the order of each sample feature node in the directed association path, in each decision tree structure layer, based on the sample features corresponding to the decision tree structure layer and the training sample group to be processed, the feature attributes of the sample feature node corresponding to the decision tree structure layer are divided to obtain classification attribute nodes with the divided feature attributes belonging to the decision tree structure layer, wherein each sample feature node corresponds to the decision tree structure layer of the corresponding trained decision tree one by one; and Based on the classification attribute nodes of each decision tree structure layer, a decision tree corresponding to the directed association path is constructed. The training samples include transaction data in anti-fraud scenarios, and the sample features of the training samples include transaction amount, transaction amount on the day, number of transactions on the day, average transaction amount in the last n days, average number of transactions in the last n days and risk score.
8. The random forest training device according to claim 7, in, The decision tree training unit comprises: The path acquisition module randomly acquires a specified number of directed association paths from the extracted directed association paths during each round of training; A decision tree training module, using each directed association path in the obtained directed association paths to train a corresponding decision tree; and The decision tree output module selects the decision tree with the best training effect from the specified number of trained decision trees as the decision tree outputted in this round of training.
9. The random forest training device according to claim 8, in, The decision tree training module includes: A feature attribute division submodule, for each directed association path, in accordance with the order of each sample feature node in the directed association path, in each decision tree structure layer, based on the sample features corresponding to the decision tree structure layer and the training sample group to be processed, divides the feature attributes of the sample feature nodes corresponding to the decision tree structure layer, so as to obtain classification attribute nodes with the divided feature attributes belonging to the decision tree structure layer, wherein each sample feature node corresponds one-to-one to the decision tree structure layer of the corresponding trained decision tree; and The decision tree construction submodule constructs a decision tree corresponding to the directed association path based on the classification attribute nodes of each decision tree structure layer.
10. The random forest training device according to claim 9, in, The feature attribute division submodule is configured as follows: For each group of training samples to be processed in each tree structure layer, execute as follows: Determining attribute division points for the training sample group according to a specified feature attribute division criterion and sample features corresponding to the decision tree structure layer; and The characteristic attributes of the sample characteristic nodes corresponding to the decision tree structure layer are divided according to the attribute division points to obtain classification attribute nodes with the divided characteristic attributes belonging to the decision tree structure layer.
11. The random forest training device according to claim 8, in, The decision tree training unit also includes: An edit distance algorithm module, using the edit distance algorithm to clean up similar directed association paths in the obtained directed association paths; and The decision tree training module is configured as follows: Each directed association path in the cleaned directed association paths is used to train the corresponding decision tree.
12. An electronic device, include: At least one processor, a memory coupled to the at least one processor, and a computer program stored on the memory, wherein the at least one processor executes the computer program to implement the method according to any one of claims 1 to 6.
13. A computer-readable storage medium storing a computer program, wherein the computer program implements the method according to any one of claims 1 to 6 when executed by a processor.
14. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Random forest model construction method and device, electronic equipment and storage medium
CN110705683A
Text classification method based on graph path knowledge extraction
CN113515632A
