Last active
November 8, 2018 05:49
-
-
Save lahaxearnaud/e4742c678474bf1d6a49d4f4d4f007c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// récupération de mon entité, avec doctrine ici | |
$mojito = $this->entityManager->getRepository(Cocktail::class)->find(666); | |
// nous génère la matrice en enlevant le mojito | |
$matrices = $this->cocktailMachineLearning->generateMatricesWithoutCocktails([$mojito]); | |
// initialisation de l'algo | |
$classifier = new KNearestNeighbors(1, new CocktailsDistance()); | |
// entrainement de l'algo sur les données normalisées | |
$classifier->train($matrices['samples'], $matrices['labels']); | |
// normalisation du mojito | |
$normalizeMojito = [ | |
intval($mojito->isAlcohol()) | |
]; | |
foreach($mojito->getIngredients() as $ingredientWithMeasure) { | |
$normalizeMojito[] = $ingredientWithMeasure->getIngredient()->getId(); | |
} | |
sort($normalizeMojito); | |
while (count($normalizeMojito) < $model['maxNbIngredients']) { | |
$normalizeMojito[] = 0; | |
} | |
// prediction de la recette la plus proche | |
$cocktailLabel = $classifier->predict($normalizeMojito); | |
dump(cocktailLabel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment