项目作者: KARTHEEKCIC

项目描述 :
Variations of minimax risk classifiers with different loss functions
高级语言: Python
项目地址: git://github.com/KARTHEEKCIC/Minimax-Risk-Classifiers.git
创建时间: 2020-12-24T11:15:51Z
项目社区:https://github.com/KARTHEEKCIC/Minimax-Risk-Classifiers

开源协议:

下载


Minimax-Risk-Classifier

Different variations of minimax risk classifiers(MRC) using different loss functions and uncertainity set of distributions.

The variants available here are -

1) MRC with 0-1 loss (MRC.py)
2) MRC with log loss (MRC.py)
3) MRC with 0-1 loss and fixed instances’ marginals (CMRC.py)
4) MRC with log loss and fixed instances’ marginals (CMRC.py)

Requirements

Generic badge

We will need have installed the following libraries:

  • numpy
  • sklearn
  • cvxpy

We can install the requirements directly from the file “requirements.txt”

  1. pip install -r requirements.txt

Usage

Fitting the models

MRC with 0-1 loss

  1. clf = MRC(r=r, loss='0-1').fit(X, Y)

MRC with log loss

  1. clf = MRC(r=r, loss='log').fit(X, Y)

MRC with 0-1 loss and fixed instances’ marginals

  1. clf = CMRC(r=r, loss='0-1').fit(X, Y)

MRC with log loss and fixed instances’ marginals

  1. clf = CMRC(r=r, loss='log').fit(X, Y)

A small training example of MRC

  1. from MRC import MRC
  2. from datasets import load_mammographic
  3. X, Y = load_mammographic(return_X_y=True)
  4. r = len(np.unique(Y))
  5. clf = MRC(r=r).fit(X, Y)
  6. y_pred = clf.predict(X[:2,:])

Bounds on the error for MRC

  1. clf = MRC(r=r).fit(X, Y)
  2. upper_bound = clf.upper
  3. lower_bound = clf.getLowerBound()

Only available for the MRC class

Setting the interval estimates while fitting

Using instances X and Y to calculate tau and lambda

  1. clf = MRC(r=r).fit(X, Y, X_, Y_)

By passing the values for tau and lambda

  1. clf = MRC(r=r).fit(X, Y, _tau=0.5, _lambda=0.1)