-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new example debug pipeline stacking
- Loading branch information
Showing
5 changed files
with
58 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,28 @@ | ||
from photonai.base.PhotonBase import Hyperpipe, PipelineElement, PipelineStacking, PipelineBranch, OutputSettings | ||
from photonai.base.PhotonBase import Hyperpipe, PipelineElement, PipelineStacking, | ||
from photonai.optimization.Hyperparameters import FloatRange, IntegerRange, Categorical | ||
from photonai.investigator.Investigator import Investigator | ||
from photonai.configuration.Register import PhotonRegister | ||
from sklearn.model_selection import KFold | ||
|
||
from sklearn.datasets import load_breast_cancer | ||
X, y = load_breast_cancer(True) | ||
|
||
|
||
my_pipe = Hyperpipe('basic_stacking', | ||
optimizer='grid_search', | ||
optimizer='sk_opt', | ||
metrics=['accuracy', 'precision', 'recall'], | ||
best_config_metric='accuracy', | ||
outer_cv=KFold(n_splits=3), | ||
inner_cv=KFold(n_splits=10), | ||
verbosity=1) | ||
|
||
tree_branch = PipelineBranch('first_branch') | ||
tree_branch += PipelineElement('StandardScaler') | ||
tree_branch += PipelineElement('DecisionTreeClassifier', {'criterion': ['gini'], | ||
'min_samples_split': IntegerRange(2, 4)}) | ||
|
||
svm_branch = PipelineBranch('svm_branch') | ||
svm_branch += PipelineElement('StandardScaler') | ||
svm_branch += PipelineElement('SVC', {'kernel': Categorical(['rbf', 'linear']), | ||
'C': FloatRange(0.5, 2, "linspace", num=3)}) | ||
|
||
|
||
my_pipe += PipelineElement('StandardScaler') | ||
my_pipe_stack = PipelineStacking('final_stack', voting=False) | ||
my_pipe_stack += svm_branch | ||
my_pipe_stack += tree_branch | ||
my_pipe_stack += PipelineElement('DecisionTreeClassifier', hyperparameters={'criterion': ['gini'], | ||
'min_samples_split': IntegerRange(2, 4)}) | ||
|
||
my_pipe_stack += PipelineElement('LinearSVC', hyperparameters={'C': FloatRange(0.5, 25)}) | ||
my_pipe += my_pipe_stack | ||
|
||
my_pipe += PipelineElement('SVC', {'kernel': Categorical(['rbf', 'linear'])}) | ||
|
||
my_pipe.fit(X, y) | ||
|
||
# Investigator.load_from_file("basic_svm_pipe", 'my_tree.p') | ||
|
||
debug = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from photonai.base.PhotonBase import Hyperpipe, PipelineElement, PipelineStacking, PipelineBranch | ||
from photonai.optimization.Hyperparameters import FloatRange, IntegerRange, Categorical | ||
from photonai.investigator.Investigator import Investigator | ||
from photonai.configuration.Register import PhotonRegister | ||
from sklearn.model_selection import KFold | ||
from sklearn.datasets import load_breast_cancer | ||
|
||
X, y = load_breast_cancer(True) | ||
|
||
|
||
my_pipe = Hyperpipe('basic_stacking', | ||
optimizer='grid_search', | ||
metrics=['accuracy', 'precision', 'recall'], | ||
best_config_metric='f1_score', | ||
outer_cv=KFold(n_splits=3), | ||
inner_cv=KFold(n_splits=10), | ||
verbosity=1) | ||
|
||
# BRANCH WITH QUANTILTRANSFORMER AND DECISIONTREECLASSIFIER | ||
tree_qua_branch = PipelineBranch('tree_branch') | ||
tree_qua_branch += PipelineElement('QuantileTransformer') | ||
tree_qua_branch += PipelineElement('DecisionTreeClassifier',{'min_samples_split': IntegerRange(2, 4)},criterion='gini') | ||
|
||
# BRANCH WITH MinMaxScaler AND DecisionTreeClassifier | ||
svm_mima_branch = PipelineBranch('svm_branch') | ||
svm_mima_branch += PipelineElement('MinMaxScaler') | ||
svm_mima_branch += PipelineElement('SVC', {'kernel': Categorical(['rbf', 'linear']), | ||
'C':2.0},gamma='auto') | ||
|
||
# BRANCH WITH StandardScaler AND KNeighborsClassifier | ||
knn_sta_branch = PipelineBranch('neighbour_branch') | ||
knn_sta_branch += PipelineElement('StandardScaler') | ||
knn_sta_branch += PipelineElement('KNeighborsClassifier') | ||
|
||
# voting = True to mean the result of every branch | ||
my_pipe_stack = PipelineStacking('final_stack', voting=True) | ||
my_pipe_stack += tree_qua_branch | ||
my_pipe_stack += svm_mima_branch | ||
my_pipe_stack += knn_sta_branch | ||
|
||
my_pipe += my_pipe_stack | ||
|
||
my_pipe += PipelineElement('LogisticRegression', solver='lbfgs') | ||
|
||
my_pipe.fit(X, y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters