diff --git a/README.md b/README.md index 499cc73047f58096bc46ba407cec3cad3f54ad17..a2e97e1307f5c3845c1477d7c6c1391ecb1674b1 100755 --- a/README.md +++ b/README.md @@ -31,7 +31,11 @@ Next, to install the database, run the MongoDB server and execute this command ( ./mongorestore --archive=/path/to/dump-iris.bin ``` -where `/path/to/` is the path to the dump file of the IRIS collection (provided with the package mongiris in `mongiris/data/dump-iris.bin`). +where `/path/to/` is the path to the dump file of the IRIS collection (provided with the package mongiris in `mongiris/data/dump-iris.bin`). +You may have to create two folders for Mongodb: `data/db` under `PATH/TO/MONGODB/bin`. A tip is to move the dump into that folder and use the hollowing steps: + +1. In a first terminal: `./mongod --dbpath=./data/db` (to run mongodb), +2. In a second terminal: `./mongorestore --archive=./data/db/dump-dbinsee.bin` (to restore data from the dump). ### Run Predihood diff --git a/predihood/__init__.py b/predihood/__init__.py index b22478b7c702aba8e96c2a06009250a37cb23920..b85fb43366971f6c9024513fa238df2f7c2a8cc4 100644 --- a/predihood/__init__.py +++ b/predihood/__init__.py @@ -1,4 +1,3 @@ import logging -import sys logging.basicConfig(level=logging.DEBUG) \ No newline at end of file diff --git a/predihood/classifiers_list.py b/predihood/classifiers_list.py index d1971991e9d133645ec23814659961ce73a88d9d..052708daac65dbc5ac5e3b7960d4049f63281431 100644 --- a/predihood/classifiers_list.py +++ b/predihood/classifiers_list.py @@ -1,7 +1,6 @@ # define available classifiers for the algorithmic interface import os import re -import sys from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier from sklearn.neighbors import KNeighborsClassifier @@ -12,7 +11,7 @@ from sklearn.tree import DecisionTreeClassifier import importlib tree = os.listdir('algorithms') regex = re.compile(r'__[^_]*__') -tree_filtered = [i for i in tree if not regex.match(i)] # remove undesirable files such as __pycache__ +tree_filtered = [i for i in tree if not regex.match(i)] # remove undesirable files such as __pycache__ AVAILABLE_CLASSIFIERS = { "Random Forest Classifier": RandomForestClassifier, diff --git a/predihood/static/js/carto.js b/predihood/static/js/carto.js index b13931a0b8d47885a6831748d74763b4f2243c0e..df7e98ae0edf57705b12806ce1370f44e605686f 100644 --- a/predihood/static/js/carto.js +++ b/predihood/static/js/carto.js @@ -104,87 +104,34 @@ function displayPopup(e) { divInformation.append(moreInfosLink); } - - if($("#assessmentMode").is(":checked")) { - // alert("assessment mode"); - - for(let env in environment_variables) { - let env_values = environment_variables[env] - let div_container = $("<div>").prop("id", "assessment"+env) - let list_values = $("<select>"); - for(let value in env_values) { list_values.append($("<option>").prop("value", env_values[value]).text(env_values[value])) } - div_container.append(env).append(list_values) - divInformation.append(div_container) - } - - if($("#addAssessmentButton").length > 0) { - $("#addAssessmentButton").removeAttr("id"); // remove id to avoid duplicates (fix the miss of event on button) - } - - let to_csv_button = $("<button>").prop("id", "addAssessmentButton"); - if(preferred_language_carto === "french") { - to_csv_button.text("Ajouter au jeu de données"); - } else { - to_csv_button.text("Add to dataset"); - } - - let messageTooltip = divInformation[0].outerHTML + to_csv_button[0].outerHTML; - layer.bindPopup(messageTooltip) - layer.bringToFront(); - layer.openPopup(); - - $("#addAssessmentButton").on("click", function() { - let data_param = {} - for(let env in environment_variables) { - data_param[env] = $("#assessment"+env)[0].children[0].value - } - data_param["code_iris"] = code_iris - console.log(data_param) - $.ajax({ - type: "GET", - url: "/add_iris_to_csv", - data: data_param, - "async": false, - contentType: 'application/json;charset=UTF-8', - success: function(result) { - alert(result) - }, - error: function(result, textStatus, errorThrown) { - console.log(errorThrown); - } - }); - }); + if (selected_algorithm !== "undefined" && selected_algorithm !== undefined) { + predictions = predict(code_iris, selected_algorithm) + console.log(predictions) } - else { - if (selected_algorithm !== "undefined" && selected_algorithm !== undefined) { - predictions = predict(code_iris, selected_algorithm) - console.log(predictions) - } - let selectAlgorithm = $("<select>") - selectAlgorithm - .prop("id", "selectAlgorithmTooltip") - .append($("<option>").prop("value", "undefined").text("---")) + let selectAlgorithm = $("<select>") + selectAlgorithm + .prop("id", "selectAlgorithmTooltip") + .append($("<option>").prop("value", "undefined").text("---")) - for(let algorithm of classifiers) { - selectAlgorithm.append($("<option>").prop("value", algorithm).text(algorithm)); - } - previously_selected_algorithm = selected_algorithm; + for(let algorithm of classifiers) { + selectAlgorithm.append($("<option>").prop("value", algorithm).text(algorithm)); + } + previously_selected_algorithm = selected_algorithm; - let divPredictions = $("<div>").prop("id", "divPredictions") - if(predictions !== undefined) { - for(let key in predictions) { divPredictions.append(capitalizeFirstLetter(key.split("_").join(" "))+': ' + predictions[key]["most_frequent"] + " (" + predictions[key]["count_frequent"] + "/7)").append($('<br>')); } - } + let divPredictions = $("<div>").prop("id", "divPredictions") + if(predictions !== undefined) { + for(let key in predictions) { divPredictions.append(capitalizeFirstLetter(key.split("_").join(" "))+': ' + predictions[key]["most_frequent"] + " (" + predictions[key]["count_frequent"] + "/7)").append($('<br>')); } + } - let messageTooltip = divInformation[0].outerHTML + selectAlgorithm[0].outerHTML + divPredictions[0].outerHTML; - console.log(messageTooltip) - layer.bindPopup(messageTooltip) - layer.bringToFront(); - layer.openPopup(); + let messageTooltip = divInformation[0].outerHTML + selectAlgorithm[0].outerHTML + divPredictions[0].outerHTML; + console.log(messageTooltip) + layer.bindPopup(messageTooltip) + layer.bringToFront(); + layer.openPopup(); - $("#selectAlgorithmTooltip").val(previously_selected_algorithm); // must be after binding the popup to be effective - $("#selectAlgorithmTooltip").on("click", function() { displayPopup(e)}) // update popup (env variables) when click on an algorithm - } + $("#selectAlgorithmTooltip").val(previously_selected_algorithm); // must be after binding the popup to be effective + $("#selectAlgorithmTooltip").on("click", function() { displayPopup(e)}) // update popup (env variables) when click on an algorithm } /** diff --git a/predihood/temp.py b/predihood/temp.py deleted file mode 100644 index 3ea63a13d49acebd0cda3eecd1802d3aaec977b4..0000000000000000000000000000000000000000 --- a/predihood/temp.py +++ /dev/null @@ -1,89 +0,0 @@ -import pandas as pd -from sklearn.cluster import KMeans - -from predihood.classes.Data import Data -from predihood.classes.Dataset import Dataset -from predihood.classes.Method import Method -from predihood.config import ENVIRONMENT_VALUES - - -def geo_position(): - file = pd.read_csv("generated_files/cleaned_data.csv") - north, south, east, west, southEast, northEast, southWest, northWest, centre, problem = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - - for index, line in file.iterrows(): - # print(line) - # print(line["old_landscape"]) - if isinstance(line["old_geographical_position"], str): - old_val = line["old_geographical_position"].split()[0].upper() - if old_val == "NORD": - north += 1 - elif old_val == "SUD": - south += 1 - elif old_val == "EST": - east += 1 - elif old_val == "OUEST": - west += 1 - elif old_val == "CENTRE": - centre += 1 - elif old_val == "NORD-EST": - northEast += 1 - elif old_val == "NORD-OUEST": - northWest += 1 - elif old_val == "SUD-EST": - southEast += 1 - elif old_val == "SUD-OUEST": - southWest += 1 - else: - problem += 1 - print(line["old_geographical_position"]) - else: - print(line["old_geographical_position"]) - problem += 1 - - if isinstance(line["new_geographical_position"], str): - new_val = line["new_geographical_position"].split()[0].upper() - if new_val == "NORD": - north += 1 - elif new_val == "SUD": - south += 1 - elif new_val == "EST": - east += 1 - elif new_val == "OUEST": - west += 1 - elif new_val == "CENTRE": - centre += 1 - elif new_val == "NORD-EST": - northEast += 1 - elif new_val == "NORD-OUEST": - northWest += 1 - elif new_val == "SUD-EST": - southEast += 1 - elif new_val == "SUD-OUEST": - southWest += 1 - else: - problem += 1 - print(line["new_geographical_position"]) - else: - print(line["new_geographical_position"]) - problem += 1 - - print(north, south, east, west, southEast, northEast, southWest, northWest, centre, " - ", problem) - - -def k_means_v1(): - data = Data() - data.init_all_in_one() - for env in ENVIRONMENT_VALUES: - dataset = Dataset(data, env, "unsupervised") - # dataset.selected_indicators = - nb_clust = len(ENVIRONMENT_VALUES[env]) - print(dataset.selected_indicators) - - estimator = Method("kmeans", dataset, KMeans(n_clusters=nb_clust)) - estimator.fit() - - -if __name__ == '__main__': - # k_means_v1() - geo_position() diff --git a/predihood/templates/algorithmic-interface.html b/predihood/templates/algorithmic-interface.html index 9b4c6e52351dedf555b59e0a368f15ef2c94bd4a..1c0f0d2aae2e824f661611816c6ec3dc2c9d59db 100644 --- a/predihood/templates/algorithmic-interface.html +++ b/predihood/templates/algorithmic-interface.html @@ -33,7 +33,7 @@ {% if language == "french" %} <h6>Paramètres spécifiques<i id="specificParametersTitle" class="fas fa-angle-double-up"></i></h6> <ul id="specificParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> - <h6>Paramèteres communs<i id="commonParametersTitle" class="fas fa-angle-double-up"></i></h6> + <h6>Paramètres communs<i id="commonParametersTitle" class="fas fa-angle-double-up"></i></h6> <ul id="commonParameters" class="nav flex-column bg-white mb-0" style="display: block"></ul> {% else %} <h6>Specific parameters<i id="specificParametersTitle" class="fas fa-angle-double-up"></i></h6> diff --git a/predihood/templates/form.html b/predihood/templates/form.html index 2f114f0f862f1835162f0b4213ae25565ee624cd..84d99687daace27c7db28553f41250fadc1f9333 100644 --- a/predihood/templates/form.html +++ b/predihood/templates/form.html @@ -55,14 +55,6 @@ <br> </div> -<div> - {% if language == "french" %} - Expertise manuelle: <input type="checkbox" id="assessmentMode"/> - {% else %} - Manual assessment: <input type="checkbox" id="assessmentMode"/> - {% endif %} -</div> - <div class="input-group mb-3"> <button class="btn" type="button" id="boutonEffacer"> {% if language == "french" %} diff --git a/predihood/tests.py b/predihood/tests.py index 97fb69451af178d245f8b8078decbbf8b4d59b55..d445c260b8588caf9c8ed0ae29b84f39f6cfb8ad 100644 --- a/predihood/tests.py +++ b/predihood/tests.py @@ -54,7 +54,7 @@ class TestCase(unittest.TestCase): classifier_name = "KNeighbors Classifier" classifier = get_classifier(classifier_name) # classifier == KNeighborsClassifier() fails because they are different objects - assert type(classifier) == type(KNeighborsClassifier()) + assert classifier.isistance(type(KNeighborsClassifier())) def test_set_classifier(self): # test if setting the parameters of a classifier changes its internal parameters @@ -150,4 +150,3 @@ class TestCase(unittest.TestCase): if __name__ == "__main__": unittest.main(verbosity=2) # run all tests with verbose mode -