1
+ # -------------------- GENERATED WITH PHOTON WIZARD (beta) ------------------------------
2
+ # PHOTON Project Folder: C:/Users/j_boeh06/Sciebo/Forschung/PythonProjects/multimodal_ER
3
+
4
+
5
+ import pandas as pd
6
+ import numpy as np
7
+ from photonai .base import Hyperpipe , PipelineElement , OutputSettings , Switch , Preprocessing
8
+ from photonai .optimization import Categorical , IntegerRange , FloatRange
9
+ from sklearn .model_selection import RepeatedKFold , KFold
10
+
11
+ # Specify how results are going to be saved
12
+ # Define hyperpipe
13
+ hyperpipe = Hyperpipe ('defaultpipelinemultimodaler' ,
14
+ project_folder = "C:/Users/j_boeh06/Sciebo/Forschung/PythonProjects/multimodal_ER" ,
15
+ optimizer = "grid_search" ,
16
+ optimizer_params = {},
17
+ metrics = ['mean_squared_error' , 'mean_absolute_error' , 'explained_variance' , 'pearson_correlation' ,
18
+ 'r2' ],
19
+ best_config_metric = "mean_squared_error" ,
20
+ outer_cv = RepeatedKFold (n_splits = 10 , random_state = 42 , n_repeats = 10 ),
21
+ inner_cv = KFold (n_splits = 10 , shuffle = True , random_state = 42 ),
22
+ verbosity = 1 )
23
+
24
+ # Add Simple Imputer to impute missing
25
+ hyperpipe += PipelineElement ("SimpleImputer" )
26
+
27
+ # Add preprocessing: Robust Scaler
28
+ hyperpipe += PipelineElement ("RobustScaler" , hyperparameters = {},
29
+ test_disabled = False , with_centering = True , with_scaling = True )
30
+
31
+ # Add feature engineering via Switch
32
+ # Tests three options PCA, off (when PCA disabled = true) and FSelect
33
+ transformer_switch = Switch ('TransformerSwitch' )
34
+ transformer_switch += PipelineElement ("PCA" , hyperparameters = {'n_components' :None },
35
+ test_disabled = True )
36
+ transformer_switch += PipelineElement ("FRegressionSelectPercentile" , hyperparameters = {'percentile' : [5 , 10 , 50 ]},
37
+ test_disabled = False )
38
+ hyperpipe += transformer_switch
39
+
40
+ # Add estimator
41
+ # Defaults as defined in the model zoo default parameters: https://github.com/wwu-mmll/photonai/blob/main/photonai/base/model_zoo.py
42
+ estimator_switch = Switch ('EstimatorSwitch' )
43
+ # I could save some time here by removing 1e-8 (0.00000001) and 1e8 (100,000,000) without losing too much
44
+ estimator_switch += PipelineElement ("SVR" , hyperparameters = {'C' : [1e-8 , 1e-6 , 1e-4 , 1e-2 , 1 , 1e2 , 1e4 , 1e6 , 1e8 ], 'kernel' : ['linear' , 'rbf' ]},
45
+ max_iter = 1000 )
46
+ estimator_switch += PipelineElement ("RandomForestRegressor" , hyperparameters = {'max_features' : ['sqrt' , 'log2' ],
47
+ 'min_samples_leaf' : [0.01 , 0.1 , 0.2 ]})
48
+ hyperpipe += estimator_switch
49
+
50
+ # Load data
51
+ # Adjust this to the modality and its data sheet!
52
+ df = pd .read_excel ('C:/Users/j_boeh06/Sciebo/Forschung/PythonProjects/multimodal_ER/features.xlsx' )
53
+ X = np .asarray (df .iloc [:, 1 :100 ])
54
+ y = np .asarray (df .iloc [:, 0 ])
55
+
56
+ # Fit hyperpipe
57
+ hyperpipe .fit (X , y )
58
+
59
+ # Feature Importances
60
+ r = hyperpipe .get_permutation_feature_importances (n_repeats = 50 , random_state = 0 )
61
+ print (r )
62
+
63
+ for i in r ["mean" ].argsort ()[::- 1 ]:
64
+ if r ["mean" ][i ] - 2 * r ["std" ][i ] > 0 :
65
+ # Hier Anpassungen von mir: Bezug auf df, Schreiben der entsprechenden Spalten-Header vor die Durchschnitts- und SD-Werte
66
+ print (f"{ df .columns [i ]:<8} : "
67
+ f"{ r ['mean' ][i ]:.3f} "
68
+ f" +/- { r ['std' ][i ]:.3f} " )
69
+
70
+ # Schreiben der Feature Importances in eine CSV-Datei
71
+ feature_importance = pd .DataFrame (r )
72
+ r .to_csv ('feature_importances.csv' )
0 commit comments