Network request data classification model training method, classification method and storage medium
Through the method of combining hidden Markov model and logistic regression model, the feature vector of network request data is extracted, which solves the problem of insufficient classification accuracy and security of network request data in the existing technology, and achieves effective detection of new illegal request data. identification and efficient classification.
Patent Information
- Application Number
- CN202111670119.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-31
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-12-31
AI Technical Summary
Existing network request data classification methods rely on fixed-format regular expression matching, which makes it difficult to effectively identify new types of illegal request data, and the classification accuracy and security are insufficient.
Using a method that combines hidden Markov models and logistic regression models, the model is trained to improve classification accuracy by extracting feature vectors of network request data, and uses cosine similarity algorithms to identify high-risk users.
It significantly improves the accuracy and security of network request data classification, can effectively identify new illegal request data, and the model can be continuously optimized based on input data and is difficult to crack.
Smart Images

Figure CN114528908B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data processing technology, and in particular to a network request data classification model training method, a classification method and a storage medium. Background Art
[0002] With the development of Internet technology and the expansion of network services, network services are also increasing. Among network service users, in addition to those who normally access and use network services, there are also some users who obtain non-public information or confidential information by assembling illegal request data, which makes the data security of network service data and server resources have serious security risks. Therefore, correctly classifying network request data is an important technical means to ensure network data security.
[0003] At present, a commonly used method for classifying network request data is to match the user's request data through regular expressions and classify the request data according to the matching results. If the matching results show that the request data is an illegal request, the server intercepts the request and counts it.
[0004] However, regular expressions are predefined string matching rules, which are relatively fixed and can be easily cracked to circumvent the matching rules. At the same time, the classification accuracy of illegal request data generated by the new data assembly method is poor. Summary of the invention
[0005] The problem solved by the present invention is how to improve the accuracy of network request data classification.
[0006] In order to solve the above problems, the present invention provides a network request data classification model training method, a classification method and a storage medium.
[0007] In a first aspect, the present invention provides a method for training a network request data classification model, wherein the network request data classification model includes a first calculation model and a second calculation model, including:
[0008] Acquire multiple pieces of network request data, and extract characteristic data from each piece of the network request data, wherein the network request data includes legal request data, and the characteristic data includes request address data;
[0009] Using a preset characteristic data matching rule to match the characteristic data in the network request data, and obtaining a quantity matching result of the characteristic data in each piece of the network request data;
[0010] The request address data of each piece of the legal request data is used to train a pre-built hidden Markov model to obtain a first calculation model, wherein the first calculation model is used to calculate the text sequence generation probability of the request address data in the network request data;
[0011] Using the first calculation model to calculate the text sequence generation probability of the request address data in each piece of the network request data;
[0012] A feature vector of each piece of the network request data is generated according to the quantity matching result and the text sequence generation probability, and a pre-built first logistic regression model is trained using the feature vector to obtain a second calculation model, which is used to determine the legal probability of the network request data.
[0013] The beneficial effect of the network request data classification model training method of the present invention is that multiple network request data can be obtained as labeled sample data, the network request data can use historical network request data, and the sample data includes legal request data and illegal request data. Extract feature data from each network request data, the feature data may include request address data, user agent data and certificate data, etc., use preset feature data matching rules to match the feature data in each network request data, and obtain the quantity matching result of the feature data in each network request data, and the data matching result is used as a numerical feature. Use the request address data of the legal request data to train the pre-constructed hidden Markov model to obtain the first calculation model, and use the first calculation model to calculate the text sequence generation probability of the request address data in each network request data. The text sequence generation probability is used as another numerical feature to abstract the network request data into a numerical feature, which can obtain its internal information to the greatest extent and improve the accuracy of the model obtained by subsequent training. The first logistic regression model is trained using a feature vector composed of a quantity matching result and a text sequence generation probability to obtain a second calculation model, which is used to determine the legal probability of network request data to classify the network request data. For example, the legal probability of network request data can be compared with a preset threshold, and the network request data is determined to be legal request data or illegal request data according to the comparison result. In the present invention, a machine learning algorithm is used to learn the laws of network request data from multiple dimensions. Compared with the regular expression matching method with a fixed format used in the prior art to classify network request data, the trained second calculation model has a higher classification accuracy. And the second calculation model can be continuously optimized according to the input network request data, which is difficult to be cracked, greatly improving security. Moreover, when facing illegal request data generated by a new assembly method, the present invention can also identify and intercept according to the general laws of learning, with a wide range of applications and high classification accuracy.
[0014] Optionally, the network request data classification model further includes a third computing model, and after the first logistic regression model pre-built by using the feature vector to train is obtained, the second computing model further includes:
[0015] Acquire all the network request data within a specified time period, and group all the network request data within the specified time period according to users to determine the network request data of each user;
[0016] Using a cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the network request data, and using the second calculation model to calculate the legal probability of each piece of the network request data;
[0017] A pre-constructed second logistic regression model is trained according to the text similarities and the legal probabilities corresponding to all the network request data of each of the users to obtain a third calculation model, wherein the third calculation model is used to determine the probability that the user is a high-risk user.
[0018] Optionally, the using the request address data of each piece of the legal request data to train a pre-built hidden Markov model to obtain a first calculation model comprises:
[0019] Segmenting the request address data of each piece of the legitimate request data to obtain a plurality of segmented data;
[0020] Marking each of the segmented data to obtain marked data, wherein the segmented data of the same character string are marked with the same value, and the segmented data of different characters are marked with different values;
[0021] Based on a forward-backward algorithm, the labeled data is used to train the hidden Markov model to obtain the first computing model.
[0022] Optionally, the adopting the feature vector to train a pre-constructed first logistic regression model to obtain a second calculation model comprises:
[0023] The feature vector is input into the first logistic regression model, and the corresponding legal probability of the network request data is output, wherein the first logistic regression model is represented by a first formula, and the first formula includes:
[0024]
[0025] Where X represents the legal probability of the network request data, k j represents the parameters of the first logistic regression model, W j represents the jth element in the feature vector;
[0026] Comparing the legal probability with a first preset threshold, and determining a first prediction label of the network request data according to the comparison result;
[0027] Optimize the parameters of the first logistic regression model according to the first predicted label and the first actual label of the network request data until the accuracy of the first logistic regression model meets a first preset condition, thereby obtaining the second calculation model.
[0028] Optionally, the using a cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the network request data includes:
[0029] Segmenting the request address data in each piece of the network request data according to word meanings to obtain word sequences corresponding to each piece of the network request data;
[0030] Encode each of the word sequences respectively to obtain an encoding vector corresponding to each piece of the network request data;
[0031] Based on the cosine similarity algorithm, the text similarity corresponding to each piece of the network request data is calculated using a second formula according to the encoding vector, and the second formula includes:
[0032]
[0033] Among them, θ i represents the text similarity corresponding to the i-th network request data, v i represents the encoding vector corresponding to the i-th network request data, v j Represents the encoding vector corresponding to the j-th network request data.
[0034] Optionally, the step of training a pre-built second logistic regression model according to the text similarities and the legal probabilities corresponding to all the network request data of each user to obtain a third calculation model comprises:
[0035] For any of the users, a similarity mean is calculated based on the text similarities corresponding to all the network request data of the user within the specified time period, and a probability mean is calculated based on the legitimacy probabilities corresponding to all the network request data of the user within the specified time period;
[0036] The similarity mean and the probability mean are input into the second logistic regression model, and the corresponding probability of the user being a high-risk user is output. The second logistic regression model is represented by a third formula, and the third formula includes:
[0037]
[0038] Among them, X Prepresents the probability that the user is a high-risk user, avg1 represents the similarity mean, avg2 represents the probability mean, T1 and T2 represent the parameters of the second logistic regression model;
[0039] Comparing the probability that the user is a high-risk user with a second preset threshold, and determining a second prediction label of the second logistic regression model according to the comparison result;
[0040] Optimize the parameters of the second logistic regression model according to the second predicted label and the second actual label of the user until the accuracy of the second logistic regression model meets a second preset condition, thereby obtaining the third calculation model.
[0041] In a second aspect, the present invention further proposes a network request data classification method, comprising:
[0042] Acquire target network request data to be classified, and extract target feature data from the target network request data, wherein the target feature data includes target request address data;
[0043] Using a preset feature data matching rule to match the target feature data in the target network request data, to obtain a quantity matching result of the target feature data;
[0044] Inputting the target request address data into a first calculation model, and outputting a text sequence generation probability of the target request address data;
[0045] Generate a target feature vector of the target network request data according to the quantity matching result and the text sequence generation probability, input the target feature vector into a second calculation model, and output a legal probability of the target network request data;
[0046] Comparing the legal probability with a first preset threshold, and determining the data type of the target network request data according to the comparison result, the data type including legal request data and illegal request data;
[0047] The first computing model and the second computing model are trained using any of the network request data classification model training methods described above.
[0048] The beneficial effects of the network request data classification method of the present invention are: obtaining the target network request data to be classified, and extracting the target feature data in the target network request data. The target feature data in the target network request data is matched using a preset feature data matching rule, and the numerical features of the target feature data are extracted from the feature data dimension to obtain the quantity matching quantity. The target request address data is input into the network request data classification model training method described in any one of the first aspects to obtain a first calculation model, and the numerical features are extracted from the target request address data dimension, and the text sequence generation probability is output. The target feature vector composed of the quantity matching result and the text sequence generation probability is input into the network request data classification model training method described in any one of the first aspects to obtain a second calculation model, and the legal probability of the target network request data is output, and the data type of the target network request data is determined according to the comparison result of the legal probability and the first preset threshold. The present invention extracts the numerical features of the network request data from multiple dimensions, and calculates the legal probability of the target network request data according to the numerical features of multiple dimensions to realize the classification of the target network request data, which effectively improves the accuracy of the classification of the network request data.
[0049] Optionally, the network request data classification method of the present invention further includes:
[0050] Obtaining all target network request data of the target user within a specified time period;
[0051] Using a cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the target network request data, and using the second calculation model to calculate the legal probability of each piece of the target network request data;
[0052] Determine a similarity mean of all the text similarities and a probability mean of all the legal probabilities, input the similarity mean and the probability mean into a third calculation model, and output a probability that the target user is a high-risk user;
[0053] Comparing the probability that the target user is a high-risk user with a second preset threshold, and determining the user type of the target user according to the comparison result, wherein the user type includes high-risk users and non-high-risk users;
[0054] The third computing model is trained using any of the network request data classification model training methods described above.
[0055] Optionally, after determining the user type of the target user according to the comparison result, the method further includes:
[0056] If the target user is a high-risk user, the target user is added to the blacklist and all network request data of the target user are rejected;
[0057] If the target user is not a high-risk user, receiving the network request data of the target user is allowed.
[0058] In a third aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the network request data classification model training method as described in any one of the above items, or the network request data classification method as described in any one of the above items is implemented.
[0059] The beneficial effects of the computer-readable storage medium described in the present invention are similar to those of the above-mentioned network request data classification method, which will not be described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 A schematic diagram of a flow chart of a network request data classification model training method according to an embodiment of the present invention;
[0061] Figure 2 A schematic diagram of a flow chart of a network request data classification method according to another embodiment of the present invention;
[0062] Figure 3 A schematic diagram of the structure of a network request data classification model training device according to another embodiment of the present invention;
[0063] Figure 4 The present invention is a schematic diagram of the structure of a network request data classification device according to another embodiment of the present invention. DETAILED DESCRIPTION
[0064] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below in conjunction with the accompanying drawings. It should be understood that the drawings and embodiments of the present invention are only for exemplary purposes and are not intended to limit the scope of protection of the present invention. It should be understood that the various steps recorded in the method implementation of the present invention can be performed in different orders and / or in parallel. In addition, the method implementation may include additional steps and / or omit the steps shown. The scope of the present invention is not limited in this respect.
[0065] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments"; the term "optionally" means "optional embodiments". Relevant definitions of other terms will be given in the following description. It should be noted that the concepts of "first", "second", etc. mentioned in the present invention are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0066] It should be noted that the modifications of "one" and "plurality" mentioned in the present invention are illustrative rather than restrictive, and those skilled in the art should understand that, unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0067] like Figure 1 As shown, an embodiment of the present invention provides a network request data classification model training method, wherein the network request data classification model includes a first calculation model and a second calculation model, including:
[0068] Step S110, acquiring multiple pieces of network request data, and extracting characteristic data from each piece of the network request data, wherein the network request data includes legal request data, and the characteristic data includes request address data.
[0069] Specifically, the network request data is data with labels, including legal request data and illegal request data. The label of the legal request data is a legal state, and the label of the illegal request data is an illegal state.
[0070] Historical network request data can be collected from services such as Elasticsearch, Logstash, and Kibana installed on the server. Elasticsearch is a distributed data search engine used to search for data stored in the server; Logstash is a log data collection and parsing engine used to store request data on the server; Kibana is a visual data analysis platform that provides visualization tools to facilitate users to conduct data analysis. All acquired network request data can be manually classified, illegal request data can be manually screened out from all network request data, separated from legal request data, and each classified network request data can be used as sample data. Sample data is obtained as training data for subsequent training models, and legal request data and illegal request data in the original network request data are separated, so that the model can learn the general rules of legal request data from the data, which is used to classify the received network request data.
[0071] Extract feature data from each sample data. The feature data may include request address data, user agent data, and certificate data. The request address data may be Request-URL, which indicates the content that the user wants to query or access; the user agent data may be User-Agent, which stores relevant information about the user's operating system and browser; the certificate data may be Cookies, which stores the user's status information when sending a network request.
[0072] Step S120, using a preset feature data matching rule to match the feature data in the network request data to obtain a quantity matching result of the feature data in each piece of the network request data; using the request address data of each piece of the legal request data to train a pre-constructed hidden Markov model to obtain a first calculation model, wherein the first calculation model is used to calculate the text sequence generation probability of the request address data in the network request data; using the first calculation model to calculate the text sequence generation probability of the request address data in each piece of the network request data.
[0073] Specifically, the regular expression matching rules for request address data, the regular expression matching rules for user agent data, and the regular expression matching rules for certificate data preset in the database are retrieved, and data matching is performed on the request address data, user agent data, and certificate data respectively to obtain the number of request address data matches, the number of user agent data matches, and the number of certificate data matches in each piece of network request data.
[0074] A hidden Markov model is pre-built, and the request address data of the legitimate request data in the sample data is retrieved to train the hidden Markov model to obtain a first calculation model, that is, a text sequence generation probability calculation model of the request address data. After the first calculation model is trained, the first calculation model is used to calculate the text sequence generation probability of the request address data in each network request data.
[0075] Step S130, generating a feature vector for each piece of the network request data according to the quantity matching result and the text sequence generation probability, using the feature vector to train a pre-built first logistic regression model to obtain a second calculation model, and the second calculation model is used to determine the legal probability of the network request data.
[0076] Specifically, a first logistic regression model is pre-constructed, and a feature vector is generated according to the number of request address data matches, the number of user agent data matches, the number of certificate data matches, and the text sequence generation probability of the request address data of each network request data. The feature vector is used to train the first logistic regression model to obtain a second calculation model, namely, a legal probability calculation model for network request data.
[0077] In this embodiment, multiple network request data can be obtained as labeled sample data, and the network request data can use historical network request data, and the sample data includes legal request data and illegal request data. Extract feature data from each network request data, and the feature data may include request address data, user agent data, and certificate data, etc. Use preset feature data matching rules to match the feature data in each network request data, and obtain the quantity matching result of the feature data in each network request data. The data matching result is used as a numerical feature. Use the request address data of the legal request data to train the pre-constructed hidden Markov model to obtain the first calculation model, and use the first calculation model to calculate the text sequence generation probability of the request address data in each network request data. The text sequence generation probability is used as another numerical feature to abstract the network request data into a numerical feature, which can obtain its internal information to the greatest extent and improve the accuracy of the model obtained by subsequent training. The first logistic regression model is trained using a feature vector composed of a quantity matching result and a text sequence generation probability to obtain a second calculation model, which is used to determine the legal probability of network request data to classify the network request data. For example, the legal probability of network request data can be compared with a preset threshold, and the network request data is determined to be legal request data or illegal request data according to the comparison result. In the present invention, a machine learning algorithm is used to learn the laws of network request data from multiple dimensions. Compared with the regular expression matching method with a fixed format used in the prior art to classify network request data, the trained second calculation model has a higher classification accuracy. And the second calculation model can be continuously optimized according to the input network request data, which is difficult to be cracked, greatly improving security. Moreover, when facing illegal request data generated by a new assembly method, the present invention can also identify and intercept according to the general laws of learning, with a wide range of applications and high classification accuracy.
[0078] Optionally, the network request data classification model further includes a third computing model, and after the first logistic regression model pre-built by using the feature vector to train is obtained, the second computing model further includes:
[0079] All the network request data within a specified time period are acquired, and all the network request data within the specified time period are grouped according to users to determine the network request data of each user.
[0080] Specifically, the network request data of a specified time period is obtained from all network request data. For example, all network request data from the 10th minute to the 20th minute are selected from the sample data. The specified time period can be set according to actual conditions. All network request data obtained within the specified time period are grouped according to users. All network request data corresponding to the same user are grouped together to obtain data groups for each user. Each data group includes all network request data of the corresponding user within the time period.
[0081] The cosine similarity algorithm is used to calculate the text similarity of the request address data in each piece of the network request data, and the second calculation model is used to calculate the legitimacy probability of each piece of the network request data.
[0082] Specifically, the request address data in each network request data is extracted, the cosine similarity algorithm is used to calculate the similarity of each request address data compared with other request address data, and the second calculation model is used to calculate the legitimacy probability of each network request data. It should be noted that before the network request data is input into the second calculation model, it is necessary to first process the network request data according to the methods of steps S110 to S130 above, which will not be repeated here.
[0083] A pre-constructed second logistic regression model is trained according to the text similarities and the legal probabilities corresponding to all the network request data of each of the users to obtain a third calculation model, wherein the third calculation model is used to determine the probability that the user is a high-risk user.
[0084] Specifically, a second logistic regression model is pre-constructed. For any user, training data is generated according to the text similarity and legal probability corresponding to the network request data of the user. The second logistic regression model is trained using the training data corresponding to each user to obtain a trained second logistic regression model. The trained second logistic regression model is the third calculation model, i.e., the high-risk user probability calculation model, which is used to determine the probability that the user is a high-risk user.
[0085] In this optional embodiment, network request data within a specified period of time is extracted from sample data, and the extracted network request data is grouped according to users, the text similarity corresponding to the network request data of each user is calculated using the cosine similarity algorithm, and the second calculation model is used to calculate the legal probability of the network request data of each user, and the training data generated by the corresponding text similarity and legal probability is used to train the second logistic regression model to obtain a third calculation model. The third calculation model can be used to determine the probability that the user is a high-risk user. On the basis of using the second model to calculate the legal probability of the network request data to classify the network request data, user risk detection is added, and users can be classified, further improving the security of the network request data, and it is conducive to managing users and improving the convenience of user management. Compared with the prior art of judging the user type based on personal experience, the trained third calculation model can learn the characteristics of high-risk users, and can dynamically judge whether the user is a high-risk user based on the network request data, thereby improving the accuracy of judging whether the user is a high-risk user.
[0086] Optionally, the using the request address data of each piece of the legal request data to train a pre-built hidden Markov model to obtain a first calculation model comprises:
[0087] The request address data of each piece of the legal request data is segmented to obtain a plurality of segmented data.
[0088] Specifically, the Request-URL of the legal request data is segmented according to character strings and symbols.
[0089] Each of the segmented data is marked to obtain the marked data, wherein the segmented data of the same character string are marked as the same value, and the segmented data of different symbols are marked as different values.
[0090] Based on a forward-backward algorithm, the labeled data is used to train the hidden Markov model to obtain the first computing model.
[0091] Specifically, the first computing model includes an initial probability matrix, a state transfer matrix and a transmission matrix. By training the hidden Markov model, a trained hidden Markov model, namely the first computing model, is obtained, and the initial probability matrix, state transfer matrix and transmission matrix in the first computing model are determined.
[0092] Among them, the calculation formula of the initial probability matrix includes:
[0093]
[0094] Among them, q i represents the initial probability of value i, Qi Indicates the occurrence of value i, ∑Q represents the total number of values, that is, the total number of data after segmentation, where the value is the state.
[0095] The calculation formula of the state transfer matrix includes:
[0096] a ij =C(i→j) / ∑ q∈Q C(i→q),
[0097] Among them, a ij represents the probability of value i jumping to value j, C(i→j) represents the number of times value i jumps to value j, and C(i→q) represents all jumps starting from value i.
[0098] The calculation formula of the emission matrix includes:
[0099]
[0100] Among them, b j (v k ) indicates that the value is j and the observation state is v k The probability of t represents the observation state at time t, s t represents the state at time t, 1 [·] represents the indicator function, and T is the preset period.
[0101] In this optional embodiment, the request address data of the legitimate request data is used to train a preset hidden Markov model to obtain a first computing model. In the process of training the first computing model, the characteristics of the request address data in the legitimate request data can be learned, so that the trained first computing model can determine whether the network request data is legitimate request data from the dimension of the request address data, thereby improving the accuracy of the classification of the network request data.
[0102] Optionally, the adopting the feature vector to train a pre-constructed first logistic regression model to obtain a second calculation model comprises:
[0103] The feature vector is input into the first logistic regression model, and the corresponding legal probability of the network request data is output, wherein the first logistic regression model is represented by a first formula, and the first formula includes:
[0104]
[0105] Where X represents the legal probability of the network request data, k j represents the parameters of the first logistic regression model, W j represents the jth element in the feature vector.
[0106] Specifically, a feature vector of each piece of the network request data is generated according to the quantity matching result and the text sequence generation probability, including combining the request address data matching quantity, the user agent data matching quantity, the certificate data matching quantity and the text sequence generation probability of the request address data of the network request data into a feature vector. The feature vector can be expressed as:
[0107] V i =[W i1 ,W i2 ,W i3 ,W i4 ],
[0108] Among them, V i The feature vector representing the i-th network request data, W i1 represents the number of regular matches of the user agent data of the i-th data, W i2 represents the number of regular matches of the certificate data of the i-th data, W i3 Indicates the number of regular matches of the request address of the i-th data, W i4 Represents the probability of generating a text sequence for the i-th data.
[0109] The legitimacy probability is compared with a first preset threshold, and a first predicted label of the network request data is determined according to the comparison result.
[0110] Specifically, the first preset threshold may be 0.5. When the legal probability is greater than 0.5, the corresponding network request data is identified as legal request data; when the legal probability is less than or equal to 0.5, the corresponding network request data is identified as illegal request data, and the first prediction label includes legal or legitimate request data.
[0111] Optimize the parameters of the first logistic regression model according to the first predicted label and the first actual label of the network request data until the accuracy of the first logistic regression model meets a first preset condition, thereby obtaining the second calculation model.
[0112] Specifically, the initially acquired network request data is labeled data, and after artificial screening of the network request data in advance, the legal request data and illegal request data in the network request data have been separated, and the label of each network request data has been determined. The first actual label includes the legal request data and the illegal request data. Based on the preset loss function, the difference between the first predicted label and the first actual label can be determined. The loss function can be specifically set according to the actual situation and is not limited here. For example, the cross entropy loss function, etc., is used to optimize the parameter k of the first logistic regression model according to the difference. j, until the difference between the first predicted label and the first actual label determined after processing by the first logistic regression model meets the first preset condition, and the first preset condition can be specifically set according to the actual situation, then the trained first logistic regression model is obtained, that is, the second calculation model.
[0113] In this optional embodiment, compared with the prior art that uses a single regular expression matching method to determine whether the network request data is legal request data, a feature data matching rule is used to match the feature data in the network request data, and the feature of the network request data is determined from the dimension of the number matching result of the feature data. The first computing model is used to calculate the text sequence generation probability of the request address data in the network request data, and the feature of the network request data is determined from the dimension of the text sequence generation probability of the request address data. The feature vector composed of the number matching result and the text sequence generation probability is used to train the first logistic regression model, so that the trained second computing model can learn the rules of legal request data from multiple dimensions, improve the accuracy of the second computing model in calculating the legal probability of the network request data, and then improve the accuracy of the classification of the network request data. Among them, the network request data is abstracted into numerical features, which can obtain the internal information of the network request data to the greatest extent and improve the accuracy of the trained second computing model.
[0114] Optionally, the using a cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the network request data includes:
[0115] Segmenting the request address data in each piece of the network request data according to word meanings to obtain word sequences corresponding to each piece of the network request data;
[0116] Each of the word sequences is encoded respectively to obtain an encoding vector corresponding to each piece of the network request data.
[0117] Specifically, the encoding vector is represented as v i =[a1,a2,a3,…,a j ], where v i Represents the encoding vector of the i-th network request data, a j Indicates whether there is word j in the preset vocabulary.
[0118] Based on the cosine similarity algorithm, the text similarity corresponding to each piece of the network request data is calculated using a second formula according to the encoding vector, and the second formula includes:
[0119]
[0120] Among them, θ i represents the text similarity corresponding to the i-th network request data, v irepresents the encoding vector corresponding to the i-th network request data, v j Represents the encoding vector corresponding to the j-th network request data.
[0121] In this optional embodiment, the cosine similarity algorithm can be used to determine the similarity between one network request data and other network request data. When the text similarity training model calculated by the pre-similarity algorithm is used, the trained model can make predictions from the dimension of similarity between network request data. For example, if one network request data deviates greatly from other network request data, then the network request data may be abnormal, which can improve the accuracy of the trained model.
[0122] Optionally, the step of training a pre-built second logistic regression model according to the text similarities and the legal probabilities corresponding to all the network request data of each user to obtain the third calculation model specifically includes:
[0123] For any of the users, a similarity mean is calculated based on the text similarities corresponding to all the network request data of the user within the specified time period, and a probability mean is calculated based on the legitimacy probabilities corresponding to all the network request data of the user within the specified time period.
[0124] The similarity mean and the probability mean are input into the second logistic regression model, and the corresponding probability of the user being a high-risk user is output. The second logistic regression model is represented by a third formula, and the third formula includes:
[0125]
[0126] Among them, X P represents the probability that the user is a high-risk user, avg1 represents the similarity mean, avg2 represents the probability mean, T1 and T2 represent the parameters of the second logistic regression model.
[0127] The probability that the user is a high-risk user is compared with a second preset threshold, and a second prediction label of the second logistic regression model is determined according to the comparison result.
[0128] Specifically, the second preset threshold may be 0.5. When the probability that the user is a high-risk user is greater than 0.5, the user is identified as a high-risk user; when the probability that the user is a high-risk user is less than or equal to 0.5, the user is identified as a non-high-risk user. The second prediction label includes high-risk users and non-high-risk users.
[0129] Optimize the parameters of the second logistic regression model according to the second predicted label and the second actual label of the user until the accuracy of the second logistic regression model meets a second preset condition, thereby obtaining the third calculation model.
[0130] Specifically, it can be determined in advance whether each user is a high-risk user or a non-high-risk user, and manual determination and other methods can be used, wherein high-risk users and non-high-risk are used as the second actual label of the user. Based on a preset loss function, the difference between the second predicted label and the second actual label can be determined. The loss function can be specifically set according to the actual situation, and is not limited here, such as a cross entropy loss function, etc. The parameters T1 and T2 of the second logistic regression model are optimized according to the difference, and the second logistic regression model is trained iteratively in a loop to obtain more accurate parameters until the difference between the second predicted label and the second actual label determined after the second logistic regression model is processed meets the second preset condition. The second preset condition can be specifically set according to the actual situation to obtain a trained second logistic regression model, that is, a third calculation model.
[0131] In this optional embodiment, compared to judging whether a user is a high-risk user based on manual experience, the third computing model is obtained by training the text similarity and legal probability corresponding to the network request data input by the user, so that the third computing model can learn the characteristics of text similarity and legal probability, as well as the relationship between these characteristics and user types. The text similarity can characterize the similarity between the network request data input by the user and other users, and the legal probability can characterize the probability that the network request data input by the user is legal request data. The correlation between these characteristics and the user type is high, which can improve the accuracy of the trained third computing model. The use of the third computing model can dynamically determine the type of the user based on the network request data input by the user in real time, thereby improving the convenience of user management.
[0132] like Figure 2 As shown, another embodiment of the present invention provides a network request data classification method, comprising:
[0133] Step S210, obtaining target network request data to be classified, and extracting target feature data from the target network request data, wherein the target feature data includes target request address data;
[0134] Step S220, using a preset feature data matching rule to match the target feature data in the target network request data to obtain a quantity matching result of the target feature data; inputting the target request address data into a first calculation model, and outputting a text sequence generation probability of the target request address data;
[0135] Step S230, generating a target feature vector of the target network request data according to the quantity matching result and the text sequence generation probability, inputting the target feature vector into a second calculation model, and outputting a legal probability of the target network request data;
[0136] Step S240, comparing the legal probability with a first preset threshold, and determining the data type of the target network request data according to the comparison result, the data type including legal request data and illegal request data;
[0137] The first computing model and the second computing model are trained using the network request data classification model training method described above.
[0138] Specifically, the specific processing steps in the network request data classification method of this embodiment are the same as the corresponding processing steps in the above-mentioned network request data classification model training method, and will not be repeated here.
[0139] In this embodiment, the target network request data to be classified is obtained, and the target feature data in the target network request data is extracted. The target feature data in the target network request data is matched using a preset feature data matching rule, and the numerical features of the target feature data are extracted from the feature data dimension to obtain the quantity matching quantity. The target request address data is input into the network request data classification model training method described in any one of the first aspects to obtain a first calculation model, and the numerical features are extracted from the target request address data dimension, and the text sequence generation probability is output. The target feature vector composed of the quantity matching result and the text sequence generation probability is input into the network request data classification model training method described in any one of the first aspects to obtain a second calculation model, and the legal probability of the target network request data is output, and the data type of the target network request data is determined according to the comparison result of the legal probability and the first preset threshold. The present invention extracts the numerical features of the network request data from multiple dimensions, and calculates the legal probability of the target network request data according to the numerical features of multiple dimensions to realize the classification of the target network request data, which effectively improves the accuracy of the classification of the network request data.
[0140] Optionally, an embodiment of the present invention provides a network request data classification method, including:
[0141] Obtaining all target network request data of the target user within a specified time period;
[0142] Using a cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the target network request data, and using the second calculation model to calculate the legal probability of each piece of the target network request data;
[0143] Determine a similarity mean of all the text similarities and a probability mean of all the legal probabilities, input the similarity mean and the probability mean into a third calculation model, and output a probability that the target user is a high-risk user;
[0144] Comparing the probability that the target user is a high-risk user with a second preset threshold, and determining the user type of the target user according to the comparison result, wherein the user type includes high-risk users and non-high-risk users;
[0145] The third computing model is trained using the network request data classification model training method described above.
[0146] The specific implementation steps of this optional embodiment correspond to the specific steps of training the third computing model in the above-mentioned network request data classification model training method, and will not be repeated here.
[0147] In this optional embodiment, the third computing model is trained using the above-mentioned network request data classification model training method to calculate the probability that the user is a high-risk user, and then the target user is classified. On the basis of the original determination of the data type of the network request data, user risk detection is added to improve the convenience of user management. Moreover, compared with the prior art of judging the user type based on manual experience, the third computing model can dynamically determine whether the corresponding user is a high-risk user based on the target network request data, thereby improving the accuracy and real-time performance of user classification.
[0148] Optionally, after determining the user type of the target user according to the comparison result, the method further includes:
[0149] If the target user is a high-risk user, the target user is added to the blacklist and all network request data of the target user are rejected;
[0150] If the target user is not a high-risk user, receiving the network request data of the target user is allowed.
[0151] In this optional embodiment, users are managed in a targeted manner according to their types. If the target user is a high-risk user, the target user is added to a blacklist and all network request data of the target user is rejected, thereby effectively improving network security and ensuring network security.
[0152] like Figure 3 As shown, another embodiment of the present invention provides a network request data classification model training device, wherein the network request data classification model includes a first calculation model and a second calculation model, including:
[0153] An acquisition module, used to acquire multiple network request data and extract characteristic data from each of the network request data, wherein the network request data includes legal request data and the characteristic data includes request address data;
[0154] A processing module, configured to match the feature data in the network request data using a preset feature data matching rule to obtain a quantity matching result of the feature data in each piece of the network request data; train a pre-constructed hidden Markov model using the request address data of each piece of the legal request data to obtain a first calculation model; and calculate the text sequence generation probability of the request address data in each piece of the network request data using the first calculation model;
[0155] A training module is used to generate a feature vector for each piece of the network request data according to the quantity matching result and the text sequence generation probability, and use the feature vector to train a pre-built first logistic regression model to obtain a second calculation model, wherein the second calculation model is used to determine the legal probability of the network request data.
[0156] The device is used to implement the above network request data classification model training method, and the specific content will not be repeated here.
[0157] like Figure 4 As shown, another embodiment of the present invention provides a network request data classification device, comprising:
[0158] An acquisition module, used for acquiring target network request data to be classified, and extracting target feature data from the target network request data, wherein the target feature data includes target request address data;
[0159] A processing module, configured to match the target feature data in the target network request data using a preset feature data matching rule to obtain a quantity matching result of the target feature data; input the target request address data into a first calculation model, and output a text sequence generation probability of the target request address data;
[0160] A prediction module, configured to generate a target feature vector of the target network request data according to the quantity matching result and the text sequence generation probability, input the target feature vector into a second calculation model, and output a legal probability of the target network request data;
[0161] A classification module, used to compare the legal probability with a first preset threshold, and determine the data type of the target network request data according to the comparison result, wherein the data type includes legal request data and illegal request data;
[0162] The first computing model and the second computing model are trained using the network request data classification model training method described above.
[0163] The device is used to implement the network request data classification method as described above, and the specific content will not be repeated here.
[0164] Another embodiment of the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program, and when the computer program is executed by the processor, the network request data classification model training method or the network request data classification method as described above is implemented.
[0165] Another embodiment of the present invention provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the network request data classification model training method or the network request data classification method as described above is implemented.
[0166] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc. In the present application, the unit described as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or it may be distributed on multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the embodiment of the present invention. In addition, each functional unit in each embodiment of the present invention can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of a software functional unit.
[0167] Although the disclosure is disclosed as above, the protection scope of the disclosure is not limited thereto. Those skilled in the art may make various changes and modifications without departing from the spirit and scope of the disclosure, and these changes and modifications will fall within the protection scope of the present invention.
Claims
1. A network request data classification model training method, characterized in that: The network request data classification model includes a first calculation model and a second calculation model, including: Acquire multiple pieces of network request data, and extract characteristic data from each piece of the network request data, wherein the network request data includes legal request data, and the characteristic data includes request address data; The feature data in the network request data are matched using a preset feature data matching rule to obtain a quantity matching result of the feature data in each piece of the network request data; the request address data of each piece of the legal request data is used to train a pre-constructed hidden Markov model to obtain a first calculation model; the first calculation model is used to calculate the text sequence generation probability of the request address data in each piece of the network request data; The step of training a pre-built hidden Markov model using the request address data of each piece of the legal request data to obtain a first calculation model includes: Segmenting the request address data of each piece of the legitimate request data to obtain a plurality of segmented data; Marking each of the segmented data to obtain marked data, wherein the segmented data of the same character string are marked with the same value, and the segmented data of different characters are marked with different values; Based on a forward-backward algorithm, the labeled data is used to train the hidden Markov model to obtain the first calculation model; Generate a feature vector for each piece of the network request data according to the quantity matching result and the text sequence generation probability, use the feature vector to train a pre-built first logistic regression model to obtain a second calculation model, the second calculation model is used to determine the legal probability of the network request data, wherein the quantity matching result includes a request address quantity matching result, a user agent data quantity matching result and a certificate data quantity matching result, and the generating of the feature vector for each piece of the network request data according to the quantity matching result and the text sequence generation probability includes: Generate the feature vector according to the request address quantity matching result, the user agent data quantity matching result, the certificate data quantity matching result and the text sequence generation probability of each piece of the network request data; The adopting the feature vector to train the pre-built first logistic regression model to obtain the second calculation model comprises: The feature vector is input into the first logistic regression model, and the corresponding legal probability of the network request data is output, wherein the first logistic regression model is represented by a first formula, and the first formula includes: Where X represents the legal probability of the network request data, k j represents the parameters of the first logistic regression model, W j represents the jth element in the feature vector; Comparing the legal probability with a first preset threshold, and determining a first prediction label of the network request data according to the comparison result; Optimize the parameters of the first logistic regression model according to the first predicted label and the first actual label of the network request data until the accuracy of the first logistic regression model meets a first preset condition, thereby obtaining the second calculation model.
2. The network request data classification model training method according to claim 1, characterized in that: The network request data classification model further includes a third computing model. After the feature vector is used to train the pre-built first logistic regression model to obtain the second computing model, the model further includes: Acquire all the network request data within a specified time period, and group all the network request data within the specified time period according to users to determine the network request data of each user; Using a cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the network request data, and using the second calculation model to calculate the legal probability of each piece of the network request data; A pre-constructed second logistic regression model is trained according to the text similarities and the legal probabilities corresponding to all the network request data of each of the users to obtain a third calculation model, wherein the third calculation model is used to determine the probability that the user is a high-risk user.
3. The network request data classification model training method according to claim 2, characterized in that: The method of using the cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the network request data includes: Segmenting the request address data in each piece of the network request data according to word meanings to obtain word sequences corresponding to each piece of the network request data; Encode each of the word sequences respectively to obtain an encoding vector corresponding to each piece of the network request data; Based on the cosine similarity algorithm, the text similarity corresponding to each piece of the network request data is calculated using a second formula according to the encoding vector, and the second formula includes: Among them, θ i represents the text similarity corresponding to the i-th network request data, v i represents the encoding vector corresponding to the i-th network request data, v j Represents the encoding vector corresponding to the j-th network request data.
4. The network request data classification model training method according to claim 2 or 3, characterized in that: The training of the pre-built second logistic regression model according to the text similarity and the legal probability corresponding to all the network request data of each user to obtain the third calculation model comprises: For any of the users, a similarity mean is calculated based on the text similarities corresponding to all the network request data of the user within the specified time period, and a probability mean is calculated based on the legitimacy probabilities corresponding to all the network request data of the user within the specified time period; The similarity mean and the probability mean are input into the second logistic regression model, and the corresponding probability of the user being a high-risk user is output. The second logistic regression model is represented by a third formula, and the third formula includes: Among them, X P represents the probability that the user is a high-risk user, avg1 represents the similarity mean, avg2 represents the probability mean, T1 and T2 represent the parameters of the second logistic regression model; Comparing the probability that the user is a high-risk user with a second preset threshold, and determining a second prediction label of the second logistic regression model according to the comparison result; Optimize the parameters of the second logistic regression model according to the second predicted label and the second actual label of the user until the accuracy of the second logistic regression model meets a second preset condition, thereby obtaining the third calculation model.
5. A network request data classification method, characterized in that: include: Acquire target network request data to be classified, and extract target feature data from the target network request data, wherein the target feature data includes target request address data; The target feature data in the target network request data is matched using a preset feature data matching rule to obtain a quantity matching result of the target feature data; the target request address data is input into a first calculation model to output a text sequence generation probability of the target request address data; Generate a target feature vector of the target network request data according to the quantity matching result and the text sequence generation probability, input the target feature vector into a second calculation model, and output a legal probability of the target network request data; Comparing the legal probability with a first preset threshold, and determining the data type of the target network request data according to the comparison result, the data type including legal request data and illegal request data; The first computing model and the second computing model are trained using the network request data classification model training method as described in any one of claims 1 to 4.
6. The network request data classification method according to claim 5, characterized in that: Also includes: Obtaining all target network request data of the target user within a specified time period; Using a cosine similarity algorithm to calculate the text similarity of the request address data in each piece of the target network request data, and using the second calculation model to calculate the legal probability of each piece of the target network request data; Determine a similarity mean of all the text similarities and a probability mean of all the legal probabilities, input the similarity mean and the probability mean into a third calculation model, and output a probability that the target user is a high-risk user; Comparing the probability that the target user is a high-risk user with a second preset threshold, and determining the user type of the target user according to the comparison result, wherein the user type includes high-risk users and non-high-risk users; Wherein, the third computing model is trained using the network request data classification model training method as described in any one of claims 2, 3 and 4.
7. The network request data classification method according to claim 6, characterized in that: After determining the user type of the target user according to the comparison result, the method further includes: If the target user is a high-risk user, the target user is added to the blacklist and all network request data of the target user are rejected; If the target user is not a high-risk user, receiving the network request data of the target user is allowed.
8. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, it implements the network request data classification model training method as described in any one of claims 1 to 4, or the network request data classification method as described in any one of claims 5 to 7.
