comparison fitted_model_eval.py @ 10:9b6faa256f15 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
author bgruening
date Sat, 01 May 2021 01:12:10 +0000
parents e3b420d0b71a
children 624e2afa1313
comparison
equal deleted inserted replaced
9:e3b420d0b71a 10:9b6faa256f15
28 28
29 input_type = params["input_options"]["selected_input"] 29 input_type = params["input_options"]["selected_input"]
30 # tabular input 30 # tabular input
31 if input_type == "tabular": 31 if input_type == "tabular":
32 header = "infer" if params["input_options"]["header1"] else None 32 header = "infer" if params["input_options"]["header1"] else None
33 column_option = params["input_options"]["column_selector_options_1"]["selected_column_selector_option"] 33 column_option = params["input_options"]["column_selector_options_1"][
34 "selected_column_selector_option"
35 ]
34 if column_option in [ 36 if column_option in [
35 "by_index_number", 37 "by_index_number",
36 "all_but_by_index_number", 38 "all_but_by_index_number",
37 "by_header_name", 39 "by_header_name",
38 "all_but_by_header_name", 40 "all_but_by_header_name",
50 elif input_type == "sparse": 52 elif input_type == "sparse":
51 X = mmread(open(infile1, "r")) 53 X = mmread(open(infile1, "r"))
52 54
53 # Get target y 55 # Get target y
54 header = "infer" if params["input_options"]["header2"] else None 56 header = "infer" if params["input_options"]["header2"] else None
55 column_option = params["input_options"]["column_selector_options_2"]["selected_column_selector_option2"] 57 column_option = params["input_options"]["column_selector_options_2"][
58 "selected_column_selector_option2"
59 ]
56 if column_option in [ 60 if column_option in [
57 "by_index_number", 61 "by_index_number",
58 "all_but_by_index_number", 62 "all_but_by_index_number",
59 "by_header_name", 63 "by_header_name",
60 "all_but_by_header_name", 64 "all_but_by_header_name",
68 infile2 = loaded_df[df_key] 72 infile2 = loaded_df[df_key]
69 else: 73 else:
70 infile2 = pd.read_csv(infile2, sep="\t", header=header, parse_dates=True) 74 infile2 = pd.read_csv(infile2, sep="\t", header=header, parse_dates=True)
71 loaded_df[df_key] = infile2 75 loaded_df[df_key] = infile2
72 76
73 y = read_columns(infile2, c=c, c_option=column_option, sep="\t", header=header, parse_dates=True) 77 y = read_columns(
78 infile2, c=c, c_option=column_option, sep="\t", header=header, parse_dates=True
79 )
74 if len(y.shape) == 2 and y.shape[1] == 1: 80 if len(y.shape) == 2 and y.shape[1] == 1:
75 y = y.ravel() 81 y = y.ravel()
76 82
77 return X, y 83 return X, y
78 84
121 if isinstance(estimator, Pipeline): 127 if isinstance(estimator, Pipeline):
122 main_est = estimator.steps[-1][-1] 128 main_est = estimator.steps[-1][-1]
123 if hasattr(main_est, "config") and hasattr(main_est, "load_weights"): 129 if hasattr(main_est, "config") and hasattr(main_est, "load_weights"):
124 if not infile_weights or infile_weights == "None": 130 if not infile_weights or infile_weights == "None":
125 raise ValueError( 131 raise ValueError(
126 "The selected model skeleton asks for weights, " "but no dataset for weights was provided!" 132 "The selected model skeleton asks for weights, "
133 "but no dataset for weights was provided!"
127 ) 134 )
128 main_est.load_weights(infile_weights) 135 main_est.load_weights(infile_weights)
129 136
130 # handle scorer, convert to scorer dict 137 # handle scorer, convert to scorer dict
131 # Check if scoring is specified 138 # Check if scoring is specified
140 147
141 scorer = get_scoring(scoring) 148 scorer = get_scoring(scoring)
142 scorer, _ = _check_multimetric_scoring(estimator, scoring=scorer) 149 scorer, _ = _check_multimetric_scoring(estimator, scoring=scorer)
143 150
144 if hasattr(estimator, "evaluate"): 151 if hasattr(estimator, "evaluate"):
145 scores = estimator.evaluate(X_test, y_test=y_test, scorer=scorer, is_multimetric=True) 152 scores = estimator.evaluate(
153 X_test, y_test=y_test, scorer=scorer, is_multimetric=True
154 )
146 else: 155 else:
147 scores = _score(estimator, X_test, y_test, scorer, is_multimetric=True) 156 scores = _score(estimator, X_test, y_test, scorer, is_multimetric=True)
148 157
149 # handle output 158 # handle output
150 for name, score in scores.items(): 159 for name, score in scores.items():