Mercurial > repos > bgruening > sklearn_feature_selection
comparison feature_selection.xml @ 3:3a1acc39b39b draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 4ed8c4f6ef9ece81797a398b17a99bbaf49a6978
author | bgruening |
---|---|
date | Wed, 30 May 2018 08:25:49 -0400 |
parents | 2eb90e73f0d5 |
children | 44e26f8a82c6 |
comparison
equal
deleted
inserted
replaced
2:2eb90e73f0d5 | 3:3a1acc39b39b |
---|---|
23 import sklearn.feature_selection | 23 import sklearn.feature_selection |
24 from sklearn import svm, linear_model, ensemble | 24 from sklearn import svm, linear_model, ensemble |
25 | 25 |
26 @COLUMNS_FUNCTION@ | 26 @COLUMNS_FUNCTION@ |
27 | 27 |
28 @FEATURE_SELECTOR_FUNCTION@ | |
29 | |
28 input_json_path = sys.argv[1] | 30 input_json_path = sys.argv[1] |
29 params = json.load(open(input_json_path, "r")) | 31 params = json.load(open(input_json_path, "r")) |
30 | 32 |
31 ## Read features | 33 ## Read features |
32 features_has_header = params["input_options"]["header1"] | 34 features_has_header = params["input_options"]["header1"] |
55 parse_dates=True | 57 parse_dates=True |
56 ) | 58 ) |
57 y=y.ravel() | 59 y=y.ravel() |
58 | 60 |
59 ## Create feature selector | 61 ## Create feature selector |
60 selector = params["feature_selection_algorithms"]["selected_algorithm"] | 62 new_selector = feature_selector(params['feature_selection_algorithms']) |
61 selector = getattr(sklearn.feature_selection, selector) | 63 if params['feature_selection_algorithms']['selected_algorithm'] != 'SelectFromModel' or \ |
62 options = params["feature_selection_algorithms"]["options"] | 64 'extra_estimator' not in params['feature_selection_algorithms'] or \ |
63 | 65 params['feature_selection_algorithms']['extra_estimator']['has_estimator'] != 'no_load' : |
64 if params['feature_selection_algorithms']['selected_algorithm'] == 'SelectFromModel': | |
65 if not options['threshold'] or options['threshold'] == 'None': | |
66 options['threshold'] = None | |
67 if 'extra_estimator' in params['feature_selection_algorithms'] and params['feature_selection_algorithms']['extra_estimator']['has_estimator'] == 'no_load': | |
68 fitted_estimator = pickle.load(open("params['feature_selection_algorithms']['extra_estimator']['fitted_estimator']", 'r')) | |
69 new_selector = selector(fitted_estimator, prefit=True, **options) | |
70 else: | |
71 estimator=params["feature_selection_algorithms"]["estimator"] | |
72 if params["feature_selection_algorithms"]["extra_estimator"]["has_estimator"]=='no': | |
73 estimator=params["feature_selection_algorithms"]["extra_estimator"]["new_estimator"] | |
74 estimator=eval(estimator.replace('__dq__', '"').replace("__sq__","'")) | |
75 new_selector = selector(estimator, **options) | |
76 new_selector.fit(X, y) | |
77 | |
78 elif params['feature_selection_algorithms']['selected_algorithm'] in ['RFE', 'RFECV']: | |
79 if 'scoring' in options and (not options['scoring'] or options['scoring'] == 'None'): | |
80 options['scoring'] = None | |
81 estimator=params["feature_selection_algorithms"]["estimator"] | |
82 if params["feature_selection_algorithms"]["extra_estimator"]["has_estimator"]=='no': | |
83 estimator=params["feature_selection_algorithms"]["extra_estimator"]["new_estimator"] | |
84 estimator=eval(estimator.replace('__dq__', '"').replace("__sq__","'")) | |
85 new_selector = selector(estimator, **options) | |
86 new_selector.fit(X, y) | |
87 | |
88 elif params['feature_selection_algorithms']['selected_algorithm'] == "VarianceThreshold": | |
89 new_selector = selector(**options) | |
90 new_selector.fit(X, y) | |
91 | |
92 else: | |
93 score_func = params["feature_selection_algorithms"]["score_func"] | |
94 score_func = getattr(sklearn.feature_selection, score_func) | |
95 new_selector = selector(score_func, **options) | |
96 new_selector.fit(X, y) | 66 new_selector.fit(X, y) |
97 | 67 |
98 ## Transform to select features | 68 ## Transform to select features |
99 selected_names = None | 69 selected_names = None |
100 if "$select_methods.selected_method" == "fit_transform": | 70 if "$select_methods.selected_method" == "fit_transform": |