crabbymetrics
  • Home
  • API
  • Binding Crash Course
  • Supervised Learning
    • OLS
    • Ridge
    • Fixed Effects OLS
    • ElasticNet
    • Synthetic Control
    • Logit
    • Multinomial Logit
    • Poisson
    • TwoSLS
    • GMM
    • FTRL
    • MEstimator Poisson
  • Semiparametrics
    • Balancing Weights
    • EPLM
    • Average Derivative
    • Double ML And AIPW
    • Richer Regression
  • Unsupervised Learning
    • PCA And Kernel Basis
  • Ablations
    • Variance Estimators
    • Semiparametric Estimator Comparisons
    • Bridging Finite And Superpopulation
  • Optimization
    • Optimizers
    • GMM With Optimizers
  • Ding: First Course
    • Overview And TOC
    • Ch 1 Correlation And Simpson
    • Ch 2 Potential Outcomes
    • Ch 3 CRE And Fisher RT
    • Ch 4 CRE And Neyman
    • Ch 9 Bridging Finite And Superpopulation
    • Ch 11 Propensity Score
    • Ch 12 Double Robust ATE
    • Ch 13 Double Robust ATT
    • Ch 21 Experimental IV
    • Ch 23 Econometric IV

FTRL Example

This page mirrors examples/ftrl_example.py.

1 Fit An FTRL Classifier

import numpy as np
from pprint import pprint

from crabbymetrics import FTRL

np.set_printoptions(precision=4, suppress=True)
rng = np.random.default_rng(6)
n = 1000
k = 5
beta = np.array([0.8, -1.2, 0.4, 0.0, 0.6])

x = rng.normal(size=(n, k))
logits = x @ beta
probs = 1.0 / (1.0 + np.exp(-logits))
y = rng.binomial(1, probs).astype(np.int32)

model = FTRL(alpha=0.1, beta=1.0, l1_ratio=1.0, l2_ratio=1.0)
model.fit(x, y)

print("true coef:", beta)
pprint(model.summary())
true coef: [ 0.8 -1.2  0.4  0.   0.6]
{'coef': array([ 0.0986, -0.0992,  0.0974,  0.0829,  0.0978]),
 'coef_se': array([0.0633, 0.0638, 0.0633, 0.0645, 0.0639])}