Skip to content
Snippets Groups Projects
Commit 13ae2147 authored by Matias Mennecart's avatar Matias Mennecart
Browse files

debut d'implemenation du choix de l'attribut de classification

parent 3611137d
No related branches found
No related tags found
No related merge requests found
...@@ -120,7 +120,10 @@ On obtient donc un taux de reussiste plutôt élevé. A chaque fois l'algorithme ...@@ -120,7 +120,10 @@ On obtient donc un taux de reussiste plutôt élevé. A chaque fois l'algorithme
| Distance Manhattan Normalisée | 0.178 | 0.188 | 0.2 | 0.215 | 0.205 | 0.203 | 0.194 | 0.190 | 0.184 | 0.180 | 0.190 | 7 | | Distance Manhattan Normalisée | 0.178 | 0.188 | 0.2 | 0.215 | 0.205 | 0.203 | 0.194 | 0.190 | 0.184 | 0.180 | 0.190 | 7 |
--- ---
ajoyter un commentaire sur les resultats Le taux de reussiste est ici plus bas, cela s'explique notement par le nombre d'attribut different et la complexité a identifier le type d'un pokemon.
Cependant le taux de reussiste reste satisfaisant et stable.
Classification par isLegendary
## Efficacité ## Efficacité
......
...@@ -45,10 +45,12 @@ public class AddDataController { ...@@ -45,10 +45,12 @@ public class AddDataController {
ClassificationModel model = ClassificationModel.getClassificationModel(); ClassificationModel model = ClassificationModel.getClassificationModel();
if (!model.getDatas().isEmpty()) { if (!model.getDatas().isEmpty()) {
Map<String, Object> attrMap = model.getDatas().get(0).getAttributesNames(); Map<String, Object> attrMap = model.getDatas().get(0).getAttributesNames();
int classificationType = model.getDatas().get(0).getClassificationType();
for (Map.Entry<String, Object> entry : attrMap.entrySet()) { for (Map.Entry<String, Object> entry : attrMap.entrySet()) {
String attrName = entry.getKey(); String attrName = entry.getKey();
Object attrValue = entry.getValue(); Object attrValue = entry.getValue();
if(!attrMap.keySet().toArray()[classificationType].equals(attrName)) {
Label label = new Label(attrName); Label label = new Label(attrName);
HBox hbox = new HBox(10, label); HBox hbox = new HBox(10, label);
hbox.setAlignment(Pos.CENTER); hbox.setAlignment(Pos.CENTER);
...@@ -96,6 +98,9 @@ public class AddDataController { ...@@ -96,6 +98,9 @@ public class AddDataController {
} }
entries.getChildren().add(hbox); entries.getChildren().add(hbox);
} }
}
} }
} }
......
...@@ -51,15 +51,6 @@ public class MethodKNN { ...@@ -51,15 +51,6 @@ public class MethodKNN {
} }
} }
/**
* Permet de recuperer les K-voisins les plus proches d'une données dans un jeu de données
* en fonction d'une Distance.
* @param datas Le jeu de données
* @param data La donnée avec laquelle calculer la distance
* @param k Le nombre de voisins a recupérer
* @param distance
* @return
*/
public static List<LoadableData> kVoisins(List<LoadableData> datas, LoadableData data, int k, Distance distance) { public static List<LoadableData> kVoisins(List<LoadableData> datas, LoadableData data, int k, Distance distance) {
// On recupere toutes les données // On recupere toutes les données
...@@ -77,7 +68,7 @@ public class MethodKNN { ...@@ -77,7 +68,7 @@ public class MethodKNN {
public static String estimateClass(List<LoadableData> datas, LoadableData data, int k, Distance distance) { public static String estimateClass(List<LoadableData> datas, LoadableData data, int k, Distance distance) throws IllegalAccessException {
// On recupere les K voisions de data. // On recupere les K voisions de data.
List<LoadableData> kVoisins = MethodKNN.kVoisins(datas, data, k, distance); List<LoadableData> kVoisins = MethodKNN.kVoisins(datas, data, k, distance);
...@@ -105,7 +96,7 @@ public class MethodKNN { ...@@ -105,7 +96,7 @@ public class MethodKNN {
} }
public static int bestK(List<LoadableData> datas, Distance distance) { public static int bestK(List<LoadableData> datas, Distance distance) throws IllegalAccessException {
// On borne le K pour eviter de trouver un K trop grand // On borne le K pour eviter de trouver un K trop grand
int maxK = (int) (Math.sqrt(datas.size())); int maxK = (int) (Math.sqrt(datas.size()));
System.out.println("Max k: " + maxK); System.out.println("Max k: " + maxK);
...@@ -128,7 +119,7 @@ public class MethodKNN { ...@@ -128,7 +119,7 @@ public class MethodKNN {
} }
public static double robustesse(List<LoadableData> datas, int k, Distance distance, double testPart) { public static double robustesse(List<LoadableData> datas, int k, Distance distance, double testPart) throws IllegalAccessException {
...@@ -167,7 +158,7 @@ public class MethodKNN { ...@@ -167,7 +158,7 @@ public class MethodKNN {
return taux/(1/testPart); return taux/(1/testPart);
} }
public static void main(String[] args) throws CsvRequiredFieldEmptyException { public static void main(String[] args) throws CsvRequiredFieldEmptyException, IllegalAccessException {
//Test de la robustesse et du meillleur K //Test de la robustesse et du meillleur K
......
...@@ -101,6 +101,8 @@ public class ClassificationModel extends Observable { ...@@ -101,6 +101,8 @@ public class ClassificationModel extends Observable {
notifyObservers(); notifyObservers();
} catch (IOException e) { } catch (IOException e) {
System.err.println("Erreur lors du chargement des données : " + e.getMessage()); System.err.println("Erreur lors du chargement des données : " + e.getMessage());
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} }
} }
...@@ -121,7 +123,11 @@ public class ClassificationModel extends Observable { ...@@ -121,7 +123,11 @@ public class ClassificationModel extends Observable {
public void classifierDonnee(LoadableData data) { public void classifierDonnee(LoadableData data) {
if(dataToClass.get(data) != null && dataToClass.get(data)) return; if(dataToClass.get(data) != null && dataToClass.get(data)) return;
this.dataToClass.remove(data); this.dataToClass.remove(data);
try {
data.setClassification(MethodKNN.estimateClass(datas, data, k, distance)); data.setClassification(MethodKNN.estimateClass(datas, data, k, distance));
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
notifyObservers(data); notifyObservers(data);
dataToClass.put(data, true); dataToClass.put(data, true);
} }
......
...@@ -68,6 +68,16 @@ public class Iris extends LoadableData { ...@@ -68,6 +68,16 @@ public class Iris extends LoadableData {
return variety; return variety;
} }
@Override
public Map<String, Object> getClassifiedAttributes() {
return Map.of();
}
@Override
public int getClassificationType() {
return 0;
}
/** /**
* Définit la classification (variété) de l'Iris. * Définit la classification (variété) de l'Iris.
* @param classification variété à définir. * @param classification variété à définir.
......
...@@ -29,7 +29,7 @@ public abstract class LoadableData { ...@@ -29,7 +29,7 @@ public abstract class LoadableData {
* Renvoie la classification de l'objet. * Renvoie la classification de l'objet.
* @return classification sous forme de chaîne. * @return classification sous forme de chaîne.
*/ */
public abstract String getClassification(); public abstract String getClassification() throws IllegalAccessException;
/** /**
* Renvoie les types de classification définis. * Renvoie les types de classification définis.
...@@ -97,11 +97,15 @@ public abstract class LoadableData { ...@@ -97,11 +97,15 @@ public abstract class LoadableData {
*/ */
public abstract Map<String, Object> getClassifiedAttributes();
public abstract int getClassificationType() ;
/** /**
* Définit la classification de l'objet. * Définit la classification de l'objet.
* @param classification classification à définir. * @param classification classification à définir.
*/ */
public abstract void setClassification(String classification); public abstract void setClassification(String classification) throws IllegalAccessException;
public abstract Map<String, Object> getAttributesNames(); public abstract Map<String, Object> getAttributesNames();
......
package fr.univlille.sae.classification.model; package fr.univlille.sae.classification.model;
import com.opencsv.bean.CsvBindByName; import com.opencsv.bean.CsvBindByName;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.*;
import java.util.Map;
public class Pokemon extends LoadableData{ public class Pokemon extends LoadableData{
...@@ -37,6 +36,7 @@ public class Pokemon extends LoadableData{ ...@@ -37,6 +36,7 @@ public class Pokemon extends LoadableData{
@CsvBindByName(column = "is_legendary") @CsvBindByName(column = "is_legendary")
private boolean isLegendary; private boolean isLegendary;
private int classificationType = 5;
public Pokemon(String name, int attack, int baseEggSteps, double captureRate, int defense, int experienceGrowth, int hp, int spAttack, int spDefense, String type1, String type2, double speed, boolean isLegendary) { public Pokemon(String name, int attack, int baseEggSteps, double captureRate, int defense, int experienceGrowth, int hp, int spAttack, int spDefense, String type1, String type2, double speed, boolean isLegendary) {
super(); super();
...@@ -76,8 +76,8 @@ public class Pokemon extends LoadableData{ ...@@ -76,8 +76,8 @@ public class Pokemon extends LoadableData{
* @return classification sous forme de chaîne. * @return classification sous forme de chaîne.
*/ */
@Override @Override
public String getClassification() { public String getClassification() throws IllegalAccessException {
return type1; return (String) this.getClass().getDeclaredFields()[classificationType].get(this).toString();
} }
/** /**
...@@ -86,10 +86,42 @@ public class Pokemon extends LoadableData{ ...@@ -86,10 +86,42 @@ public class Pokemon extends LoadableData{
* @param classification classification à définir. * @param classification classification à définir.
*/ */
@Override @Override
public void setClassification(String classification) { public void setClassification(String classification) throws IllegalAccessException {
this.type1 = classification; this.getClass().getDeclaredFields()[classificationType].set("", classification);
}
/**
* Permet de modifier l'attribut sur lequelle ont souhaite classifier
* Ne sont valable que les attributs present dans getClassificationAttributes()
*
* Le numéro de l'attribut correspond a sa place dans la liste de tous le attributs.
* @param classificationType
*/
public void setClassificationType(int classificationType) throws IllegalArgumentException{
if(classificationType < 0 || classificationType > getAttributesNames().size()) throw new IllegalArgumentException("Cette attribut n'existe pas");
if(getClassifiedAttributes().containsKey(getAttributesNames().keySet().toArray()[classificationType])) throw new IllegalArgumentException("Cette attribut ne peut pas être utiliser pour la classification");
this.classificationType = classificationType;
}
public Map<String, Object> getClassifiedAttributes() {
Map<String, Object> attributes = new HashMap<>();
attributes.put("Experience growth", experienceGrowth);
attributes.put("Type 1", type1);
attributes.put("Type 2", type2);
attributes.put("Is legendary", isLegendary);
return attributes;
} }
@Override
public int getClassificationType() {
return classificationType;
}
/** /**
* Renvoie les noms des attributs de l'objet. * Renvoie les noms des attributs de l'objet.
...@@ -109,6 +141,8 @@ public class Pokemon extends LoadableData{ ...@@ -109,6 +141,8 @@ public class Pokemon extends LoadableData{
attrNames.put("HP", hp); attrNames.put("HP", hp);
attrNames.put("Special attack", spAttack); attrNames.put("Special attack", spAttack);
attrNames.put("Special defense", spDefense); attrNames.put("Special defense", spDefense);
attrNames.put("Type 1", type1);
attrNames.put("Type 2", type2);
attrNames.put("Speed", speed); attrNames.put("Speed", speed);
attrNames.put("Is legendary", isLegendary); attrNames.put("Is legendary", isLegendary);
return attrNames; return attrNames;
......
...@@ -87,9 +87,9 @@ public class ViewUtil { ...@@ -87,9 +87,9 @@ public class ViewUtil {
tempHBox = new HBox(); tempHBox = new HBox();
label = new Label(colorsString[i+j]); label = new Label(colorsString[i+j]);
rectangle = new Rectangle(10, 10); Circle circle = new Circle(5);
rectangle.setFill(colors.get(colorsString[i+j])); circle.setFill(colors.get(colorsString[i+j]));
tempHBox.getChildren().addAll(rectangle, label); tempHBox.getChildren().addAll(circle, label);
line.getChildren().add(tempHBox); line.getChildren().add(tempHBox);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment