Skip to content

Where should I add ILOGMR sklearn compatible? #50

@jgrizou

Description

@jgrizou

Hi guys,

I started using ILOGMR to compare it with various regression algortihm in sci-kit learn. For this I had to create a class wrapping the ilo_gmm from explauto to an ILOGMR estimator in sklearn.

Should I had this file in the explauto repo? If yes, where should it land?

Currently the class is as follow:

import numpy

from sklearn.base import BaseEstimator

from explauto.sensorimotor_model import ilo_gmm


class ILOGMR(BaseEstimator):

    def __init__(self, conf, n_components=3, n_neighbors=100, random_state=None):
        self.conf = conf
        self.explauto_ilo_gmm = ilo_gmm.IloGmm(conf, n_components)
        self.explauto_ilo_gmm.n_neighbors = n_neighbors
        self.random_state = random_state

    def fit(self, X, y):
        self.explauto_ilo_gmm.dataset.reset()
        for n in range(X.shape[0]):
            self.explauto_ilo_gmm.update(X[n, :], y[n, :])

    def compute_conditional_gmm(self, x):
        return self.explauto_ilo_gmm.compute_conditional_gmm(
            self.conf.m_dims, self.conf.s_dims, x)

    def predict(self, X):
        y_pred = numpy.zeros((X.shape[0], len(self.explauto_ilo_gmm.s_dims)))
        for n in range(X.shape[0]):
            gmm = self.compute_conditional_gmm(X[n, :])
            y_pred[n, :] = numpy.sum(gmm.means_.T * gmm.weights_)
        return y_pred

This use the new interface for ilo_gmm.py that is currently under pull request #49

It still lacks the set_param, get_parm method so we can use it with the really convenient GridSearchCV but it will come at some point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions