Giter Site home page Giter Site logo

jingweitoo / machine-learning-regression-toolbox Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 4.0 51 KB

This toolbox offers 7 machine learning methods for regression problems.

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
linear-regression decision-tree-regression machine-learning regression holdout k-fold-cross-validation leave-one-out-cross-validation lasso-regression ridge-regression neural-network

machine-learning-regression-toolbox's Introduction

Jx-MLT : A Machine Learning Toolbox for Regression

License GitHub release


"Toward Talent Scientist: Sharing and Learning Together" --- Jingwei Too


Wheel

Introduction

  • This toolbox contains 7 widely used machine learning algorithms
  • The Demo_LR and Demo_LASSO provide the examples of how to use these methods on benchmark dataset

Usage

You may switch the algorithm by changing the lr in from MLR.lr import jkfold to other abbreviations

  • If you wish to use linear regression ( LR ) then you may write
from MLR.lr import jkfold 
  • If you want to use decision tree ( DT ) then you may write
from MLR.dt import jkfold  

Input

  • feat : feature vector matrix ( Instance x Features )
  • label : label matrix ( Instance x 1 )
  • opts : parameter settings
    • ho : ratio of testing data in hold-out validation
    • kfold : number of folds in k-fold cross-validation

Output

  • mdl : Machine learning model ( It contains several results )
    • mse : mean square error
    • r2 : R square score

How to choose the validation scheme?

There are three types of performance validations. These validation strategies are listed as following ( LR is adopted as an example ).

  • Hold-out cross-validation
from MLR.lr import jho
  • K-fold cross-validation
from MLR.lr import jkfold
  • Leave-one-out cross-validation
from MLR.lr import jloo

Example 1 : Linear Regression ( LR ) with k-fold cross-validation

import numpy as np
# change this to switch algorithm & types of validation (jho, jkfold, jloo)
from MLR.lr import jkfold 
import matplotlib.pyplot as plt
from sklearn import datasets


# load data
X, Y  = datasets.load_diabetes(return_X_y=True)
feat  = X[:, np.newaxis, 2]
label = Y

# parameters
kfold = 10
opts  = {'kfold':kfold}
# LR with k-fold
mdl   = jkfold(feat, label, opts) 

# overall mse
mse = mdl['mse']

# overall r2 score
r2  = mdl['r2']

Example 2 : LASSO Regression with hold-out validation

import numpy as np
# change this to switch algorithm & types of validation (jho, jkfold, jloo)
from MLR.lasso import jho 
import matplotlib.pyplot as plt
from sklearn import datasets


# load data
X, Y  = datasets.load_diabetes(return_X_y=True)
feat  = X[:, np.newaxis, 2]
label = Y

# parameters
ho    = 0.3    # ratio of testing data
alpha = 1
opts  = {'alpha':alpha, 'ho':ho}
# LR 
mdl   = jho(feat, label, opts) 

# overall mse
mse = mdl['mse']

# overall r2 score
r2  = mdl['r2']

Example 3 : Decision Tree ( DT ) with leave-one-out validation

import numpy as np
# change this to switch algorithm & types of validation (jho, jkfold, jloo)
from MLR.dt import jloo 
import matplotlib.pyplot as plt
from sklearn import datasets


# load data
X, Y  = datasets.load_diabetes(return_X_y=True)
feat  = X[:, np.newaxis, 2]
label = Y

# parameters
maxDepth = 5      # maximum depth of tree
opts  = {'maxDepth':maxDepth}
# DT 
mdl   = jloo(feat, label, opts) 

# overall mse
mse = mdl['mse']

# overall r2 score
r2  = mdl['r2']

Requirement

  • Python 3
  • Numpy
  • Pandas
  • Scikit-learn
  • Matplotlib

List of available machine learning methods

  • Click on the name of algorithm to check the parameters
  • Use the opts to set the specific parameters
  • If you do not set extra parameters then the algorithm will use default setting in here
No. Abbreviation Name
07 en Elastic Net
06 nn Neural Network
05 svr Support Vector Regression
04 ridge Ridge Regression
03 lasso Lasso Regression
02 dt Decision Tree
01 lr Linear Regression

machine-learning-regression-toolbox's People

Contributors

jingweitoo avatar

Stargazers

 avatar  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.