This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- BigQuery Function to check if 8, 12, 13, 14 digit GTIN codes are valid. | |
| -- https://www.gs1.org/services/how-calculate-check-digit-manually | |
| CREATE OR REPLACE FUNCTION `project-name.dataset-name.is_gtin_valid`(gtin STRING) AS ( | |
| CASE WHEN LENGTH(gtin) = 8 AND | |
| MOD(10 - MOD( | |
| CAST(SUBSTR(gtin, 1, 1) AS INT64) * 3 + | |
| CAST(SUBSTR(gtin, 2, 1) AS INT64) * 1 + | |
| CAST(SUBSTR(gtin, 3, 1) AS INT64) * 3 + | |
| CAST(SUBSTR(gtin, 4, 1) AS INT64) * 1 + | |
| CAST(SUBSTR(gtin, 5, 1) AS INT64) * 3 + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def focal_loss_lgb(y_true, y_pred, alpha=0.25, gamma=1.0): | |
| # Alpha or (1-alpha) | |
| a = y_true * alpha + (1-y_true) * (1-alpha) | |
| # Sign | |
| s = y_true * 2 - 1 | |
| # Gamma | |
| g = gamma | |
| # Prob. | |
| p = 1/(1+np.exp(-y_pred)) |