Browse Source

Add of RFE and SVM classifier

Jérôme BUISINE 5 years ago
parent
commit
ebb14c3efc

+ 1 - 0
custom_config.py

@@ -16,6 +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"]
 ## normalization_choices           = ['svd', 'svdn', 'svdne']

+ 4 - 4
data_processing/generateAndTrain_maxwell_custom.sh

@@ -31,7 +31,7 @@ scenes="A, D, G, H"
 start=0
 end=$size
 
-for nb_zones in {4,6,8,10,12}; do
+for nb_zones in {4,6,8,10,11,12}; do
 
     for mode in {"svd","svdn","svdne"}; do
         for model in {"svm_model","ensemble_model","ensemble_model_v2"}; do
@@ -47,11 +47,11 @@ for nb_zones in {4,6,8,10,12}; do
 
                 echo "${MODEL_NAME} results already generated..."
             else
-                python generate/generate_data_model_random_${data}.py --output ${FILENAME} --interval "${start},${end}" --kind ${mode} --feature ${feature} --scenes "${scenes}" --nb_zones "${nb_zones}" --percent 1 --renderer "maxwell" --step 40 --random 1 --custom ${CUSTOM_MIN_MAX_FILENAME}
-                python train_model.py --data ${FILENAME} --output ${MODEL_NAME} --choice ${model}
+                python generate/generate_data_model_random_${data}.py --output ${FILENAME} --interval "${start},${end}" --kind ${mode} --feature ${feature} --scenes "${scenes}" --nb_zones "${nb_zones}" --percent 1 --renderer "maxwell" --step 10 --random 1 --custom ${CUSTOM_MIN_MAX_FILENAME}
+                #python train_model.py --data ${FILENAME} --output ${MODEL_NAME} --choice ${model}
 
                 #python prediction/predict_seuil_expe_maxwell.py --interval "${start},${end}" --model "saved_models/${MODEL_NAME}.joblib" --mode "${mode}" --feature ${feature} --limit_detection '2' --custom ${CUSTOM_MIN_MAX_FILENAME}
-                python others/save_model_result_in_md_maxwell.py --interval "${start},${end}" --model "saved_models/${MODEL_NAME}.joblib" --mode "${mode}" --feature ${feature}
+                #python others/save_model_result_in_md_maxwell.py --interval "${start},${end}" --model "saved_models/${MODEL_NAME}.joblib" --mode "${mode}" --feature ${feature}
             fi
         done
     done

+ 1 - 1
data_processing/generateAndTrain_maxwell_custom_optimization.sh

@@ -61,7 +61,7 @@ for nb_zones in {10,12}; do
                 python generate/generate_data_model_random_${data}.py --output ${FILENAME} --interval "${start},${end}" --kind ${mode} --feature ${feature} --scenes "${scenes}" --nb_zones "${nb_zones}" --percent 1 --renderer "maxwell" --step 40 --random 1 --custom ${CUSTOM_MIN_MAX_FILENAME}
                 
                 echo "Train ${MODEL_NAME}"
-                python find_best_${filter}.py --data ${FILENAME} --choice ${model} &
+                #python find_best_${filter}.py --data ${FILENAME} --choice ${model} &
             fi
         done
     done

+ 1 - 1
display/display_reconstructed_image_from_simulation.py

@@ -75,7 +75,7 @@ def reconstruct_image(folder_path, model_name, p_limit):
 
             row = np.asarray(row)
 
-            threshold = row[2]
+            #threshold = row[2]
             start_index = row[3]
             step_value = row[4]
             rendering_predictions = row[5:]

+ 30 - 1
models.py

@@ -4,6 +4,7 @@ from sklearn.linear_model import LogisticRegression
 from sklearn.ensemble import RandomForestClassifier, VotingClassifier
 from sklearn.neighbors import KNeighborsClassifier
 from sklearn.ensemble import GradientBoostingClassifier
+from sklearn.feature_selection import RFECV
 import sklearn.svm as svm
 
 
@@ -62,6 +63,31 @@ 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__kernel':['rbf'], 'estimator__C': Cs, 'estimator__gamma' : gammas}
+
+    svc = svm.SVC(probability=True)
+
+    rfe_model = RFECV(svc, step=1, cv=10, verbose=0)
+
+    clf = GridSearchCV(rfe_model, param_grid, cv=10, scoring='accuracy', verbose=1)
+
+    clf.fit(X_train, y_train)
+
+    print(clf.best_estimator_)
+    print('------------------------------')
+    print(clf.best_estimator_.n_features_)
+    print('------------------------------')
+    print(clf.best_estimator_.ranking_)
+    print('------------------------------')
+    print(clf.best_estimator_.grid_scores_)
+
+    return clf.best_estimator_.estimator_
+
+
 def get_trained_model(choice, X_train, y_train):
 
     if choice == 'svm_model':
@@ -71,4 +97,7 @@ 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)
+        return ensemble_model_v2(X_train, y_train)
+
+    if choice == 'rfe_svm_model':
+        return rfe_svm_model(X_train, y_train)