pystacked: Stacking generalization and machine learning in Stata

Achim Ahrens, Christian B. Hansen, Mark Edwin Schaffer

Research output: Contribution to journalArticlepeer-review

1 Citation (Scopus)
23 Downloads (Pure)


The pystacked command implements stacked generalization (Wolpert, 1992, Neural Networks 5: 241–259) for regression and binary classification via Python’s scikit-learn. Stacking combines multiple supervised machine learners—the “base” or “level-0” learners—into one learner. The currently supported base learners include regularized regression, random forest, gradient boosted trees, support vector machines, and feed-forward neural nets (multilayer perceptron). pystacked can also be used as a “regular” machine learning program to fit one base learner and thus provides an easy-to-use application programming interface for scikit-learn‘s machine learning algorithms.
Original languageEnglish
Pages (from-to)909-931
Number of pages23
JournalThe Stata Journal
Issue number4
Early online date21 Dec 2023
Publication statusPublished - Dec 2023


  • Python
  • machine learning
  • model averaging
  • pystacked
  • sci-kit learn
  • st0731
  • stacked generalization

ASJC Scopus subject areas

  • Mathematics (miscellaneous)


Dive into the research topics of 'pystacked: Stacking generalization and machine learning in Stata'. Together they form a unique fingerprint.

Cite this