{"id":31225225,"url":"https://github.com/machinelearningbcam/mrcs-for-covariate-shift-adaptation","last_synced_at":"2025-09-22T00:42:12.182Z","repository":{"id":171577816,"uuid":"613970466","full_name":"MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation","owner":"MachineLearningBCAM","description":"Minimax Classification under Covariate Shift with Performance Guarantees","archived":false,"fork":false,"pushed_at":"2024-01-11T15:35:00.000Z","size":13384,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-01-11T23:57:47.451Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MachineLearningBCAM.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-03-14T16:22:14.000Z","updated_at":"2023-07-22T23:45:45.000Z","dependencies_parsed_at":"2024-01-11T18:51:45.302Z","dependency_job_id":null,"html_url":"https://github.com/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation","commit_stats":null,"previous_names":["machinelearningbcam/mrcs-for-covariate-shift-adaptation"],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MachineLearningBCAM%2FMRCs-for-Covariate-Shift-Adaptation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MachineLearningBCAM%2FMRCs-for-Covariate-Shift-Adaptation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MachineLearningBCAM%2FMRCs-for-Covariate-Shift-Adaptation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MachineLearningBCAM%2FMRCs-for-Covariate-Shift-Adaptation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MachineLearningBCAM","download_url":"https://codeload.github.com/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MachineLearningBCAM%2FMRCs-for-Covariate-Shift-Adaptation/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276329459,"owners_count":25623326,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-21T02:00:07.055Z","response_time":72,"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":"2025-09-22T00:42:09.840Z","updated_at":"2025-09-22T00:42:12.140Z","avatar_url":"https://github.com/MachineLearningBCAM.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Double-Weighting for General Covariate Shift Adaptation\n[![Made with!](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](#python-code) [![Made with!](https://img.shields.io/badge/Made%20with-MATLAB-red)](#matlab-code) [![Ask Me Anything !](https://img.shields.io/badge/Ask%20me-anything-1abc9c.svg)](#support-and-authors)\n\nThis repository is the official implementation of [Double-Weighting for General Covariate Shift Adaptation](https://arxiv.org/abs/2305.08637). \n\nThe algorithm proposed in the paper provides efficient learning for the proposed Doble-Weighting for General Covariate Shift (DW-GCS). In particular, we first compute weights $\\alpha$ and $\\beta$ by solving the Double-Weighting Kernel Mean Matching (DW-KMM). Then, we learn the classifier's parameters by solving the MRC using double-weighting.\n\n## Python Code\n\n### Requirements\n\nThe standard libraries required are listed in the file `requirements.txt`. To install these libraries using\n\n1) `pip`\n```setup\npip install -r requirements.txt\n```\n\n2) `conda` environment\n```\nconda create --name \u003cenvironment_name\u003e --file requirements.txt\n```\n\nIn addition, the implementation of the proposed algorithm utilizes the MOSEK optimizer for which license can be downloaded from [here](https://www.mosek.com/products/academic-licenses/).\n\n### Code\n\nThe functions in the folder [Python_code](https://github.com/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation/tree/main/Experiments_Paper) folder contains experiment scripts required to replicate the experiments of the paper.\n\n* Experiment_Features.py, Experiment_PCA.py and Experiment_20News.py are the main files. \n* Experiment_Features.py file perform a experiment for datasets in which we artificially introduce the covariate shift based on the median of the features. \n* Experiment_PCA.py file perform a experiment for datasets in which we artificially introduce the covariate shift based on the median of the first principal component of the features. \n* Experiment_20News.py file perform a experiment using the “News20groups” dataset that is intrinsically affected by a covariate shift since the training and testing partitions correspond to different times.\n* In such files we can modify the feature mapping, and the loss we are going to use. We can also choose if the classifier is deterministic or not.\n* The file CovShiftGen.py generate covariate shift in the datasets. In particular, we select training and testing samples with different probabilities based on the medians of the first 3 features, and based on the median of the first principal component of features.\n* The folder [Auxiliary_Functions](https://github.com/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation/tree/main/Auxiliary_Functions) contains the function phi.py that calculates the feature mappings using linear, polinomial or random Fourier features (RFF).\n* The folder [DWGCS](https://github.com/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation/tree/main/DWGCS) contains the functions of the Double-Weighting for General Covariate Shift Adaptation.\n* DWGCS.DWKMM computes the estimated weights $\\beta$ and $\\alpha$ solving the double-weighting kernel mean matching.\n* DWGCS.parameters obtains mean vector estimate $\\tau$ and confidence vector $\\lambda$.\n* DWGCS.learning solves the convex MRC optimization problem using double-weighting and obtains the classifier parameters.\n* DWGCS.prediction assigns labels to instances and gives the classification error.\n\n## Matlab Code\n\n[Matlab_code](https://github.com/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation/tree/main/Matlab_Code%20) folder contains Matlab scripts required to execute the method:\n\n* run_DWGCS_example1.m and run_DWGCS_example1.m are the main files. \n* run_DWGCS_example1.m file perform a experiment for datasets in which we artificially introduce the covariate shift. \n* run_DWGCS_example2.m file perform a experiment using the “News20groups” dataset that is intrinsically affected by a covariate shift since the training and testing partitions correspond to different times. \n* In such files we can modify the feature mapping, and the loss we are going to use. We can also choose if the classifier is deterministic or not.\n* The functions in the folder [CovShift_Generation](https://github.com/MachineLearningBCAM/MRCs-for-Covariate-Shift-Adaptation/tree/main/Matlab_Code%20/CovShift_Generation) generate covariate shift in the datasets. In particular, we select training and testing samples with different probabilities based on the medians of the first 3 features, and based on the median of the first principal component of features.\n* phi.m calculates the feature mappings using linear, polinomial or random Fourier features (RFF).\n* DWGCS_weights.m computes the estimated weights $\\beta$ and $\\alpha$ solving the double-weighting kernel mean matching.\n* DWGCS_parameters.m obtains mean vector estimate $\\tau$ and confidence vector $\\lambda$.\n* DWGCS_learning.m solves the convex MRC optimization problem using double-weighting and obtains the classifier parameters.\n* DWGCS_prediction.m assigns labels to instances and gives the classification error.\n\n## Data\n\nThe repository contains multiple datasets to perform experiments as follows - \n\nDataset | Covariates | Samples | Ratio of majority class | $\\sigma$\n--- | --- | --- | --- | ---\nBlood | 3 | 748 | 76.20% | 0.7491\nBreastCancer | 9 | 683 | 65.01% | 1.6064\nHaberman | 3 | 306 | 75.53% | 1.3024\nRingnorm | 20 | 7400 | 50.49% | 3.8299\ncomp vs sci | 1000 | 5309 (tr) / 3534 (te) | 55.31% | 23.5628\ncomp vs talk | 1000 | 4888 (tr) / 3256 (te) | 60.06% | 23.4890\nrec vs sci | 1000 | 4762 (tr) / 3169 (te) | 50.17% | 24.5642\nrec vs talk | 1000 | 4341 (tr) / 2891 (te) | 55.02% | 25.1129\nsci vs talk | 1000 | 4325 (tr) / 2880 (te) | 54.85% | 24.8320\n\nThe datasets are available as csv files in this repository in the `Datasets` and `Datasets_20News`folders.\n\n## Support and Authors\n\nJosé I. Segovia-Martín\n\njsegovia@bcamath.org\n\nSantiago Mazuelas \n\nsmazuelas@bcamath.org\n\nAnqi Liu\n\naliu@cs.jhu.edu\n\n## Citation\n\nIf you find useful the code in your research, please include explicit mention of our work in your publication with the following corresponding entry in your bibliography:\n\n[1] José I. Segovia-Martín, S. Mazuelas, A. Liu \"Double-Weighting for Covariate Shift Adaptation\". Proceedings of the 40th International Conference on Machine Learning. PMLR, 2023.\n\nThe corresponding BiBTeX citation is given below:\n\n@inproceedings{SegMazLiu2023,\n  title={Double-Weighting for Covariate Shift Adaptation},\n  author={Segovia-Mart'{i}n, Jos'{e} I. and Mazuelas, Santiago and Liu, Anqi},\n  booktitle={International Conference on Machine Learning},\n  pages={30439--30457},\n  year={2023},\n  organization={PMLR}\n}","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachinelearningbcam%2Fmrcs-for-covariate-shift-adaptation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmachinelearningbcam%2Fmrcs-for-covariate-shift-adaptation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachinelearningbcam%2Fmrcs-for-covariate-shift-adaptation/lists"}