Classification

Classification is one of the main machine Learning task in these days. PHOTON provides all tools for a fast and convenient design of classification machine learning pipeline layouts.

           
from photonai.base.PhotonBase import Hyperpipe, PipelineElement
from photonai.optimization.Hyperparameters import Categorical
from photonai.configuration.Register import PhotonRegister
from sklearn.model_selection import KFold
from sklearn.datasets import load_breast_cancer,load_iris

X,y = load_breast_cancer(True)

# DESIGN YOUR PIPELINE
my_pipe = Hyperpipe('basic_classification_pipe',
                    optimizer='sk_opt',
                    metrics=['accuracy', 'f1_score'],  # the performance metrics of your interest
                    best_config_metric='accuracy',  # after hyperparameter search, the metric declares the winner config
                    outer_cv=KFold(n_splits=3),  # repeat hyperparameter search three times
                    inner_cv=KFold(n_splits=3),  # test each configuration ten times respectively
                    verbosity=1)


# NOW FIND OUT MORE ABOUT THE LinearSVC ELEMENT
PhotonRegister.info('LinearSVC')

# ADD ELEMENTS TO YOUR PIPELINE
# first normalize all features
my_pipe += PipelineElement('StandardScaler',test_disabled=True)

my_pipe += PipelineElement('LinearSVC', hyperparameters={'C': FloatRange(0.5, 25)})

# NOW TRAIN YOUR PIPELINE
my_pipe.fit(X, y)