While we keep working on the docs and figures, here is a little example you
all can already run:

import numpy as np
import pandas as pd
from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import GridSearchCV
from pipegraph.pipeGraph import PipeGraphClassifier, Concatenator
import matplotlib.pyplot as plt
from sklearn.datasets import load_iris
from sklearn.naive_bayes import GaussianNB
from sklearn.svm import SVC
from sklearn.neural_network import MLPClassifier

iris = load_iris()
X = iris.data
y = iris.target

scaler = MinMaxScaler()
gaussian_nb = GaussianNB()
svc = SVC()
mlp = MLPClassifier()
concatenator = Concatenator()

steps = [('scaler', scaler),
         ('gaussian_nb', gaussian_nb),
         ('svc', svc),
         ('concat', concatenator),
         ('mlp', mlp)]

connections = { 'scaler': {'X': 'X'},
                'gaussian_nb': {'X': ('scaler', 'predict'),
                                'y': 'y'},
                'svc':  {'X': ('scaler', 'predict'),
                         'y': 'y'},
                'concat': {'X1': ('scaler', 'predict'),
                           'X2': ('gaussian_nb', 'predict'),
                           'X3': ('svc', 'predict')},
                'mlp': {'X': ('concat', 'predict'),
                        'y': 'y'}

param_grid = {'svc__C': [0.1, 0.5, 1.0],
              'mlp__hidden_layer_sizes': [(3,), (6,), (9,),],
              'mlp__max_iter': [5000, 10000]}

pgraph = PipeGraphClassifier(steps=steps, connections=connections)
grid_search_classifier  = GridSearchCV(estimator=pgraph,
param_grid=param_grid, refit=True)
grid_search_classifier.fit(X, y)
y_pred = grid_search_classifier.predict(X)

'predict' is the default output name. One of these days we will simplify
the notation to simply the name of the node in case of default output names.

Best wishes

2018-02-07 23:29 GMT+01:00 Andreas Mueller <t3k...@gmail.com>:

> Thanks Manuel, that looks pretty cool.
> Do you have a write-up about it? I don't entirely understand the
> connections setup.
> _______________________________________________
> scikit-learn mailing list
> scikit-learn@python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
scikit-learn mailing list

Reply via email to