@@ -128,7 +128,7 @@ Samples
128128
129129 # Set the file paths
130130 dictionary_file_path = os.path.join(kh.get_samples_dir(), " Adult" , " Adult.kdic" )
131- output_dir = os.path.join(" kh_samples" , " export_dictionary_file " )
131+ output_dir = os.path.join(" kh_samples" , " export_dictionary_files " )
132132 output_dictionary_file_path = os.path.join(output_dir, " ModifiedAdult.kdic" )
133133 output_dictionary_json_path = os.path.join(output_dir, " ModifiedAdult.kdicj" )
134134 alt_output_dictionary_json_path = os.path.join(output_dir, " AltModifiedAdult.kdicj" )
@@ -686,6 +686,37 @@ Samples
686686 kh.interpret_predictor(predictor_file_path, " SNB_Adult" , interpretor_file_path)
687687
688688 print (f " The interpretation model is ' { interpretor_file_path} ' " )
689+ .. autofunction :: reinforce_predictor
690+ .. code-block :: python
691+
692+ # Imports
693+ import os
694+ from khiops import core as kh
695+
696+ dictionary_file_path = os.path.join(kh.get_samples_dir(), " Adult" , " Adult.kdic" )
697+ data_table_path = os.path.join(kh.get_samples_dir(), " Adult" , " Adult.txt" )
698+ output_dir = os.path.join(" kh_samples" , " reinforce_predictor" )
699+ analysis_report_file_path = os.path.join(output_dir, " AnalysisResults.khj" )
700+ reinforced_predictor_file_path = os.path.join(output_dir, " ReinforcedAdultModel.kdic" )
701+
702+ # Build prediction model
703+ _, predictor_file_path = kh.train_predictor(
704+ dictionary_file_path,
705+ " Adult" ,
706+ data_table_path,
707+ " class" ,
708+ analysis_report_file_path,
709+ )
710+
711+ # Build reinforced predictor
712+ kh.reinforce_predictor(
713+ predictor_file_path,
714+ " SNB_Adult" ,
715+ reinforced_predictor_file_path,
716+ reinforcement_lever_variables = [" occupation" ],
717+ )
718+
719+ print (f " The reinforced predictor is ' { reinforced_predictor_file_path} ' " )
689720 .. autofunction :: multiple_train_predictor
690721.. code-block :: python
691722
@@ -1064,7 +1095,7 @@ Samples
10641095 dictionary_file_path = os.path.join(accidents_dir, " Accidents.kdic" )
10651096 accidents_table_path = os.path.join(accidents_dir, " Accidents.txt" )
10661097 vehicles_table_path = os.path.join(accidents_dir, " Vehicles.txt" )
1067- output_dir = os.path.join(" kh_samples" , " deploy_model_mt " )
1098+ output_dir = os.path.join(" kh_samples" , " deploy_model_mt_with_interpretation " )
10681099 report_file_path = os.path.join(output_dir, " AnalysisResults.khj" )
10691100 interpretor_file_path = os.path.join(output_dir, " InterpretationModel.kdic" )
10701101 output_data_table_path = os.path.join(output_dir, " InterpretedAccidents.txt" )
@@ -1088,7 +1119,8 @@ Samples
10881119 model_dictionary_file_path,
10891120 " SNB_Accident" ,
10901121 interpretor_file_path,
1091- reinforcement_target_value = " NonLethal" ,
1122+ max_variable_importances = 3 ,
1123+ importance_ranking = " Individual" ,
10921124 )
10931125
10941126 # Deploy the interpretation model on the database
@@ -1101,6 +1133,53 @@ Samples
11011133 output_data_table_path,
11021134 additional_data_tables = {" Vehicles" : vehicles_table_path},
11031135 )
1136+ .. autofunction :: deploy_reinforced_model_mt
1137+ .. code-block :: python
1138+
1139+ # Imports
1140+ import os
1141+ from khiops import core as kh
1142+
1143+ # Set the file paths
1144+ accidents_dir = os.path.join(kh.get_samples_dir(), " AccidentsSummary" )
1145+ dictionary_file_path = os.path.join(accidents_dir, " Accidents.kdic" )
1146+ accidents_table_path = os.path.join(accidents_dir, " Accidents.txt" )
1147+ vehicles_table_path = os.path.join(accidents_dir, " Vehicles.txt" )
1148+ output_dir = os.path.join(" kh_samples" , " deploy_reinforced_model_mt" )
1149+ report_file_path = os.path.join(output_dir, " AnalysisResults.khj" )
1150+ reinforced_predictor_file_path = os.path.join(output_dir, " ReinforcedModel.kdic" )
1151+ output_data_table_path = os.path.join(output_dir, " ReinforcedAccidents.txt" )
1152+
1153+ # Train the predictor (see train_predictor_mt for details)
1154+ _, model_dictionary_file_path = kh.train_predictor(
1155+ dictionary_file_path,
1156+ " Accident" ,
1157+ accidents_table_path,
1158+ " Gravity" ,
1159+ report_file_path,
1160+ additional_data_tables = {" Vehicles" : vehicles_table_path},
1161+ max_trees = 0 ,
1162+ )
1163+
1164+ # Reinforce the predictor
1165+ kh.reinforce_predictor(
1166+ model_dictionary_file_path,
1167+ " SNB_Accident" ,
1168+ reinforced_predictor_file_path,
1169+ reinforcement_target_value = " NonLethal" ,
1170+ reinforcement_lever_variables = [" InAgglomeration" , " CollisionType" ],
1171+ )
1172+
1173+ # Deploy the reinforced model on the database
1174+ # Besides the mandatory parameters, it is specified:
1175+ # - A python dictionary linking data paths to file paths for non-root tables
1176+ kh.deploy_model(
1177+ reinforced_predictor_file_path,
1178+ " Reinforcement_SNB_Accident" ,
1179+ accidents_table_path,
1180+ output_data_table_path,
1181+ additional_data_tables = {" Vehicles" : vehicles_table_path},
1182+ )
11041183 .. autofunction :: deploy_model_mt_snowflake
11051184.. code-block :: python
11061185
0 commit comments