Explorar el Código

Remove of rfe method (move to another git repo)

Jérôme BUISINE hace 5 años
padre
commit
d5683567d5

+ 1 - 1
custom_config.py

@@ -16,7 +16,7 @@ optimization_filters_result_filename    = 'optimization_comparisons_filters.csv'
 optimization_attributes_result_filename = 'optimization_comparisons_attributes.csv'
 
 filter_reduction_choices                = ['attributes', 'filters']
-models_names_list                       = ["svm_model","ensemble_model","ensemble_model_v2","deep_keras","rfe_svm_model"]
+models_names_list                       = ["svm_model","ensemble_model","ensemble_model_v2","deep_keras"]
 
 ## models_names_list               = ["svm_model","ensemble_model","ensemble_model_v2","deep_keras"]
 ## normalization_choices           = ['svd', 'svdn', 'svdne']

+ 1 - 19
models.py

@@ -63,21 +63,6 @@ def ensemble_model_v2(X_train, y_train):
 
     return ensemble_model
 
-def rfe_svm_model(X_train, y_train, n_components=1):
-
-    # Cs = [0.001, 0.01, 0.1, 1, 10, 100, 1000]
-    # gammas = [0.001, 0.01, 0.1, 1, 5, 10, 100]
-    # param_grid = [{'estimator__C': Cs, 'estimator__gamma' : gammas}]
-
-    gammas = [0.001, 0.01, 0.1]
-    param_grid = [{'estimator__gamma' : gammas}]
-
-    estimator = svm.SVC(kernel="linear")
-    selector = RFECV(estimator, step=1, cv=4, verbose=0)
-    clf = GridSearchCV(selector, param_grid, cv=5, verbose=1)
-    clf.fit(X_train, y_train)
-
-    return (clf.best_estimator_, clf.best_estimator_.support_)
 
 
 def get_trained_model(choice, X_train, y_train):
@@ -89,7 +74,4 @@ def get_trained_model(choice, X_train, y_train):
         return ensemble_model(X_train, y_train)
 
     if choice == 'ensemble_model_v2':
-        return ensemble_model_v2(X_train, y_train)
-
-    if choice == 'rfe_svm_model':
-        return rfe_svm_model(X_train, y_train)
+        return ensemble_model_v2(X_train, y_train)

+ 7 - 7
prediction/predict_noisy_image_svd.py

@@ -52,14 +52,14 @@ def main():
         kind_model = 'keras'
 
     if 'corr' in p_model_file:
-        corr_model = True
+        indices_model = True
 
         indices_corr_path = os.path.join(cfg.correlation_indices_folder, p_model_file.split('/')[1].replace('.json', '').replace('.joblib', '') + '.csv')
 
         with open(indices_corr_path, 'r') as f:
-            data_corr_indices = [int(x) for x in f.readline().split(';') if x != '']
+            selected_indices = [int(x) for x in f.readline().split(';') if x != '']
     else:
-        corr_model = False
+        indices_model = False
 
 
     if kind_model == 'sklearn':
@@ -87,8 +87,8 @@ def main():
     # check if custom min max file is used
     if p_custom:
 
-        if corr_model:
-            test_data = data[data_corr_indices]
+        if indices_model:
+            test_data = data[selected_indices]
         else:
             test_data = data[begin:end]
 
@@ -127,8 +127,8 @@ def main():
         else:
             l_values = data
 
-        if corr_model:
-            test_data = data[data_corr_indices]
+        if indices_model:
+            test_data = data[selected_indices]
         else:
             test_data = data[begin:end]
 

+ 1 - 5
prediction/predict_seuil_expe_curve_opti_scene.py

@@ -144,10 +144,6 @@ def main():
 
                 print(str(id_block) + " : " + str(current_quality_image) + "/" + str(threshold_expes[id_block]) + " => " + str(prediction))
 
-        print("------------------------")
-        print("Scene " + str(id_scene + 1) + "/" + str(len(scenes)))
-        print("------------------------")
-
     # end of scene => display of results
 
     # construct path using model name for saving threshold map folder
@@ -157,7 +153,7 @@ def main():
     if not os.path.exists(model_threshold_path):
         os.makedirs(model_threshold_path)
 
-    map_filename = os.path.join(model_threshold_path, simulation_curves_zones + folder_scene)
+    map_filename = os.path.join(model_threshold_path, simulation_curves_zones + scene_name)
     f_map = open(map_filename, 'w')
 
     for line in block_predictions_str:

+ 1 - 6
prediction/predict_seuil_expe_curve_scene.py

@@ -142,11 +142,6 @@ def main():
 
                 print(str(id_block) + " : " + str(current_quality_image) + "/" + str(threshold_expes[id_block]) + " => " + str(prediction))
 
-        print("------------------------")
-        print("Scene " + str(id_scene + 1) + "/" + str(len(scenes)))
-        print("------------------------")
-
-    # end of scene => display of results
 
     # construct path using model name for saving threshold map folder
     model_threshold_path = os.path.join(threshold_map_folder, p_model_file.split('/')[-1].replace('.joblib', ''))
@@ -155,7 +150,7 @@ def main():
     if not os.path.exists(model_threshold_path):
         os.makedirs(model_threshold_path)
 
-    map_filename = os.path.join(model_threshold_path, simulation_curves_zones + folder_scene)
+    map_filename = os.path.join(model_threshold_path, simulation_curves_zones + scene_name)
     f_map = open(map_filename, 'w')
 
     for line in block_predictions_str:

+ 2 - 9
train_model.py

@@ -88,11 +88,8 @@ def main():
 
     print("-------------------------------------------")
     print("Train dataset size: ", final_df_train_size)
-    if p_choice == 'rfe_svm_model': 
-        model, indices = mdl.get_trained_model(p_choice, x_dataset_train, y_dataset_train)
-        selected_indices = [(i+1) for i in np.arange(len(indices)) if indices[i] == True]
-    else:
-        model = mdl.get_trained_model(p_choice, x_dataset_train, y_dataset_train)
+
+    model = mdl.get_trained_model(p_choice, x_dataset_train, y_dataset_train)
 
     #######################
     # 3. Fit model : use of cross validation to fit model
@@ -116,10 +113,6 @@ def main():
 
     X_test, X_val, y_test, y_val = train_test_split(x_dataset_test, y_dataset_test, test_size=0.5, random_state=1)
 
-    if p_choice == 'rfe_svm_model': 
-        X_test = X_test.loc[:, selected_indices]
-        X_val = X_val.loc[:, selected_indices]
-
     y_test_model = model.predict(X_test)
     y_val_model = model.predict(X_val)