{"id":18812175,"url":"https://github.com/drorspei/varvar","last_synced_at":"2026-07-03T01:31:50.541Z","repository":{"id":57676308,"uuid":"429061721","full_name":"drorspei/varvar","owner":"drorspei","description":"Python package to model variance in different ways","archived":false,"fork":false,"pushed_at":"2023-01-24T14:15:47.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-27T00:35:22.923Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drorspei.png","metadata":{"files":{"readme":"README.md","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":"2021-11-17T13:43:57.000Z","updated_at":"2021-11-17T14:34:28.000Z","dependencies_parsed_at":"2023-02-13T22:16:46.320Z","dependency_job_id":null,"html_url":"https://github.com/drorspei/varvar","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drorspei/varvar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorspei%2Fvarvar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorspei%2Fvarvar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorspei%2Fvarvar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorspei%2Fvarvar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drorspei","download_url":"https://codeload.github.com/drorspei/varvar/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drorspei%2Fvarvar/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35069183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-02T02:00:06.368Z","response_time":173,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":[],"created_at":"2024-11-07T23:30:14.047Z","updated_at":"2026-07-03T01:31:50.505Z","avatar_url":"https://github.com/drorspei.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# varvar\nPython package to model variance in different ways\n\n# Multiplicative variance trees and the varvar algorithm\n\nvarvar is a greedy algorithm for multiplicative variance trees.\n\nvarvar is to variance as lightgbm/xgboost/... are to expectation.\n\nThere are currently two implementations of varvar algorithms:\n1. using quantile search at every split (in `varvar.qtrees`)\n2. using histograms, with binning before starting (in `varvar.htrees`)\n\nQuantile search is much slower, but can be more accurate.\n\nThis is similar to the \"exact\" and \"hist\" modes in xgboost, except our \"exact\"\nalgorithm goes over a small (exact) subset of each feature.\n\nBoth implementation modules have a `multiplicative_variance_trees` function.\n\nUse `varvar.predict` for prediction.\n\nThe trees are returned as plain python types and can be serialized with pickle\nor even as json.\n\nHere is an example:\n\n```\nfrom varvar.htrees import multiplicative_variance_trees\nfrom varvar import predict\nimport numpy as np\n\nrandom = np.random.RandomState(1729)\nn = 200000\nx = random.uniform(-1000, 1000, n)\ncorrect_threshold = 300\nsigma = 1 * (x \u003c= correct_threshold) + 30 * (x \u003e correct_threshold)\ne = sigma * random.randn(n)\n\ntrees = multiplicative_variance_trees(\n    [x], e**2,\n    num_trees=2, max_depth=1, min_gain=1, learning_rate=1,\n)\npreds = predict(trees, [x])\n\nfound_threshold = trees[1][0][1]\nprint(correct_threshold, found_threshold)  # 300, 295\nprint(np.sqrt(min(preds)), np.sqrt(max(preds)))  # 1, 30\n```\n\n## conversion to xgboost booster\n\nYou can convert multiplicative variance trees to an xgboost booster.\n\nThis allows you to use xgboost's predict function (which actually seems to be a bit slower), and more importantly to use the shap package\nto interpret varvar predictions.\n\n```\nfrom varvar import mvt_to_xgboost\nbooster = mvt_to_xgboost(trees, feature_names=[\"f1\", \"f2\"])\n```\n\nYou need xgboost 1.6.1 or higher installed to run this code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorspei%2Fvarvar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrorspei%2Fvarvar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrorspei%2Fvarvar/lists"}