MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / save_predictions

Function save_predictions

alphapy/model.py:1157–1250  ·  view source on GitHub ↗

r"""Save the predictions to disk. Parameters ---------- model : alphapy.Model The model object to save. tag : str A unique identifier for the output files, e.g., a date stamp. partition : alphapy.Partition Reference to the dataset. Returns ------

(model, tag, partition)

Source from the content-addressed store, hash-verified

1155#
1156
1157def save_predictions(model, tag, partition):
1158 r"""Save the predictions to disk.
1159
1160 Parameters
1161 ----------
1162 model : alphapy.Model
1163 The model object to save.
1164 tag : str
1165 A unique identifier for the output files, e.g., a date stamp.
1166 partition : alphapy.Partition
1167 Reference to the dataset.
1168
1169 Returns
1170 -------
1171 preds : numpy array
1172 The prediction vector.
1173 probas : numpy array
1174 The probability vector.
1175
1176 """
1177
1178 # Extract model parameters.
1179
1180 directory = model.specs['directory']
1181 extension = model.specs['extension']
1182 model_type = model.specs['model_type']
1183 separator = model.specs['separator']
1184
1185 # Get date stamp to record file creation
1186 timestamp = get_datestamp()
1187
1188 # Specify input and output directories
1189
1190 input_dir = SSEP.join([directory, 'input'])
1191 output_dir = SSEP.join([directory, 'output'])
1192
1193 # Read the prediction frame
1194 file_spec = ''.join([datasets[partition], '*'])
1195 file_name = most_recent_file(input_dir, file_spec)
1196 file_name = file_name.split(SSEP)[-1].split(PSEP)[0]
1197 pf = read_frame(input_dir, file_name, extension, separator)
1198
1199 # Cull records before the prediction date
1200
1201 try:
1202 predict_date = model.specs['predict_date']
1203 found_pdate = True
1204 except:
1205 found_pdate = False
1206
1207 if found_pdate:
1208 pd_indices = pf[pf.date >= predict_date].index.tolist()
1209 pf = pf.iloc[pd_indices]
1210 else:
1211 pd_indices = pf.index.tolist()
1212
1213 # Save predictions for all projects
1214

Callers 2

prediction_pipelineFunction · 0.90
save_modelFunction · 0.85

Calls 4

get_datestampFunction · 0.90
most_recent_fileFunction · 0.90
read_frameFunction · 0.90
write_frameFunction · 0.90

Tested by

no test coverage detected