Skip to content

Instantly share code, notes, and snippets.

@MrFlick
MrFlick / makeglm.R
Last active October 7, 2023 11:28
makeglm.R: Creates a "fake" glm object with specific coefficients that you can use for predicting without fitting a model first
makeglm <- function(formula, ..., family, data=NULL) {
dots <- list(...)
out<-list()
tt <- terms(formula, data=data)
if(!is.null(data)) {
mf <- model.frame(tt, data)
vn <- sapply(attr(tt, "variables")[-1], deparse)
if((yvar <- attr(tt, "response"))>0)
vn <- vn[-yvar]
@mblondel
mblondel / letor_metrics.py
Last active September 19, 2024 06:13
Learning to rank metrics.
# (C) Mathieu Blondel, November 2013
# License: BSD 3 clause
import numpy as np
def ranking_precision_score(y_true, y_score, k=10):
"""Precision at rank k
Parameters