CTR prediction optimization method based on differentiable precision and recall
By calculating the difference between the predicted value and the threshold in the CTR prediction model, differentiable precision and recall are obtained and integrated into the loss function, which solves the problem of non-differentiability in traditional methods and improves the training efficiency and prediction performance of the model.
Patent Information
- Application Number
- CN202411920564.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2044-12-25
AI Technical Summary
In the optimization process of traditional CTR prediction models, the calculation of precision, recall and F1-Score is not differentiable, which limits the improvement of model performance and results in low computational efficiency, especially when processing large-scale data, the computational complexity increases significantly.
By constructing a CTR prediction model, the difference between the predicted value and the threshold is calculated, and differentiable precision and recall are calculated based on the difference. These are then integrated into the loss function, and the loss function is minimized using a gradient optimization algorithm to optimize the model parameters.
This enables efficient training and optimization of the CTR prediction model, improving its predictive ability and computational efficiency in imbalanced data environments, and enhancing its evaluation accuracy and generalization ability.
Smart Images

Figure CN119760242B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of CTR prediction optimization technology, and in particular to a CTR prediction optimization method based on differentiable precision and recall. Background Technology
[0002] In recommender systems, click-through rate (CTR) prediction is a crucial task, aiming to predict the probability of a user clicking on a recommended item. Precision, recall, and F1-Score are important metrics for evaluating the performance of CTR prediction models. Precision measures the proportion of instances predicted as positive by the model that are actually positive, reflecting the model's accuracy. Recall measures the proportion of all truly positive instances that were correctly predicted as positive by the model, reflecting the model's coverage. The F1-Score is the harmonic mean of precision and recall, used to comprehensively evaluate the model's performance.
[0003] In traditional methods, the calculation of these metrics typically relies on threshold setting, conditional judgment, and ranking operations. For example, to calculate precision and recall, a threshold must first be set based on the model's predicted probability, the predicted results are binarized into positive or negative samples, then conditional judgments are made based on the true labels, and finally, ranking operations are used to calculate the metric values. While these methods are intuitive and easy to understand, they suffer from numerous problems during optimization.
[0004] Traditional methods for calculating precision, recall, and F1-score are often non-differentiable during optimization, making them unsuitable for direct application in gradient optimization algorithms and limiting further improvements in model performance. When dealing with large-scale data, traditional methods are computationally inefficient. This is especially true when sorting operations are involved, where computational complexity increases significantly, leading to longer training times and increased resource consumption. Summary of the Invention
[0005] To address the issue that existing traditional methods for calculating precision, recall, and F1-Score are often non-differentiable during the optimization process, thus limiting their direct application in gradient optimization algorithms and hindering further improvements in model performance, this application provides a CTR prediction optimization method based on differentiable precision and recall, comprising the following steps:
[0006] Collect user click behavior data and divide the behavior data into training set and test set;
[0007] The training set is preprocessed to obtain training data, and the data features of the training set are encoded and standardized.
[0008] Based on preset conditions, the features of the data after encoding and standardization are filtered, and high-level features of the data are extracted using feature engineering methods to obtain training features.
[0009] Construct a CTR prediction model by inputting the training data and the training features into the CTR prediction model;
[0010] After the output layer of the CTR prediction model, the difference between the predicted value and the threshold is calculated;
[0011] Based on the differences, calculate the differentiable precision and recall.
[0012] The differentiable precision and recall are integrated into the loss function of the CTR prediction model, and the loss function is minimized by an optimization algorithm to obtain the trained CTR prediction model.
[0013] The test set is input into the trained CTR prediction model, and the AUC-PR metric is calculated.
[0014] When the AUC-PR metric meets the preset standard metric, the CTR prediction model is completed and deployed.
[0015] In one feasible implementation, the behavioral data includes user feature data, item feature data, and context feature data, and the preprocessing operations include data cleaning, data deduplication, and handling of missing data values.
[0016] In one feasible implementation, the step of calculating the differentiable precision and recall based on the difference includes:
[0017] Calculate the difference between the predicted value and the threshold, take the absolute value of the difference and normalize it, and adjust the range of the difference after normalization to obtain the first variable score1;
[0018] Calculate the product of the first variable score1 and the true label, retain the predicted samples whose true label is positive, and obtain the second variable score2;
[0019] Sum the second variable score2 to obtain the number of samples score3 where all predicted samples are positive samples and the true label is a positive sample;
[0020] Sum the first variable score1 to obtain the number of all predicted positive samples score4.
[0021] Sum the values of the true labels to obtain the number of samples whose true labels are positive (score5).
[0022] The differentiable precision and recall are calculated based on the number of samples with positive true labels (score3), the number of predicted samples with positive true labels (score4), and the number of samples with positive true labels (score5).
[0023] In one feasible implementation, the formulas for calculating the differentiable precision and recall based on the number of samples with positive true labels (score3), the number of predicted positive samples (score4), and the number of samples with positive true labels (score5) are as follows:
[0024] Precision=score3 / (score4+ε);
[0025] Recall=score3 / (score5+ε);
[0026] In the formula: ε is the preset minimum value, Precision is the precision rate, and Recall is the recall rate.
[0027] In one feasible implementation, the step of adjusting the range of the normalized differences includes:
[0028] Add 1 to the difference after normalization and multiply by 0.5 to obtain the first variable, score1.
[0029] In one feasible implementation, the optimization algorithm minimizes the following: gradient descent, stochastic gradient descent, and dynamic learning rate adjustment algorithm.
[0030] In one feasible implementation, the step of integrating the differentiable precision and recall into the loss function of the CTR prediction model further includes:
[0031] Calculate the cross-entropy loss using Keras backend functions;
[0032] The loss function is formed by combining the cross-entropy loss, the differentiable precision, and the recall according to given weighting coefficients.
[0033] As described above, this application provides a CTR prediction optimization method based on differentiable precision and recall. This method approximates the calculation of precision and recall using mathematical expressions, eliminating the dependence on thresholds, conditional judgments, and ranking. It can be directly used in the gradient optimization process and possesses high computational efficiency. This method can be integrated into the loss function of the CTR prediction model, improving the model's predictive ability and computational efficiency in imbalanced data environments. Simultaneously, this method can also be used to calculate the area under the PR curve (AUC-PR), further improving the accuracy of model evaluation. This application integrates differentiable precision and recall into the loss function and minimizes the loss function through an optimization algorithm, making the model training process more efficient and stable. Attached Figure Description
[0034] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the implementation of the invention and, together with the description, serve to explain the principles of the embodiments of the invention. It is obvious that the drawings described below are merely some embodiments of the invention, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort.
[0035] Figure 1 This is a flowchart illustrating an exemplary embodiment of the CTR prediction optimization method based on differentiable precision and recall. Detailed Implementation
[0036] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that the embodiments of the invention will be more comprehensive and complete, and will fully convey the concept of the exemplary embodiments to those skilled in the art. The described features, mechanisms, or characteristics may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a full understanding of how embodiments of the invention are carried out.
[0037] In recommender systems, click-through rate (CTR) prediction is a crucial task, aiming to predict the probability of a user clicking on a recommended item. Precision, recall, and F1-score are important metrics for evaluating the performance of CTR prediction models. However, traditional methods for calculating these metrics rely on threshold settings, conditional judgments, and ranking operations. These operations are often non-differentiable during optimization, making them difficult to directly apply to gradient optimization algorithms. Furthermore, traditional methods are computationally inefficient when handling large-scale data, especially when ranking is involved, where computational complexity increases significantly. Therefore, there is an urgent need for a differentiable and computationally efficient method to calculate these performance metrics to optimize the performance of CTR prediction models.
[0038] To address the aforementioned problems, this application provides a CTR prediction optimization method based on differentiable precision and recall, referring to... Figure 1 As shown, the steps include:
[0039] S100: Collect user click behavior data and divide the behavior data into training set and test set.
[0040] In some embodiments, behavioral data includes user feature data, item feature data, and contextual feature data, wherein the training set is used for training and optimizing the model, and the test set is used for evaluating the model's performance.
[0041] Collecting behavioral data can provide sufficient data support for the model, ensuring that the model can learn the patterns and rules of user behavior. By dividing the training set and the test set, the generalization ability of the model can be objectively evaluated.
[0042] S200: Perform preprocessing operations such as processing the training set to obtain training data, and encode and standardize the data features of the training set.
[0043] In some embodiments, preprocessing operations include: data cleaning, data deduplication, and handling of missing values. The data features of the training set are encoded and standardized, such as through one-hot encoding, label encoding, normalization, and standardization. Preprocessing operations can improve data quality and reduce the impact of noise on model training.
[0044] Furthermore, encoding and standardization processes give features a uniform dimension and distribution, which is beneficial for model training and optimization.
[0045] S300: Based on preset conditions, the features of the encoded and standardized data are selected, and feature engineering methods are used to extract high-level data features to obtain training features.
[0046] Feature engineering methods, including Principal Component Analysis (PCA) and Linear Discriminant Analysis (LDA), can remove redundant and irrelevant features, reduce model complexity, and improve training efficiency. Simultaneously, extracting high-level features can better capture patterns and regularities in user behavior, thereby improving the model's predictive performance.
[0047] S400: Build a CTR prediction model by inputting training data and training features into the CTR prediction model.
[0048] CTR prediction models include logistic regression models, support vector machine models, deep learning models, etc. This application does not impose specific restrictions. This step builds a model framework for predicting user click behavior, and then inputs the processed data into CTR prediction to provide data support for the training and optimization of CTR prediction.
[0049] S500: After the output layer of the CTR prediction model, calculate the difference between the predicted value and the threshold, and calculate the differentiable precision and recall based on the difference.
[0050] Here, the predicted value refers to the output of the CTR prediction model, while the threshold is a preset value used to determine whether the predicted value meets a certain condition (such as whether it belongs to a certain category). Calculating the difference between the predicted value and the threshold is equivalent to calculating the difference between these two values, and this difference can be used to evaluate the reliability or accuracy of the prediction results.
[0051] Specifically, based on the differences, differentiable precision and recall are calculated. These differentiable precision and recall can be used as part of the loss function to guide model training and optimization. This, in turn, evaluates the model's predictive performance and serves as an optimization objective.
[0052] S600: Integrates differentiable precision and recall into the loss function of the CTR prediction model, and minimizes the loss function through an optimization algorithm to obtain a trained CTR prediction model;
[0053] A loss function is used to optimize a model. In machine learning and deep learning, a loss function (or cost function) is a function that measures the difference between the model's predictions and the actual results. The purpose of constructing a loss function is to find an optimal set of model parameters during model training, so that the model's predictions are as close as possible to the actual results. Loss functions integrate differentiable precision and recall, as well as traditional loss functions, such as the cross-entropy loss function. The aim is to optimize the model not only by considering its CTR prediction ability, but also by simultaneously optimizing the two important performance metrics of precision and recall.
[0054] During the model training phase, the model is trained using a training dataset, and an optimization algorithm is used to minimize the loss function. For example, gradient descent. Gradient descent calculates the gradient of the loss function with respect to the model parameters and updates the model parameters based on this gradient information to gradually reduce the value of the loss function. Through continuous iteration of the training process, the model parameters gradually converge to an optimal solution (or near-optimal solution). At this point, the model's prediction results will be as close as possible to the actual results, and precision, recall, and CTR prediction ability will all be optimized.
[0055] S700: Input the test set into the trained CTR prediction model and calculate the AUC-PR metric. AUC-PR is one of the important metrics for evaluating the performance of a CTR prediction model, as it considers the balance between precision and recall. By calculating the AUC-PR metric, the predictive performance of the model can be objectively evaluated and compared with preset standard metrics.
[0056] S800: When the AUC-PR metric meets the preset standard, the CTR prediction model is completed and deployed. When the AUC-PR metric meets the preset standard, the model is considered to have been trained successfully and achieved the expected predictive performance. The trained CTR prediction model is deployed to the actual production environment to predict user click behavior. Specifically, in practical applications, the method of this application can be used to calculate the area under the PR curve (AUC-PR), further improving the accuracy of model evaluation.
[0057] As described above, the CTR prediction optimization method based on differentiable precision and recall provided in this application significantly improves the prediction performance of the CTR prediction model by introducing differentiable precision and recall as part of the loss function and continuously optimizing the model parameters. By dividing the training and test sets and using evaluation metrics such as AUC-PR, the generalization ability of the model can be objectively assessed, ensuring the stability and reliability of the model in practical applications. Through feature selection and extraction steps, redundant and irrelevant features can be removed, and high-level features can be extracted, thereby improving the training efficiency and prediction performance of the model. The trained CTR prediction model can be used to predict user click behavior in real time, providing strong support for personalized recommendations and improving user experience and satisfaction.
[0058] In some embodiments of this application, the steps of calculating differentiable precision and recall based on the differences include:
[0059] S510: Calculate the difference between the predicted value and the threshold, and normalize the absolute value of the difference. Then adjust the range of the difference after normalization to obtain the first variable score1.
[0060] Specifically, the difference between the predicted value of the CTR prediction model and a preset threshold is calculated. The absolute value of the difference is taken to ensure it is positive for subsequent processing. The difference is then normalized, scaling it to a suitable range (e.g., between 0 and 1) to eliminate the influence of different feature units. Adjusting the range of the normalized difference may involve further scaling or translation operations to suit the needs of subsequent calculations. The resulting first variable, score1, reflects the relative difference between the predicted value and the threshold, forming the basis for subsequent precision and recall calculations. Simultaneously, normalization ensures that all features are compared on the same scale, improving the model's stability and robustness.
[0061] S520: Calculate the product of the first variable score1 and the true label, retain the predicted samples whose true label is positive, and obtain the second variable score2.
[0062] Multiply the first variable, `score1`, by the true label (0 or 1). Retain the predicted samples whose true label is positive (i.e., 1), as these samples are crucial for subsequent precision and recall calculations. The resulting second variable, `score2`, contains only the scores of the predicted samples whose true label is positive. This step filters out samples that contribute to precision and recall calculations, reducing the complexity of subsequent calculations.
[0063] S530: Sum the second variable score2 to get the number of samples score3 where all predicted samples are positive and the true label is positive.
[0064] The summation of all values in the second variable, score2, represents the number of samples that were predicted to be positive and were also actually positive (i.e., True Positives, TP). The resulting number of samples with positive true labels, score3, is one of the foundations for calculating precision. The summation operation simplifies the calculation process and directly yields the required statistics.
[0065] S540: Sum the first variable score1 to get the number of all predicted positive samples score4; the number of predicted positive samples score4 is another basis for calculating precision and recall. Through this step, we can get the total number of predicted positive samples, which can be used to calculate precision in the subsequent calculation.
[0066] S550: Sum the results of all samples with positive true labels, score5.
[0067] S560: Differentiable precision and recall are calculated based on the number of samples with true positive labels (score3), the number of predicted positive samples (score4), and the number of true positive samples (score5).
[0068] Conventional precision and recall are typically calculated based on discrete values (i.e., classification results of 0 or 1). However, in this embodiment, they are calculated using continuous values, thus achieving differentiable precision and recall. This allows precision and recall to be used as part of the loss function for optimization operations such as gradient descent. By integrating differentiable precision and recall into the loss function, the model can directly optimize these two metrics during training, thereby improving optimization efficiency.
[0069] In some embodiments of this application, the formulas for calculating the differentiable precision and recall based on the number of samples with positive true labels (score3), the number of predicted positive samples (score4), and the number of samples with positive true labels (score5) are as follows:
[0070] Precision = score3 / (score4 + ε); where ε is the preset minimum value and Precision is the accuracy.
[0071] Specifically, this represents the proportion of samples that the model predicts to be positive, but which are actually positive. The higher this proportion, the more accurate the model's prediction.
[0072] Recall = score3 / (score5 + ε); where ε is the preset minimum value and Recall is the recall rate.
[0073] The percentage of samples predicted as positive by the model out of all samples that were actually positive. The higher this percentage, the more real positive samples the model covers.
[0074] Specifically, ε is a preset, extremely small value used to prevent division by zero errors caused by a denominator of zero. This improves the robustness of the formula. Furthermore, the value of ε is typically very small, so its impact on the calculation results of precision and recall is negligible.
[0075] In this application, precision and recall are two metrics that directly reflect model performance. Higher precision indicates more accurate predictions; higher recall indicates that the model covers more real positive samples. Once precision and recall are calculated, they can be used as one of the goals for model optimization. By adjusting model parameters or feature selection, precision and recall can be improved, thereby enhancing model performance.
[0076] In some embodiments of this application, the step of adjusting the range of differences after normalization includes: adding 1 to the differences after normalization and multiplying by 0.5 to obtain the first variable score1.
[0077] Specifically, adding 1 to the difference ensures that all difference values are positive. Normalized difference values may contain negative or zero values; adding 1 converts them all to positive numbers, facilitating subsequent processing. Simultaneously, it adjusts the range of the difference values. The addition operation essentially performs a translation transformation on the difference values, changing their range.
[0078] Multiplying by 0.5 effectively scales the difference value, reducing its range by half. This facilitates subsequent calculations. By adjusting the range of the difference value, it becomes more suitable for later calculations and comparisons.
[0079] In some embodiments of this application, the optimization algorithm minimization includes: gradient descent, stochastic gradient descent, and dynamic learning rate adjustment algorithm.
[0080] Gradient descent is a commonly used numerical optimization algorithm for finding the minimum or local minimum of a function. It iteratively adjusts parameters, gradually decreasing the objective function value along the opposite direction of the function's gradient to find the optimal solution. Stochastic gradient descent (SGD) is a variant of gradient descent and is widely used in the optimization of machine learning models. A key characteristic of SGD is that it doesn't use the entire dataset to calculate the gradient in each iteration; instead, it randomly selects a sample (or a mini-batch) to calculate the gradient and update the model parameters. Dynamic learning rate adjustment is a strategy that adjusts the learning rate based on the training process to improve model performance and training efficiency. The learning rate is a key parameter in optimization algorithms, controlling the step size for updating model parameters. Dynamically adjusting the learning rate can optimize the training process by adjusting the learning rate according to different training stages and model performance.
[0081] Gradient descent, stochastic gradient descent, and dynamic learning rate adjustment algorithms are all commonly used optimization algorithms, each with its own advantages and applicability in different application scenarios. In practical applications, appropriate optimization algorithms can be selected based on the specific problem and the characteristics of the dataset to improve model performance and training efficiency. This application does not impose specific restrictions on the optimization algorithms actually used in its embodiments.
[0082] In some embodiments of this application, the step of integrating differentiable precision and recall into the loss function of the CTR prediction model further includes: calculating cross-entropy loss using a Keras backend function; and combining the cross-entropy loss, differentiable precision, and recall according to given weight coefficients to form a loss function.
[0083] Cross-entropy loss is a common method for measuring the difference between two probability distributions. In CTR prediction, it measures the difference between the model's predicted CTR and the actual click behavior. Minimizing cross-entropy loss can improve the model's prediction accuracy. Using backend functions provided by the Keras framework, the cross-entropy loss between the model's output probability distribution and the actual labels can be easily calculated.
[0084] Specifically, in this embodiment, the backend functions provided by the Keras framework are used to calculate the cross-entropy loss between the model's predicted CTR and the actual click behavior. The cross-entropy loss, differentiable precision, and recall are linearly combined according to preset weight coefficients to form the final loss function. This loss function considers both the model's prediction accuracy (reflected by the cross-entropy loss) and the model's classification performance (reflected by precision and recall).
[0085] This application also provides code (based on Keras and TensorFlow) for integrating differentiable precision and recall into the loss function of a CTR prediction model:
[0086]
[0087]
[0088] As described above, this application provides a CTR prediction optimization method based on differentiable precision and recall, including the following steps: constructing a CTR prediction model and inputting training data and training features into the CTR prediction model; calculating the difference between the predicted value and the threshold after the output layer of the CTR prediction model, and calculating the differentiable precision and recall based on the difference; integrating the differentiable precision and recall into the loss function of the CTR prediction model, and minimizing the loss function through an optimization algorithm to obtain the trained CTR prediction model, etc. This approach achieves high computational efficiency and differentiability, and can be directly integrated into gradient optimization algorithms. By eliminating the dependence on threshold, conditional judgment, and ranking operations, this application can handle large-scale imbalanced data, significantly improving the performance and training efficiency of the CTR prediction model. Furthermore, it has broad application prospects in the field of recommender systems, effectively enhancing the model's predictive ability and commercial value.
[0089] Other embodiments of this disclosure will be readily apparent to those skilled in the art upon consideration of the disclosure in the specification and examples. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
Claims
1. A CTR prediction optimization method based on differentiable precision and recall, characterized in that, Including the following steps: Collect user click behavior data and divide the behavior data into training set and test set; The training set is preprocessed to obtain training data, and the data features of the training set are encoded and standardized. Based on preset conditions, the features of the data after encoding and standardization are filtered, and high-level features of the data are extracted using feature engineering methods to obtain training features. Construct a CTR prediction model by inputting the training data and the training features into the CTR prediction model; After the output layer of the CTR prediction model, the difference between the predicted value and the threshold is calculated, and the absolute value of the difference is normalized. The range of the difference after normalization is adjusted to obtain the first variable score1. Calculate the product of the first variable score1 and the true label, retain the predicted samples whose true label is positive, and obtain the second variable score2; Sum the second variable score2 to obtain the number of samples score3 where all predicted samples are positive samples and the true label is a positive sample; Sum the first variable score1 to obtain the number of all predicted positive samples score4. Sum the values of the true labels to obtain the number of samples whose true labels are positive (score5). The differentiable precision and recall are calculated based on the number of samples with positive true labels (score3), the number of predicted positive samples (score4), and the number of samples with positive true labels (score5), using the following formulas: Precision=score3 / (score4+ε); Recall=score3 / (score5+ε); In the formula: ε is the preset minimum value, Precision is the precision rate, and Recall is the recall rate; The differentiable precision and recall are integrated into the loss function of the CTR prediction model, and the loss function is minimized by an optimization algorithm to obtain the trained CTR prediction model. The test set is input into the trained CTR prediction model, and the AUC-PR metric is calculated. When the AUC-PR metric meets the preset standard metric, the CTR prediction model is completed and deployed.
2. The CTR prediction optimization method based on differentiable precision and recall according to claim 1, characterized in that, The behavioral data includes user feature data, item feature data, and context feature data. The preprocessing operations include data cleaning, data deduplication, and handling of missing data values.
3. The CTR prediction optimization method based on differentiable precision and recall according to claim 1, characterized in that, The step of adjusting the range of the difference after normalization includes: Add 1 to the difference after normalization and multiply by 0.5 to obtain the first variable, score1.
4. The CTR prediction optimization method based on differentiable precision and recall according to claim 1, characterized in that, The optimization algorithms for minimization include: gradient descent, stochastic gradient descent, and dynamic learning rate adjustment.
5. The CTR prediction optimization method based on differentiable precision and recall according to claim 1, characterized in that, The step of integrating the differentiable precision and recall into the loss function of the CTR prediction model further includes: Calculate the cross-entropy loss using Keras backend functions; The loss function is formed by combining the cross-entropy loss, the differentiable precision, and the recall according to given weighting coefficients.
Citation Information
Patent Citations
Platform-related advertisement click rate prediction method based on deep learning
CN113689234A
Image classification method and device based on differential network structure search
CN115115873A