Skip to content

Instantly share code, notes, and snippets.

View lorenzwalthert's full-sized avatar

Lorenz Walthert lorenzwalthert

View GitHub Profile
# adapted from https://towardsdatascience.com/simple-trick-to-train-an-ordinal-regression-with-any-classifier-6911183d2a3c
class OrdinalClassifier:
def __init__(self, clf):
self.clf = clf
self.clfs = {}
def fit(self, X, y):
self.classes_ = np.sort(np.unique(y))
if self.classes_.shape[0] > 2:
for level in self.classes_[: (self.classes_.shape[0] - 1)]:
library(styler)
guide <- tidyverse_style(scope = "line_breaks", indent_by = 8)
guide_with_indention_rules_only <- purrr::modify_at(
guide, 3, ~.x[grepl("indent", names(.x))]
)
styler::style_text(
"call(
x = 2
)
a =3
``` r
string_formula <- paste0(names(mtcars)[1], " ~", paste0(names(mtcars)[-1], collapse = "+"))
lm(as.formula(string_formula), data = mtcars)
#>
#> Call:
#> lm(formula = as.formula(string_formula), data = mtcars)
#>
#> Coefficients:
#> (Intercept) cyl disp hp drat
@lorenzwalthert
lorenzwalthert / lm_with_flexible_variables
Last active July 19, 2017 14:30
access the formula interface
``` r
# with a formula
fit_something <- function(data, formula, ...) {
lm(as.formula(formula), data = data, ...)
}
fit_something(mtcars, "cyl ~mpg")
#>
#> Call:
#> lm(formula = as.formula(formula), data = data)
# ____________________________________________________________________________
# function test ####
test <- function(x) {
## ............................................................................
## A: pre-processing ####
### .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
### a: assertive tests ####
# x
if(missing(x) || is.null(x)){
x <- character()
devtools::install_github("lorenzwalthert/strcode")
@lorenzwalthert
lorenzwalthert / summary
Last active February 18, 2017 20:09
summary created with sum_str
Summarized structure of ~/Documents/short-term back-up/sum_str.R
line level section
1 # ________________________________________________________
2 # A title
8 ## ........................................................
9 ## A subtitle
15 ### . . . . . . . . . . . . . . . . . . . . . . . . . . . ..
16 ### Another one
#< 56f5139874167f4f5635b42c37fd6594 >#
this_is_a_super_important_but_hard_to_describe_line_so_let_me_anchor_it
@lorenzwalthert
lorenzwalthert / anchored_section
Created February 18, 2017 19:36
An anchored section
## ........ #< bdd0351ff9987e58fec1e1d3dbcdd8d1 ># ........
## An anchored section ####
@lorenzwalthert
lorenzwalthert / abstract
Last active February 18, 2017 19:35
a concept of code structuring
# ________________________________________________________
# A title ####
# this is a level 1 section. l1 sections are are high-level
# blocks.
# [your code here]
## ........................................................
## A sub title ####
# this is a level 2 section. These sections are medium-level