Reduced Order Models¶
Metamodels¶
-
class
rom.metamodels.
Metamodels
(filename)[source]¶ Bases:
object
-
property
algorithm_options
¶ Return the algorithm options from the metamodels.json file that was passed in.
- Returns
dict, Algorithm options.
-
property
analysis
¶ Return the ROM analysis file.
- Returns
Parsed JSON ROM file.
-
property
analysis_name
¶ Return the analysis name from the metamodels.json file that was passed in.
- Returns
str, Analysis name.
-
available_response_names
(_model_type)[source]¶ Return a list of response names.
- Parameters
_model_type – str, The type of reduced order model (e.g. RandomForest).
- Returns
list, Response names.
-
covariate_names
(model_type)[source]¶ Return a list of covariate names. The order in the JSON file must be the order that is passed into the metamodel, otherwise the data will not make sense.
- Parameters
model_type – str, The type of reduced order model (e.g. RandomForest).
- Returns
list, Covariate names.
-
covariate_types
(model_type)[source]¶ Return dictionary of covariate types.
- Parameters
model_type – str, The type of reduced order model (e.g. RandomForest).
- Returns
dict, {‘type’:[‘covariate name’]}.
-
covariates
(model_type)[source]¶ Return dictionary of covariates for specified model type.
- Parameters
model_type – str, The type of reduced order model (e.g. RandomForest).
- Returns
dict, Covariates.
-
downsamples
(model_name)[source]¶ Return the downsamples list from the metamodels.json file that was passed in.
- Parameters
model_name – str, name of the model to look for down samples
- Returns
list, Downsamples.
-
load_file
(filename)[source]¶ Parse the file that defines the ROMs that have been created.
- Parameters
filename – str, The JSON ROM file path.
-
load_models
(model_type, models_to_load=None, downsample=None, root_path=None)[source]¶ Load in the metamodels/generators.
- Parameters
model_type – str, The type of reduced order model (e.g. RandomForest).
models_to_load – list, Name of responses to load.
downsample – float, The downsample value to load. Defaults to None.
- Returns
dict, Metrics {response, model type, downsample, load time, disk size}.
-
property
loaded_models
¶ Return the list of available keys in the models dictionary.
- Returns
list, Responses.
-
model
(response_name)[source]¶ Return model for specific response.
- Parameters
response_name – str, Name of model response.
-
model_paths
(model_type, response, downsample=None, root_path=None)[source]¶ Return the paths to the model to be loaded. This includes the scaler value if the model requires the data to scale the input.
If the root path is provided, then that path will take precedent over the downsample and no values passed format.
- Parameters
model_type – str, The type of reduced order model (e.g. RandomForest).
response – str, The response (or model) to load (e.g. ETSOutletTemperature).
downsample – float, The downsample value to load. Defaults to None.
root_path – If used, then it is the root path of the models. The models will be in subdirectories for each
of the model_types. :return: list, [model_path, scaler_path].
-
models_exist
(model_type, models_to_load=None, downsample=None, root_path=None)[source]¶ Check if the models exist, if not, then return false.
- Parameters
model_type – str, The type of reduced order model (e.g. RandomForest).
models_to_load – list, Name of responses to load.
downsample – float, The downsample value to load. Defaults to None.
root_path – If used, then it is the root path of the models. The models will be in subdirectories for each
of the model_types. :return: bool
-
classmethod
resolve_algorithm_options
(algorithm_options)[source]¶ Go through the algorithm options that are in the metamodel.json file and run ‘eval’ on the strings. This allows complex strings to exist in the json file that get expanded as necessary.
# TODO: Add an example
- Parameters
algorithm_options – dict, the algorithm options to run eval on
- Returns
-
property
results_file
¶ Path to the results file that is to be processed. This is a CSV file.
- Returns
str, path.
-
save_2d_csvs
(data, first_dimension, file_prepend)[source]¶ Generate 2D (time, first) CSVs based on the model loaded and the two dimensions.
The rows are the datetimes as defined in the data (DataFrame).
- Parameters
data – pandas DataFrame
first_dimension – str, The column heading variable.
file_prepend – str, Special variable to prepend to the file name.
- Returns
None
-
save_3d_csvs
(data, first_dimension, second_dimension, second_dimension_short_name, file_prepend, save_figure=False)[source]¶ Generate 3D (time, first, second) CSVs based on the model loaded and the two dimensions. The second dimension becomes individual files.
The rows are the datetimes as defined in the data (DataFrame)
- Parameters
data – pandas DataFrame
first_dimension – str, The column heading variable.
second_dimension – str, The values that will be reported in the table.
second_dimension_short_name – str, Short display name for second variable (for filename).
file_prepend – str, Special variable to prepend to the file name.
- Returns
None
-
save_csv
(data, csv_name)[source]¶ Save pandas DataFrame in CSV format.
- Parameters
data – pandas DataFrame, Data to be exported.
csv_name – str, Name of the CSV file.
- Returns
-
set_analysis
(moniker)[source]¶ Set the index of the analysis based on the ID or the name of the analysis.
- Parameters
moniker – str, Analysis ID or name.
- Returns
bool
-
property
validation_id
¶ Return the validation ID from the metamodels.json file that was passed in.
- Returns
str, Validation ID.
-
yhat
(response_name, data)[source]¶ Run predict on the selected model (response) with the supplied data.
- Parameters
response_name – str, Name of the model to evaluate.
data – pandas DataFrame, Values to predict on.
- Returns
pandas DataFrame, Predictions.
- Raises
Exception: Model does not have the response.
-
yhats
(data, prepend_name, response_names=None)[source]¶ Run predict on multiple responses with the supplied data and store the results in the supplied DataFrame.
The prepend_name is needed in order to not overwrite the existing data in the dataframe after evaluation. For example, if the response name is HeatingElectricity, the supplied data may already have that field provided; therefore, this method adds the prepend_name to the newly predicted data. If prepend_name is set to ‘abc’, then the new column would be ‘abc_HeatingElectricity’.
- Parameters
data – pandas DataFrame, Values to predict on.
prepend_name – str, Name to prepend to the beginning of each of the response names.
response_names – list, Responses to evaluate. If None, then defaults to all the available_response_names.
- Returns
pandas DataFrame, Original data with added predictions.
-
property