{"id":13655960,"url":"https://github.com/fukatani/stacked_generalization","last_synced_at":"2026-04-02T18:45:27.605Z","repository":{"id":46529229,"uuid":"58473332","full_name":"fukatani/stacked_generalization","owner":"fukatani","description":"Library for machine learning stacking generalization.","archived":false,"fork":false,"pushed_at":"2019-05-02T05:09:54.000Z","size":117,"stargazers_count":117,"open_issues_count":3,"forks_count":25,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-09-29T17:22:43.738Z","etag":null,"topics":["machine-learning"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fukatani.png","metadata":{"files":{"readme":"Readme.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-10T15:35:12.000Z","updated_at":"2024-01-08T14:06:32.000Z","dependencies_parsed_at":"2022-07-19T22:34:02.214Z","dependency_job_id":null,"html_url":"https://github.com/fukatani/stacked_generalization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fukatani/stacked_generalization","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fukatani%2Fstacked_generalization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fukatani%2Fstacked_generalization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fukatani%2Fstacked_generalization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fukatani%2Fstacked_generalization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fukatani","download_url":"https://codeload.github.com/fukatani/stacked_generalization/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fukatani%2Fstacked_generalization/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31313302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-02T12:59:32.332Z","status":"ssl_error","status_checked_at":"2026-04-02T12:54:48.875Z","response_time":89,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["machine-learning"],"created_at":"2024-08-02T04:00:43.405Z","updated_at":"2026-04-02T18:45:27.580Z","avatar_url":"https://github.com/fukatani.png","language":"Python","funding_links":[],"categories":["Machine Learning","Python","Uncategorized"],"sub_categories":["Ensemble Methods","General-Purpose Machine Learning","Uncategorized"],"readme":"|Build Status|\n\nstacked\\_generalization\n=======================\n\nImplemented machine learning ***stacking technic[1]*** as handy library\nin Python. Feature weighted linear stacking is also available. (See\nhttps://github.com/fukatani/stacked\\_generalization/tree/master/stacked\\_generalization/example)\n\nIncluding simple model cache system Joblibed claasifier and Joblibed\nRegressor.\n\nFeature\n-------\n\n1) Any scikit-learn model is availavle for Stage 0 and Stage 1 model.\n'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n\nAnd stacked model itself has the same interface as scikit-learn library.\n''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n\nYou can replace model such as *RandomForestClassifier* to *stacked\nmodel* easily in your scripts. And multi stage stacking is also easy.\n\nex.\n\n.. code:: python\n\n    from stacked_generalization.lib.stacking import StackedClassifier\n    from sklearn.ensemble import RandomForestClassifier, GradientBoostingClassifier\n    from sklearn.linear_model import LogisticRegression, RidgeClassifier\n    from sklearn import datasets, metrics\n    iris = datasets.load_iris()\n\n    # Stage 1 model\n    bclf = LogisticRegression(random_state=1)\n\n    # Stage 0 models\n    clfs = [RandomForestClassifier(n_estimators=40, criterion = 'gini', random_state=1),\n            GradientBoostingClassifier(n_estimators=25, random_state=1),\n            RidgeClassifier(random_state=1)]\n\n    # same interface as scikit-learn\n    sl = StackedClassifier(bclf, clfs)\n    sl.fit(iris.target, iris.data)\n    score = metrics.accuracy_score(iris.target, sl.predict(iris.data))\n    print(\"Accuracy: %f\" % score)\n\nMore detail example is here.\nhttps://github.com/fukatani/stacked\\_generalization/blob/master/stacked\\_generalization/example/cross\\_validation\\_for\\_iris.py\n\nhttps://github.com/fukatani/stacked\\_generalization/blob/master/stacked\\_generalization/example/simple\\_regression.py\n\n2) Evaluation model by out-of-bugs score.\n'''''''''''''''''''''''''''''''''''''''''\n\nStacking technic itself uses CV to stage0. So if you use CV for entire\nstacked model, ***each stage 0 model are fitted n\\_folds squared\ntimes.*** Sometimes its computational cost can be significent, therefore\nwe implemented CV only for stage1[2].\n\nFor example, when we get 3 blends (stage0 prediction), 2 blends are used\nfor stage 1 fitting. The remaining one blend is used for model test.\nRepitation this cycle for all 3 blends, and averaging scores, we can get\noob (out-of-bugs) score ***with only n\\_fold times stage0 fitting.***\n\nex.\n\n.. code:: python\n\n    sl = StackedClassifier(bclf, clfs, oob_score_flag=True)\n    sl.fit(iris.data, iris.target)\n    print(\"Accuracy: %f\" % sl.oob_score_)\n\n3) Caching stage1 blend\\_data and trained model. (optional)\n'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''\n\nIf cache is exists, recalculation for stage 0 will be skipped. This\nfunction is useful for stage 1 tuning.\n\n.. code:: python\n\n    sl = StackedClassifier(bclf, clfs, save_stage0=True, save_dir='stack_temp')\n\nFeature of Joblibed Classifier / Regressor\n------------------------------------------\n\nJoblibed Classifier / Regressor is simple cache system for scikit-learn\nmachine learning model. You can use it easily by minimum code\nmodification.\n\nAt first fitting and prediction, model calculation is performed\nnormally. At the same time, model fitting result and prediction result\nare saved as *.pkl* and *.csv* respectively.\n\n**At second fitting and prediction, if cache is existence, model and\nprediction results will be loaded from cache and never recalculation.**\n\ne.g.\n\n.. code:: python\n\n    from sklearn import datasets\n    from sklearn.cross_validation import StratifiedKFold\n    from sklearn.ensemble import RandomForestClassifier\n    from stacked_generalization.lib.joblibed import JoblibedClassifier\n\n    # Load iris\n    iris = datasets.load_iris()\n\n    # Declaration of Joblibed model\n    rf = RandomForestClassifier(n_estimators=40)\n    clf = JoblibedClassifier(rf, \"rf\")\n\n    train_idx, test_idx = list(StratifiedKFold(iris.target, 3))[0]\n\n    xs_train = iris.data[train_idx]\n    y_train = iris.target[train_idx]\n    xs_test = iris.data[test_idx]\n    y_test = iris.target[test_idx]\n\n    # Need to indicate sample for discriminating cache existence.\n    clf.fit(xs_train, y_train, train_idx)\n    score = clf.score(xs_test, y_test, test_idx)\n\nSee also\nhttps://github.com/fukatani/stacked\\_generalization/blob/master/stacked\\_generalization/lib/joblibed.py\n\nSoftware Requirement\n--------------------\n\n-  Python (2.7 or 3.5 or later)\n-  numpy\n-  scikit-learn\n-  pandas\n\nInstallation\n------------\n\n::\n\n    pip install stacked_generalization\n\nLicense\n-------\n\nMIT License. (http://opensource.org/licenses/mit-license.php)\n\nCopyright\n---------\n\nCopyright (C) 2016, Ryosuke Fukatani\n\nMany part of the implementation of stacking is based on the following.\nThanks!\nhttps://github.com/log0/vertebral/blob/master/stacked\\_generalization.py\n\nOther\n-----\n\nAny contributions (implement, documentation, test or idea...) are\nwelcome.\n\nReferences\n----------\n\n[1] L. Breiman, \"Stacked Regressions\", Machine Learning, 24, 49-64\n(1996). [2] J. Sill1 et al, \"Feature Weighted Linear Stacking\",\nhttps://arxiv.org/abs/0911.0460, 2009.\n\n.. |Build Status| image:: https://travis-ci.org/fukatani/stacked_generalization.svg?branch=master\n   :target: https://travis-ci.org/fukatani/stacked_generalization\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffukatani%2Fstacked_generalization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffukatani%2Fstacked_generalization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffukatani%2Fstacked_generalization/lists"}