// 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