GithubHelp home page GithubHelp logo

msvr's Introduction

Multiple Support Vector Regression

Multiple support vector regression is a method which implements support vector regression with multi-input and multi-output. This package is based on the paper, Multi-dimensional function approximation and regression estimation, F Pérez-Cruz.

Usage

from msvr import kernelmatrix
from msvr import msvr
import numpy as np

# Construct x samples (input) and y samples (output)
# x: num_samples * dimension
# y: num_smaples * dimension
x1 = np.sin(np.arange(0, 9, 0.01))
x2 = np.cos(np.arange(0, 9, 0.01))
x3 = x1**2
x4 = (x1+x2)/2

x = np.vstack((x1,x2)).T
y = np.vstack((x3,x4)).T

# Input & Output
# Xtrain: number of samples * input dimension
# Ytrain: number of samples * output dimension

Xtrain = x[:600, :]
Ytrain = y[:600, :]
Xtest = x[600:, :]
Ytest = y[600:, :]
Xtrain = (Xtrain-np.min(Xtrain))/(np.max(Xtrain)-np.min(Xtrain))
Ytrain = (Ytrain-np.min(Ytrain))/(np.max(Ytrain)-np.min(Ytrain))

# Parameters
#  ker: kernel ('lin', 'poly', 'rbf'),
#  C: cost parameter,
#  par (kernel):
#	  -lin: no parameters,
#	  -poly: [gamma, b, degree],
#	  -rbf: sigma (width of the RBF kernel),
#  tol: tolerance.

ker  = 'rbf'
C    = 2
epsi = 0.001
par  = 0.8 # if kernel is 'rbf', par means sigma
tol  = 1e-10

# Train
Beta = msvr(Xtrain, Ytrain, ker, C, epsi, par, tol)

# Predict with train set
H = kernelmatrix('rbf', Xtrain, Xtrain, par);
Ypred = np.dot(H, Beta)

# Predict with test set
H = kernelmatrix('rbf', Xtest, Xtrain, par);
Ypred = np.dot(H, Beta)

Kernel function

kernel function

msvr's People

Contributors

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