Skip to content

Instantly share code, notes, and snippets.

@lahaxearnaud
Last active November 8, 2018 05:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lahaxearnaud/e4742c678474bf1d6a49d4f4d4f007c4 to your computer and use it in GitHub Desktop.
Save lahaxearnaud/e4742c678474bf1d6a49d4f4d4f007c4 to your computer and use it in GitHub Desktop.
// 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