Upgrade to Pro — share decks privately, control downloads, hide ads and more …

データサイエンティストに同じクエリは二度も通じぬ

 データサイエンティストに同じクエリは二度も通じぬ

Presentation in Japan.R 2019

Takahiro Yoshinaga

December 07, 2019
Tweet

More Decks by Takahiro Yoshinaga

Other Decks in Technology

Transcript

  1. @t_yoshinaga0106 Takahiro Yoshinaga aE l l , l hi RE

    S R E s l e t a t o l l / BL cDn IPN
  2. #  , , cost, impression Web service df #>

    gender age cost impression click conversion #> 1 M 10 51 101 0 0 #> 2 F 20 52 102 3 1 #> 3 M 30 53 103 6 2 #> 4 F 40 54 104 9 3 #> 5 M 50 55 105 12 4 #> 6 F 60 56 106 15 5 #> 7 M 70 57 107 18 6 #> 8 F 80 58 108 21 7 #> 9 M 90 59 109 24 8 #> 10 F 100 60 110 27 9 Sample   # !"        !  
  3. :

  4. dplyr # Summarize by gender df_summarized_gender <- df %>% group_by(gender)

    %>% summarize( cost = sum(cost), impression = sum(impression), click = sum(click), conversion = sum(conversion), ctr = sum(click) / sum(impression), cvr = sum(conversion) / sum(click), ctvr = sum(conversion) / sum(impression), cpa = sum(cost) / sum(conversion), cpc = sum(cost) / sum(click), ecpm = sum(cost) / sum(impression) * 1000 ) df_summarized_gender #> # A tibble: 2 x 11 #> gender cost impression click conversion ctr cvr ctvr cpa cpc ecpm #> <fct> <int> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 F 280 530 75 25 0.142 0.333 0.0472 11.2 3.73 528. #> 2 M 275 525 60 20 0.114 0.333 0.0381 13.8 4.58 524. # Summarize by age df_summarized_age <- df %>% group_by(age) %>% summarize( cost = sum(cost), impression = sum(impression), click = sum(click), conversion = sum(conversion), ctr = sum(click) / sum(impression), cvr = sum(conversion) / sum(click), ctvr = sum(conversion) / sum(impression), cpa = sum(cost) / sum(conversion), cpc = sum(cost) / sum(click), ecpm = sum(cost) / sum(impression) * 1000 ) df_summarized_age #> # A tibble: 10 x 11 #> age cost impression click conversion ctr cvr ctvr cpa cpc ecpm #> <dbl> <int> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 10 51 101 0 0 0 NaN 0 Inf Inf 505. #> 2 20 52 102 3 1 0.0294 0.333 0.00980 52 17.3 510. #> 3 30 53 103 6 2 0.0583 0.333 0.0194 26.5 8.83 515. #> 4 40 54 104 9 3 0.0865 0.333 0.0288 18 6 519. #> 5 50 55 105 12 4 0.114 0.333 0.0381 13.8 4.58 524. #> 6 60 56 106 15 5 0.142 0.333 0.0472 11.2 3.73 528. #> 7 70 57 107 18 6 0.168 0.333 0.0561 9.5 3.17 533. #> 8 80 58 108 21 7 0.194 0.333 0.0648 8.29 2.76 537. #> 9 90 59 109 24 8 0.220 0.333 0.0734 7.38 2.46 541. #> 10 100 60 110 27 9 0.245 0.333 0.0818 6.67 2.22 545.
  5. dplyr # Summarize by gender df_summarized_gender <- df %>% group_by(gender)

    %>% summarize( cost = sum(cost), impression = sum(impression), click = sum(click), conversion = sum(conversion), ctr = sum(click) / sum(impression), cvr = sum(conversion) / sum(click), ctvr = sum(conversion) / sum(impression), cpa = sum(cost) / sum(conversion), cpc = sum(cost) / sum(click), ecpm = sum(cost) / sum(impression) * 1000 ) df_summarized_gender #> # A tibble: 2 x 11 #> gender cost impression click conversion ctr cvr ctvr cpa cpc ecpm #> <fct> <int> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 F 280 530 75 25 0.142 0.333 0.0472 11.2 3.73 528. #> 2 M 275 525 60 20 0.114 0.333 0.0381 13.8 4.58 524. # Summarize by age df_summarized_age <- df %>% group_by(age) %>% summarize( cost = sum(cost), impression = sum(impression), click = sum(click), conversion = sum(conversion), ctr = sum(click) / sum(impression), cvr = sum(conversion) / sum(click), ctvr = sum(conversion) / sum(impression), cpa = sum(cost) / sum(conversion), cpc = sum(cost) / sum(click), ecpm = sum(cost) / sum(impression) * 1000 ) df_summarized_age #> # A tibble: 10 x 11 #> age cost impression click conversion ctr cvr ctvr cpa cpc ecpm #> <dbl> <int> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 10 51 101 0 0 0 NaN 0 Inf Inf 505. #> 2 20 52 102 3 1 0.0294 0.333 0.00980 52 17.3 510. #> 3 30 53 103 6 2 0.0583 0.333 0.0194 26.5 8.83 515. #> 4 40 54 104 9 3 0.0865 0.333 0.0288 18 6 519. #> 5 50 55 105 12 4 0.114 0.333 0.0381 13.8 4.58 524. #> 6 60 56 106 15 5 0.142 0.333 0.0472 11.2 3.73 528. #> 7 70 57 107 18 6 0.168 0.333 0.0561 9.5 3.17 533. #> 8 80 58 108 21 7 0.194 0.333 0.0648 8.29 2.76 537. #> 9 90 59 109 24 8 0.220 0.333 0.0734 7.38 2.46 541. #> 10 100 60 110 27 9 0.245 0.333 0.0818 6.67 2.22 545. !? !?
  6. mmetrics GI EI - C l ü . : .

    : A - . . / l - ü - .: C - . l : ü LD ND R l - : ü .: .: - : : : - C .
  7. # metrics <- mmetrics::define( cost = sum(cost), impression = sum(impression),

    click = sum(click), conversion = sum(conversion), ctr = sum(click) / sum(impression), cvr = sum(conversion) / sum(click), ctvr = sum(conversion) / sum(impression), cpa = sum(cost) / sum(conversion), cpc = sum(cost) / sum(click), ecpm = sum(cost) / sum(impression) * 1000) # axis df_summarized_gender <- mmetrics::add(df, gender, metrics = metrics) df_summarized_age <- mmetrics::add(df, age, metrics = metrics) Use Case of mmetrics
  8. Result #  df_summarized_gender #> # A tibble: 2 x

    11 #> gender cost impression click conversion ctr cvr ctvr cpa cpc ecpm #> <fct> <int> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 F 280 530 75 25 0.142 0.333 0.0472 11.2 3.73 528. #> 2 M 275 525 60 20 0.114 0.333 0.0381 13.8 4.58 524. #  df_summarized_age #> # A tibble: 10 x 11 #> age cost impression click conversion ctr cvr ctvr cpa cpc ecpm #> <dbl> <int> <int> <dbl> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 10 51 101 0 0 0 NaN 0 Inf Inf 505. #> 2 20 52 102 3 1 0.0294 0.333 0.00980 52 17.3 510. #> 3 30 53 103 6 2 0.0583 0.333 0.0194 26.5 8.83 515. #> 4 40 54 104 9 3 0.0865 0.333 0.0288 18 6 519. #> 5 50 55 105 12 4 0.114 0.333 0.0381 13.8 4.58 524. #> 6 60 56 106 15 5 0.142 0.333 0.0472 11.2 3.73 528. #> 7 70 57 107 18 6 0.168 0.333 0.0561 9.5 3.17 533. #> 8 80 58 108 21 7 0.194 0.333 0.0648 8.29 2.76 537. #> 9 90 59 109 24 8 0.220 0.333 0.0734 7.38 2.46 541. #> 10 100 60 110 27 9 0.245 0.333 0.0818 6.67 2.22 545.      
  9.