Coder Social home page Coder Social logo

hadinh1306 / regscore-py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ubc-mds/regscorepy

0.0 1.0 0.0 148 KB

This is the repo for a python package that does model comparison between different regression models.

License: MIT License

Python 100.00%

regscore-py's Introduction

RegscorePy

Build Status codecov

A python package that does model comparison between different regression models.

Installation

pip install git+https://github.com/UBC-MDS/RegscorePy.git

Function Description And Usage

AIC

AIC stands for Akaike’s Information Criterion. It estimates the quality of a model, relative to each of other models. The lower AIC score is, the better the model is. Therefore, a model with lowest AIC - in comparison to others, is chosen.

AIC = n*log(residual sum of squares/n) + 2K

where:

  • n: number of observations
  • K: number of parameters (including intercept)

Function

aic(y, y_pred, p)

Parameters:

  • y: array-like of shape = (n_samples) or (n_samples, n_outputs)

    • True target variable(s)
  • y_pred: array-like of shape = (n_samples) or (n_samples, n_outputs)

    • Fitted target variable(s) obtained from your regression model
  • p: int

    • Number of predictive variable(s) used in the model

Return:

  • aic_score: int
    • AIC score of the model

BIC

BIC stands for Bayesian Information Criterion. Like AIC, it also estimates the quality of a model. When fitting models, it is possible to increase model fitness by adding more parameters. Doing this may result in model overfit. Both AIC and BIC help to resolve this problem by using a penalty term for the number of parameters in the model. This term is bigger in BIC than in AIC.

BIC = n*log(residual sum of squares/n) + K*log(n)

where:

  • n: number of observations
  • K: number of parameters (including intercept)

Function

bic(y, y_pred, p)

Parameters:

  • y: array-like of shape = (n_samples) or (n_samples, n_outputs)

    • True target variable(s)
  • y_pred: array-like of shape = (n_samples) or (n_samples, n_outputs)

    • Fitted target variable(s) obtained from your regression model
  • p: int

    • Number of predictive variable(s) used in the model

Return:

  • bic_score: int
    • BIC score of the model

Mallow's C_p

Introduction

Mallow's C_p is named for Colin Lingwood Mallows. It is used to assess the fit of regression model, finding the best model involving a subset of predictive variables available for predicting some outcome.

C_p = (SSE_p/MSE) - (n - 2p)

where:

  • SSE_k: residual sum of squares for the subset model containing p explanatory variables counting the intercept.
  • MSE: mean squared error for the full model (model containing all k explanatory variables of interest)
  • n: number of observations
  • p: number of subset explanatory variables

Function

mallow(y, y_pred, y_sub, k, p)

Parameters:

  • y: array-like of shape = (n_samples) or (n_samples, n_outputs)

    • True target variable(s)
  • y_pred: array-like of shape = (n_samples) or (n_samples, n_outputs)

    • Fitted target variable(s) obtained from your regression model
  • y_sub: array-like of shape = (n_samples) or (n_samples, n_outputs)

    • Fitted target variable(s) obtained from your subset regression model
  • k: int

    • Number of predictive variable(s) used in the model
  • p: int

    • Number of predictive variable(s) used in the subset model

Return:

  • mallow_score: int
    • Mallow's C_p score of the subset model

Usage

>> from RegscorePy import *
>> y = [1,2,3,4]
>> y_pred = [5,6,7,8]
>> p = 3
>> aic.aic(y, y_pred, p)
17.090354888959126
>>
>>
>> bic.bic(y, y_pred, p)
15.249237972318795
>>
>>
>> y_sub = [1,2,3,5]
>> k = 3
>> p = 2
>> mallow.mallow(y, y_pred, y_sub, k, p) 
>> 0.015625

  • This usage apply to python3. If you use python2, please run from __future__ import division before run the function.

How to run tests

From root directory, run all test files in terminal:

python -m pytest

You also have the option to run individual test files by referencing its path. For example, if you want to test aic function, you can use the command below:

python -m pytest RegscorePy/test/test_aic.py

License

MIT

Contributing

This is an open source project. Please follow the guidelines below for contribution.

  • Open an issue for any feedback and suggestions.
  • For contributing to the project, please refer to Contributing for details.

regscore-py's People

Contributors

hadinh1306 avatar rq1995 avatar simrnsethi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.