Skip to content

Instantly share code, notes, and snippets.

@lahaxearnaud lahaxearnaud/prediction
Last active Nov 8, 2018

What would you like to do?
// 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 = [
foreach($mojito->getIngredients() as $ingredientWithMeasure) {
$normalizeMojito[] = $ingredientWithMeasure->getIngredient()->getId();
while (count($normalizeMojito) < $model['maxNbIngredients']) {
$normalizeMojito[] = 0;
// prediction de la recette la plus proche
$cocktailLabel = $classifier->predict($normalizeMojito);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.