Changing Project Parameters
Before training a Classifier we often times want to change the type of classifier and other parameters.
On project creation the classifier object is initalized with default values. Depending on our needs we want to change those parameter to more fitting values.
At first we need to point python to the program folder. The path can be assigned as a relative path as shown below, or as an absolute system path. Than the module can be imported via the import cloud_classifier command.
[1]:
import sys
import ctypytool
Project creation
Let’s first create a new project. This time we want to train a Decison Tree classifier and choose a name for our project accordingly.
[2]:
cc = ctypytool.cloud_classifier()
cc.create_new_project(name="NewDecisionTreeClassifier", path="../classifiers")
Project folder created successfully!
The new classifier will automatically be initalized with default parameters. Iinside of the project folder folder a new folder called settings was created, containing the files config.json, holding information about the type and parameters of classifier we want to use and the file data_structure.json, holding information about the structure of our used data files.
[3]:
%%bash
cat ../classifiers/NewDecisionTreeClassifier/settings/config.json
cat ../classifiers/NewDecisionTreeClassifier/settings/data_structure.json
{
"classifier_type": "Forest",
"max_depth": 35,
"ccp_alpha": 0,
"n_estimators": 100,
"max_features": null,
"min_samples_split" : 2,
"merge_list" : [],
"difference_vectors": true,
"original_values": true,
"samples": 100
}
{
"data_source_folder": "../data/full_dataset",
"timestamp_length": 13,
"sat_file_structure": "msevi-medi-TIMESTAMP.nc",
"label_file_structure": "nwcsaf_msevi-medi-TIMESTAMP.nc",
"input_source_folder": "../data/example_data",
"georef_file" : "../data/auxilary_files/msevi-medi-georef.nc" ,
"mask_file" : "../data/auxilary_files/lsm_mask_medi.nc",
"mask_key": "land_sea_mask",
"mask_sea_coding": 0,
"input_channels": [
"bt062",
"bt073",
"bt087",
"bt097",
"bt108",
"bt120",
"bt134"
],
"cloudtype_channel": "ct",
"nwcsaf_in_version": "auto",
"nwcsaf_out_version": "v2018",
"hours": [
0
]
}
Changing Classifier Type
We can now use the command set_project_parameters in order to change any parameter. For changing the classifier to a Decision Tree, we change the first parameter of the file config.json, which carries the name classifier_type to "Tree".
[4]:
cc.set_project_parameters(classifier_type="Tree")
When we check out the file again, we can see that the corresponding parameter has changed.
[5]:
%%bash
cat ../classifiers/NewDecisionTreeClassifier/settings/config.json
{
"classifier_type": "Tree",
"max_depth": 35,
"ccp_alpha": 0,
"n_estimators": 100,
"max_features": null,
"min_samples_split": 2,
"merge_list": [],
"difference_vectors": true,
"original_values": true,
"samples": 100
}
Changing Input Channels
As an additional example we will change the input channels we use from the satelite data files. First we can access the list of input channels using our classifier object.
[6]:
changed_input_channels = cc.params["input_channels"]
print(changed_input_channels)
['bt062', 'bt073', 'bt087', 'bt097', 'bt108', 'bt120', 'bt134']
Then we can change the list, for example by removing the entry 'bt134'. Alternativly we could also add channels, if we knew, that our satelite data contained those additional channels and wanted to use them, or create a completely new list, if the data structure was different than in our example. The command set_project_parameters again can be used to then write the changed list to our project.
[7]:
changed_input_channels.remove("bt134")
print(changed_input_channels)
cc.set_project_parameters(input_channels=changed_input_channels)
['bt062', 'bt073', 'bt087', 'bt097', 'bt108', 'bt120']
[8]:
%%bash
cat ../classifiers/NewDecisionTreeClassifier/settings/data_structure.json
{
"data_source_folder": "../data/full_dataset",
"timestamp_length": 13,
"sat_file_structure": "msevi-medi-TIMESTAMP.nc",
"label_file_structure": "nwcsaf_msevi-medi-TIMESTAMP.nc",
"input_source_folder": "../data/example_data",
"georef_file": "../data/auxilary_files/msevi-medi-georef.nc",
"mask_file": "../data/auxilary_files/lsm_mask_medi.nc",
"mask_key": "land_sea_mask",
"mask_sea_coding": 0,
"input_channels": [
"bt062",
"bt073",
"bt087",
"bt097",
"bt108",
"bt120"
],
"cloudtype_channel": "ct",
"nwcsaf_in_version": "auto",
"nwcsaf_out_version": "v2018",
"hours": [
0
]
}
Alternativly all parameters can be changed directly in the specified parameter files. The classifier needs to be loaded again after doing so, in order to be able to apply the changed parameters.