Commit e2ec5c64 authored by Imanol Perez's avatar Imanol Perez
Browse files

Upload new file

parent bbe079e5
import numpy as np
import iisignature
from sklearn.ensemble import RandomForestRegressor
import numbers
class sigLearn:
def __init__(self, order=2, alpha=0.1):
if not isinstance(order, numbers.Integral) or order<1:
raise NameError('The order must be a positive integer.')
if not isinstance(alpha, numbers.Real) or alpha<=0.0:
raise NameError('Alpha must be a positive real.')
def train(self, x, y):
Trains the model using signatures.
x: list of inputs.
y: list of outputs.
# We check that types of x and y are the expected ones
if x is None or y is None:
if not (type(x) is list or type(x) is tuple) or not (type(y) is list or type(y) is tuple):
raise NameError('Input and output must be lists or tuples.')
if len(x)!=len(y):
raise NameError('The number of inputs and the number of outputs must coincide.')
X=[list(iisignature.sig(np.array(stream), self.order)) for stream in x]
self.reg = RandomForestRegressor(n_estimators=100, oob_score=True), y)
def predict(self, x):
Predicts the outputs of the inputs x using the the pre-trained model.
x: list of inputs.
list of predicted outputs.
if self.reg is None:
raise NameError('The model is not trained.')
X=[list(iisignature.sig(np.array(stream), self.order)) for stream in x]
return self.reg.predict(X)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment