4. Parameter files Flashcards
1
Q
How can you add parameter files to your model?
A
- You can simply drag and drop into the appropriate folder or right-click on the folder and select Upload Files
- They can be JSON or CSV, although json files are faster.
- Create a subfolder inside the algorithms folder and name it json_parameter_files. CSV files go into the parameter_tables folder
- The files are separated like this due to how hx Renew is structured. For a file to be accessed from within rating.py, it must be located inside the ‘algorithms’ folder. Except csv files that are located in the parameter_tables folder, where the ‘hx.params’ function can be used to extract them.
2
Q
What is the layout of the json parameter file?
A
- The JSON files are composed of key:value pairs, similar to how the example data is structured. For example
{
“Manufacturing”: 0.16,
“Distributing”: 0.02
}
3
Q
What is the layout of the csv parameter file?
A
- The top row contains your column headers, separated by commas.
- Again, you cannot have spaces in your column headers and should always use lower case.
- Your header names will be how you access the data in that column, either in the data schema or in your rating algorithm.
- Your data for each column then follows underneath. For example:
- size_gte,adjustment
0,0.2
7,14
4
Q
How do you access parameter data?
A
- first extract it from the JSON or CSV files. This allows other files (like view.js and rating.py) to retrieve this data.
- For the JSON file, we will load them into the data schema using the get_parameters function. Put from algorithms.json_parameter_files.parameters import get_parameters into the data schema.
- The get_parameters function should sit inside the json_parameter_files folder that you created earlier. It is a hx-built function, and you are able to copy and paste the code below:
import os
import json
-Function takes the file name as an argument
def get_parameters(file_name):
# Get the path to the parent directory parent_dir = os.path.dirname(\_\_file\_\_) # Get the path to the specific file by joining the parent directory with the file name file_path = os.path.join(parent_dir, file_name) # Return the json from the parameter file with open(file_path) as f: parameter_json = json.load(f) return parameter_json
5
Q
How do you define parameters from a csv?
A
- Open parameter_tables_schema.json
- “csv_table_name”:{
“column_name”:”column_type”
}