GeezerVison is showing github.com — work on example · WinVector/Examples@c7033c0
File treeExpand file treeCollapse file tree Open diff view settings traj_graph_2_files/figure-gfm
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: rebalance/traj_graph_2.Rmd +2-12Lines changed: 2 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -15,6 +15,7 @@ d_ex <- wrapr::build_frame( | 15 | 15 | "x1" , "x2", "y" | | 16 | 16 | 0 , 0 , 0 | | 17 | 17 | 1 , 0 , 1 | | | 18 | + -2 , 0 , 0 | | 18 | 19 | 0 , 2 , 1 | | 19 | 20 | 1 , 2 , 1 | | 20 | 21 | 1 , 1 , 0 ) | @@ -30,7 +31,7 @@ is_non_decreasing <- function(x) {all(x == cummax(x))} | 30 | 31 | ```{r} | 31 | 32 | frames <- list() | 32 | 33 | suppressWarnings( | 33 | | - for(lambda in seq(0.01, 0.99, length.out = 100)) { | | 34 | + for(lambda in seq(0, 10.0, length.out = 1000)) { | 34 | 35 | model <- glm(y ~ x1 + x2, family=binomial(), data=d_ex, weights = 1 + lambda * d_ex$y) | 35 | 36 | preds <- predict(model, type='response', newdata=d_ex) | 36 | 37 | row_frame <- as.data.frame(t(as.matrix(preds))) | @@ -39,14 +40,11 @@ suppressWarnings( | 39 | 40 | } | 40 | 41 | ) | 41 | 42 | frames <- do.call(rbind, frames) | 42 | | -for(col in colnames(frames)) { stopifnot(is_non_decreasing(frames[[col]])) } | 43 | 43 | plot_dat <- data.frame(data.table::melt( | 44 | 44 | data.table(frames), | 45 | 45 | variable.name = 'row', | 46 | 46 | value.name = 'score', | 47 | 47 | id.vars='lambda')) | 48 | | -plot_dat['logit(lambda)'] = logit(plot_dat['lambda']) | 49 | | -plot_dat['logit(score)'] = logit(plot_dat['score']) | 50 | 48 | ``` | 51 | 49 |
| 52 | 50 |
| @@ -59,11 +57,3 @@ ggplot( | 59 | 57 | geom_line() | 60 | 58 | ``` | 61 | 59 |
| 62 | | - | 63 | | -```{r} | 64 | | -ggplot( | 65 | | - data=plot_dat, | 66 | | - mapping=aes(x=`logit(lambda)`, y=`logit(score)`, color=row) | 67 | | -) + | 68 | | - geom_line() | 69 | | -``` |
Collapse file Copy file name to clipboardExpand all lines: rebalance/traj_graph_2.md +3-14Lines changed: 3 additions & 14 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -19,6 +19,7 @@ d_ex <- wrapr::build_frame( | 19 | 19 | "x1" , "x2", "y" | | 20 | 20 | 0 , 0 , 0 | | 21 | 21 | 1 , 0 , 1 | | | 22 | + -2 , 0 , 0 | | 22 | 23 | 0 , 2 , 1 | | 23 | 24 | 1 , 2 , 1 | | 24 | 25 | 1 , 1 , 0 ) | @@ -30,6 +31,7 @@ knitr::kable(d_ex) | 30 | 31 | |----:|----:|----:| | 31 | 32 | | 0 | 0 | 0 | | 32 | 33 | | 1 | 0 | 1 | | | 34 | +| -2 | 0 | 0 | | 33 | 35 | | 0 | 2 | 1 | | 34 | 36 | | 1 | 2 | 1 | | 35 | 37 | | 1 | 1 | 0 | | @@ -42,7 +44,7 @@ is_non_decreasing <- function(x) {all(x == cummax(x))} | 42 | 44 | ``` r | 43 | 45 | frames <- list() | 44 | 46 | suppressWarnings( | 45 | | - for(lambda in seq(0.01, 0.99, length.out = 100)) { | | 47 | + for(lambda in seq(0, 10.0, length.out = 1000)) { | 46 | 48 | model <- glm(y ~ x1 + x2, family=binomial(), data=d_ex, weights = 1 + lambda * d_ex$y) | 47 | 49 | preds <- predict(model, type='response', newdata=d_ex) | 48 | 50 | row_frame <- as.data.frame(t(as.matrix(preds))) | @@ -51,14 +53,11 @@ suppressWarnings( | 51 | 53 | } | 52 | 54 | ) | 53 | 55 | frames <- do.call(rbind, frames) | 54 | | -for(col in colnames(frames)) { stopifnot(is_non_decreasing(frames[[col]])) } | 55 | 56 | plot_dat <- data.frame(data.table::melt( | 56 | 57 | data.table(frames), | 57 | 58 | variable.name = 'row', | 58 | 59 | value.name = 'score', | 59 | 60 | id.vars='lambda')) | 60 | | -plot_dat['logit(lambda)'] = logit(plot_dat['lambda']) | 61 | | -plot_dat['logit(score)'] = logit(plot_dat['score']) | 62 | 61 | ``` | 63 | 62 |
| 64 | 63 | ``` r | @@ -70,13 +69,3 @@ ggplot( | 70 | 69 | ``` | 71 | 70 |
| 72 | 71 | <!-- --> | 73 | | - | 74 | | -``` r | 75 | | -ggplot( | 76 | | - data=plot_dat, | 77 | | - mapping=aes(x=`logit(lambda)`, y=`logit(score)`, color=row) | 78 | | -) + | 79 | | - geom_line() | 80 | | -``` | 81 | | - | 82 | | -<!-- --> |
Collapse file Copy file name to clipboard 6.47 KB
- Display the source diff
- Display the rich diff
Collapse file Copy file name to clipboard -3.91 KB
- Display the source diff
- Display the rich diff
|