Skip to content
Snippets Groups Projects
Commit 73c68c5b authored by Nelly Barret's avatar Nelly Barret
Browse files

[FINAL] final version

parent 5b911d7a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
import logging
import sys
logging.basicConfig(level=logging.DEBUG)
\ No newline at end of file
# 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,
......
......@@ -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
}
/**
......
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()
......@@ -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>
......
......@@ -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" %}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment