text: -- This SQL code was generated by sklearn2sql (development version).
  -- Copyright 2018
  
  -- Model : CaretClassifier_xgbTree
  -- Dataset : BreastCancer
  -- Database : mssql
  
  
  -- This SQL code can contain one or more statements, to be executed in the order they appear in this file.
  
  
  
  -- Model deployment code
  
  WITH [DT_node_lookup] AS 
  (SELECT [ADS].[KEY] AS [KEY], CASE WHEN ([ADS].[Feature_20] < 16.8150005) THEN CASE WHEN ([ADS].[Feature_7] < 0.0439950004) THEN 3 ELSE 4 END ELSE CASE WHEN ([ADS].[Feature_7] < 0.0777349994) THEN 5 ELSE 6 END END AS node_id_2 
  FROM [BreastCancer] AS [ADS]), 
  [DT_node_data] AS 
  (SELECT [Values].nid AS nid, [Values].[Score] AS [Score] 
  FROM (SELECT 3 AS nid, -0.768159211 AS [Score] UNION ALL SELECT 4 AS nid, -0.327272743 AS [Score] UNION ALL SELECT 5 AS nid, 0.436363667 AS [Score] UNION ALL SELECT 6 AS nid, 0.761904776 AS [Score]) AS [Values]), 
  [DT_Output] AS 
  (SELECT [DT_node_lookup].[KEY] AS [KEY], [DT_node_lookup].node_id_2 AS node_id_2, [DT_node_data].nid AS nid, [DT_node_data].[Score] AS [Score] 
  FROM [DT_node_lookup] LEFT OUTER JOIN [DT_node_data] ON [DT_node_lookup].node_id_2 = [DT_node_data].nid), 
  [XGB_Model_0_0] AS 
  (SELECT [DT_Output].[KEY] AS [KEY], [DT_Output].[Score] AS [Score_0] 
  FROM [DT_Output]), 
  [DT_node_lookup_1] AS 
  (SELECT [ADS].[KEY] AS [KEY], CASE WHEN ([ADS].[Feature_27] < 0.145449996) THEN CASE WHEN ([ADS].[Feature_13] < 29.2250004) THEN 3 ELSE 4 END ELSE 2 END AS node_id_2 
  FROM [BreastCancer] AS [ADS]), 
  [DT_node_data_1] AS 
  (SELECT [Values].nid AS nid, [Values].[Score] AS [Score] 
  FROM (SELECT 2 AS nid, 0.592611194 AS [Score] UNION ALL SELECT 3 AS nid, -0.590538204 AS [Score] UNION ALL SELECT 4 AS nid, -0.252212733 AS [Score]) AS [Values]), 
  [DT_Output_1] AS 
  (SELECT [DT_node_lookup_1].[KEY] AS [KEY], [DT_node_lookup_1].node_id_2 AS node_id_2, [DT_node_data_1].nid AS nid, [DT_node_data_1].[Score] AS [Score] 
  FROM [DT_node_lookup_1] LEFT OUTER JOIN [DT_node_data_1] ON [DT_node_lookup_1].node_id_2 = [DT_node_data_1].nid), 
  [XGB_Model_0_1] AS 
  (SELECT [DT_Output_1].[KEY] AS [KEY], [DT_Output_1].[Score] AS [Score_0] 
  FROM [DT_Output_1]), 
  [XGB_0] AS 
  (SELECT [XGB_esu_0].[KEY] AS [KEY], [XGB_esu_0].[Score_0] AS [Score_0] 
  FROM (SELECT [XGB_Model_0_0].[KEY] AS [KEY], CAST([XGB_Model_0_0].[Score_0] AS FLOAT(53)) AS [Score_0] 
  FROM [XGB_Model_0_0] UNION ALL SELECT [XGB_Model_0_1].[KEY] AS [KEY], CAST([XGB_Model_0_1].[Score_0] AS FLOAT(53)) AS [Score_0] 
  FROM [XGB_Model_0_1]) AS [XGB_esu_0]), 
  [XGB] AS 
  (SELECT [XGBbig_esu].[KEY] AS [KEY], [XGBbig_esu].[Score_0] AS [Score_0] 
  FROM (SELECT [XGB_0].[KEY] AS [KEY], CAST([XGB_0].[Score_0] AS FLOAT(53)) AS [Score_0] 
  FROM [XGB_0]) AS [XGBbig_esu]), 
  [XGB_sum] AS 
  (SELECT [T].[KEY] AS [KEY], CAST([T].[Score_0] AS FLOAT(53)) AS [Score_0] 
  FROM (SELECT [XGB].[KEY] AS [KEY], sum([XGB].[Score_0]) AS [Score_0] 
  FROM [XGB] GROUP BY [XGB].[KEY]) AS [T]), 
  orig_cte AS 
  (SELECT [XGB_sum].[KEY] AS [KEY], [XGB_sum].[Score_0] AS [Score_0], CAST(NULL AS FLOAT(53)) AS [Score_1], 1.0 - 1.0 / (1.0 + exp(CASE WHEN (100.0 <= CASE WHEN (-100.0 <= -[XGB_sum].[Score_0]) THEN -[XGB_sum].[Score_0] ELSE -100.0 END) THEN 100.0 ELSE CASE WHEN (-100.0 <= -[XGB_sum].[Score_0]) THEN -[XGB_sum].[Score_0] ELSE -100.0 END END)) AS [Proba_0], 1.0 / (1.0 + exp(CASE WHEN (100.0 <= CASE WHEN (-100.0 <= -[XGB_sum].[Score_0]) THEN -[XGB_sum].[Score_0] ELSE -100.0 END) THEN 100.0 ELSE CASE WHEN (-100.0 <= -[XGB_sum].[Score_0]) THEN -[XGB_sum].[Score_0] ELSE -100.0 END END)) AS [Proba_1], CAST(NULL AS FLOAT(53)) AS [LogProba_0], CAST(NULL AS FLOAT(53)) AS [LogProba_1], CAST(NULL AS BIGINT) AS [Decision], CAST(NULL AS FLOAT(53)) AS [DecisionProba] 
  FROM [XGB_sum]), 
  score_class_union AS 
  (SELECT scu.[KEY_u] AS [KEY_u], scu.class AS class, scu.[LogProba] AS [LogProba], scu.[Proba] AS [Proba], scu.[Score] AS [Score] 
  FROM (SELECT orig_cte.[KEY] AS [KEY_u], 0 AS class, orig_cte.[LogProba_0] AS [LogProba], orig_cte.[Proba_0] AS [Proba], orig_cte.[Score_0] AS [Score] 
  FROM orig_cte UNION ALL SELECT orig_cte.[KEY] AS [KEY_u], 1 AS class, orig_cte.[LogProba_1] AS [LogProba], orig_cte.[Proba_1] AS [Proba], orig_cte.[Score_1] AS [Score] 
  FROM orig_cte) AS scu), 
  score_max AS 
  (SELECT orig_cte.[KEY] AS [KEY], orig_cte.[Score_0] AS [Score_0], orig_cte.[Score_1] AS [Score_1], orig_cte.[Proba_0] AS [Proba_0], orig_cte.[Proba_1] AS [Proba_1], orig_cte.[LogProba_0] AS [LogProba_0], orig_cte.[LogProba_1] AS [LogProba_1], orig_cte.[Decision] AS [Decision], orig_cte.[DecisionProba] AS [DecisionProba], max_select.[KEY_m] AS [KEY_m], max_select.[max_Proba] AS [max_Proba] 
  FROM orig_cte LEFT OUTER JOIN (SELECT score_class_union.[KEY_u] AS [KEY_m], max(score_class_union.[Proba]) AS [max_Proba] 
  FROM score_class_union GROUP BY score_class_union.[KEY_u]) AS max_select ON orig_cte.[KEY] = max_select.[KEY_m]), 
  union_with_max AS 
  (SELECT score_class_union.[KEY_u] AS [KEY_u], score_class_union.class AS class, score_class_union.[LogProba] AS [LogProba], score_class_union.[Proba] AS [Proba], score_class_union.[Score] AS [Score], score_max.[KEY] AS [KEY], score_max.[Score_0] AS [Score_0], score_max.[Score_1] AS [Score_1], score_max.[Proba_0] AS [Proba_0], score_max.[Proba_1] AS [Proba_1], score_max.[LogProba_0] AS [LogProba_0], score_max.[LogProba_1] AS [LogProba_1], score_max.[Decision] AS [Decision], score_max.[DecisionProba] AS [DecisionProba], score_max.[KEY_m] AS [KEY_m], score_max.[max_Proba] AS [max_Proba] 
  FROM score_class_union LEFT OUTER JOIN score_max ON score_class_union.[KEY_u] = score_max.[KEY]), 
  arg_max_cte AS 
  (SELECT score_max.[KEY] AS [KEY], score_max.[Score_0] AS [Score_0], score_max.[Score_1] AS [Score_1], score_max.[Proba_0] AS [Proba_0], score_max.[Proba_1] AS [Proba_1], score_max.[LogProba_0] AS [LogProba_0], score_max.[LogProba_1] AS [LogProba_1], score_max.[Decision] AS [Decision], score_max.[DecisionProba] AS [DecisionProba], score_max.[KEY_m] AS [KEY_m], score_max.[max_Proba] AS [max_Proba], [arg_max_t_Proba].[KEY_Proba] AS [KEY_Proba], [arg_max_t_Proba].[arg_max_Proba] AS [arg_max_Proba] 
  FROM score_max LEFT OUTER JOIN (SELECT union_with_max.[KEY] AS [KEY_Proba], min(union_with_max.class) AS [arg_max_Proba] 
  FROM union_with_max 
  WHERE union_with_max.[max_Proba] <= union_with_max.[Proba] GROUP BY union_with_max.[KEY]) AS [arg_max_t_Proba] ON score_max.[KEY] = [arg_max_t_Proba].[KEY_Proba])
   SELECT arg_max_cte.[KEY] AS [KEY], CAST(NULL AS FLOAT(53)) AS [Score_0], CAST(NULL AS FLOAT(53)) AS [Score_1], arg_max_cte.[Proba_0] AS [Proba_0], arg_max_cte.[Proba_1] AS [Proba_1], CASE WHEN (arg_max_cte.[Proba_0] IS NULL OR arg_max_cte.[Proba_0] > 0.0) THEN log(arg_max_cte.[Proba_0]) ELSE -1.79769313486231e+308 END AS [LogProba_0], CASE WHEN (arg_max_cte.[Proba_1] IS NULL OR arg_max_cte.[Proba_1] > 0.0) THEN log(arg_max_cte.[Proba_1]) ELSE -1.79769313486231e+308 END AS [LogProba_1], arg_max_cte.[arg_max_Proba] AS [Decision], arg_max_cte.[max_Proba] AS [DecisionProba] 
  FROM arg_max_cte