Upload
joel-lord
View
75
Download
0
Embed Size (px)
Citation preview
www.spiria.com
Apprendre l’apprentissage automatisé
Présenté par
JOEL LORD
Web à Québec4 avril, 2017
@joel__lord#WAQ17
JOEL LORDÀ propos de moi
• Adorateur de Javascript• Bidouilleur• Enthousiaste des
technologies
@joel__lord#WAQ17
Agenda
• Intelligence articifielle vs Apprentissage automatisé• Big Data et apprentissage profond• Les algo de base
• Naïve Bayes Classifier• Sentiment Analysis• Genetic Algorithm
@joel__lord#WAQ17
Agenda
• Intelligence articifielle vs Apprentissage automatisé• Big Data et apprentissage profond• Les algo de base
• Naïve Bayes Classifier• Sentiment Analysis• Genetic Algorithm
• Le tout parsemé de démos
Intelligence Articielle et Apprentissage automatisé
UN PEU PLUS AU SUJET DE…
@joel__lord#WAQ17
Intelligence artificielleQU’EST CE QUI EN EST
@joel__lord#WAQ17
L'intelligence artificielle (IA) estl'intelligence fournie par les machines. Eninformatique, le domaine de la recherchesur l'IA se définit comme l'étude des «agents intelligents»: tout dispositif qui perçoit son environnement et prend des mesures qui maximisent ses chances de succès à un but.
@joel__lord#WAQ17
Intelligence ArtificielleEXEMPLES CONCRETS
@joel__lord#WAQ17
Intelligence ArtificielleEXEMPLES CONCRETES
• Filtres de pouriels
@joel__lord#WAQ17
Intelligence ArtificielleEXEMPLES CONCRETES
• Filtres de polluriels• Prévention de la fraude
@joel__lord#WAQ17
Intelligence ArtificielleEXEMPLES CONCRETES
• Filtres de polluriels• Prévention de la fraude• Reconnaissance faciale
@joel__lord#WAQ17
L'apprentissage automatisé est le sous-domaine de l'informatique qui donne aux «ordinateurs la possibilité d'apprendresans être explicitement programmés».
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google• Chat Bots
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google• Chat Bots
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google• Chat Bots
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google• Chat Bots
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google• Chat Bots
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google• Chat Bots
@joel__lord#WAQ17
Apprentissage automatiséEXEMPLES CONCRETS
• Thermostats intelligents• Cortana, Siri et Ok Google• Chat Bots
Big Data et apprentissageprofond
ENCORE UN PEU DE THÉORIE
@joel__lord#WAQ17
Big DataQU’EST-CE QUE C’EST?
• Croissanceexponentielle des données digitales
• Trop complexe à traiterde façon traditionnelle
• Principalement utiliséepour de la prédictionou analyse des comportements des utilisateurs
@joel__lord#WAQ17
Apprentissage profonD (Deep learning)QU’EST-CE QUE C’EST
• Utilise des réseaux neuronaux pour traiter les données• Idéal pour des classsificateurs complexes• Un moyen de traiter le big data
@joel__lord#WAQ17
Réseaux NeuronauxEUH…. WHAT?
• Une collection de couches d’opérations
• Déconstruction d’uneproblème complexe entâches plus simples
Supervisé vs non-superviséUNE DERNIÈRE PETITE CHOSE…
@joel__lord#WAQ17
Apprentissage superviséQU’EST-CE QUE C’EST
• Requiert une rétroaction• Débute avec aucune connaissance et augmente sa compréhension• Inutile lorsque les données sont de mauvaise qualité• Cas pratiques
• Classification
@joel__lord#WAQ17
Apprentissage non-superviséCONTRAIRE DE SUPERVISÉ?
• Besoin d’aucun feedback• Pratique lorsqu’il n’y a pas de bonne ou mauvais réponse• Aide à trouver des patterns ou structures de données• Cas pratiques
• “Vous pourriez aussi être intéressé par…”• Grouper des clients selon leur comportement
Apprentissage automatiséDE RETOUR À LA PROGRAMMATION NORMALE
@joel__lord#WAQ17
Classification naïve bayésienneDÉFINITION
• Algorithme supervisé• Un simple moyen de classifier et identifier l’information
var classifier = new Classifier();classifier.classify("J'adore le Javascript", POSITIVE);classifier.classify('WebStorm est génial', POSITIVE);classifier.classify('Non, Javascript est mauvais', NEGATIVE);classifier.classify("Je n'aime pas le brocoli", NEGATIVE);
console.log(classifier.categorize("Javascript est génial"));// "positive"
console.log(classifier.categorize("J'aime WebStorm"));// undefined
@joel__lord#WAQ17
Classification naïve bayésienneDÉFINITION
• Algorithme supervisé• Un simple moyen de classifier et identifier l’information• Mathématiquement exprimé par la fonction suivante
@joel__lord#WAQ17
Classification naïve bayésienneDÉFINITION DE LA STRUCTURE
var Classifier = function() {this.dictionaries = {};};
Classifier.prototype.classify = function(text, group) {
};
Classifier.prototype.categorize = function(text) {
};
@joel__lord#WAQ17
Classification naïve bayésienneCRÉATION DE LA CLASSIFICATION
Classifier.prototype.classify = function(text, group) {var words = text.split(" ");this.dictionaries[group] ? "" : this.dictionaries[group] = {};
var self = this;words.map((w) => {if (self.dictionaries[group][w]) {self.dictionaries[group][w]++;} else {self.dictionaries[group][w] = 1;}});};
@joel__lord#WAQ17
Classification naïve bayésienneET LE RESTE…Classifier.prototype.categorize = function(text) {var self = this;var probabilities = {};var groups = [];var finals = {};//Find the groupsfor (var k in this.dictionaries) {groups.push(k);}var sums = {};var probs = {};//Loop through the groups to calculate the sums of found textfor (var j = 0; j < groups.length; j++) {if (!sums[text]) sums[text] = 0;if (!this.dictionaries[groups[j]][text]) this.dictionaries[groups[j]][text] = 0;sums[text] += this.dictionaries[groups[j]][text];probs[groups[j]] = (this.dictionaries[groups[j]][text]) ? this.dictionaries[groups[j]][text] : 0;}// Perform calculationsfor (var j = 0; j < groups.length; j++) {(!probabilities[text]) ? probabilities[text] = {} : "";(!probs[groups[j]]) ? probabilities[text][groups[j]] = 0 : probabilities[text][groups[j]] =
probs[groups[j]]/sums[text];}//Average out the probabilities
for (var j = 0; j < groups.length; j++) {if (!finals[groups[j]]) finals[groups[j]] = [];finals[groups[j]].push(probabilities[text][groups[j]]);}for (var i = 0; i < groups.length; i++) {finals[groups[i]] = average(finals[groups[i]]);}//Find the largest probabilityvar highestGroup = "";var highestValue = 0;for (var group in finals) {if (finals[group] > highestValue) {highestGroup = group;highestValue = finals[group];}}
return highestGroup;};
@joel__lord#WAQ17
Classification naïve bayésienneCATÉGORISATION
Classifier.prototype.categorize = function(text) {var self = this;var probabilities = {};var groups = [];var finals = {};
};
@joel__lord#WAQ17
Classification naïve bayésienneCATÉGORISATION
Classifier.prototype.categorize = function(text) {…//Find the groupsfor (var k in this.dictionaries) {groups.push(k);}var sums = {};var probs = {};
};
@joel__lord#WAQ17
Classification naïve bayésienneCATÉGORISATION
Classifier.prototype.categorize = function(text) {…//Loop through the groups to calculate the sums of found textfor (var j = 0; j < groups.length; j++) {if (!sums[text]) sums[text] = 0;if (!this.dictionaries[groups[j]][text]) this.dictionaries[groups[j]][text]
= 0;sums[text] += this.dictionaries[groups[j]][text];probs[groups[j]] = (this.dictionaries[groups[j]][text]) ?
this.dictionaries[groups[j]][text] : 0;}};
@joel__lord#WAQ17
Classification naïve bayésienneCATÉGORISATION
Classifier.prototype.categorize = function(text) {…// Perform calculationsfor (var j = 0; j < groups.length; j++) {(!probabilities[text]) ? probabilities[text] = {} : "";(!probs[groups[j]]) ? probabilities[text][groups[j]] = 0 :
probabilities[text][groups[j]] = probs[groups[j]]/sums[text];}};
@joel__lord#WAQ17
Classification naïve bayésienneCATÉGORISATION
Classifier.prototype.categorize = function(text) {…
//Average out the probabilities
for (var j = 0; j < groups.length; j++) {if (!finals[groups[j]]) finals[groups[j]] = [];finals[groups[j]].push(probabilities[text][groups[j]]);
}for (var i = 0; i < groups.length; i++) {finals[groups[i]] = average(finals[groups[i]]);
}};
@joel__lord#WAQ17
Classification naïve bayésienneCATÉGORISATION
Classifier.prototype.categorize = function(text) {…//Find the largest probabilityvar highestGroup = "";var highestValue = 0;for (var group in finals) {if (finals[group] > highestValue) {highestGroup = group;highestValue = finals[group];
}}
return highestGroup;};
@joel__lord#WAQ17
Classification naïve bayésienneSOMMAIREClassifier.prototype.categorize = function(text) {var self = this;var probabilities = {};var groups = [];var finals = {};//Find the groupsfor (var k in this.dictionaries) {groups.push(k);}var sums = {};var probs = {};//Loop through the groups to calculate the sums of found textfor (var j = 0; j < groups.length; j++) {if (!sums[text]) sums[text] = 0;if (!this.dictionaries[groups[j]][text]) this.dictionaries[groups[j]][text] = 0;sums[text] += this.dictionaries[groups[j]][text];probs[groups[j]] = (this.dictionaries[groups[j]][text]) ? this.dictionaries[groups[j]][text] : 0;}// Perform calculationsfor (var j = 0; j < groups.length; j++) {(!probabilities[text]) ? probabilities[text] = {} : "";(!probs[groups[j]]) ? probabilities[text][groups[j]] = 0 : probabilities[text][groups[j]] =
probs[groups[j]]/sums[text];}//Average out the probabilities
for (var j = 0; j < groups.length; j++) {if (!finals[groups[j]]) finals[groups[j]] = [];finals[groups[j]].push(probabilities[text][groups[j]]);}for (var i = 0; i < groups.length; i++) {finals[groups[i]] = average(finals[groups[i]]);}//Find the largest probabilityvar highestGroup = "";var highestValue = 0;for (var group in finals) {if (finals[group] > highestValue) {highestGroup = group;highestValue = finals[group];}}
return highestGroup;};
Montrez moi !CLASSIFICATION NAÏVE BAYÉSIENNE
@joel__lord#WAQ17
Analyse de sentimentsCOMMENT ÇA FONCTIONNE
• Approche similaire aux classificateurs• Utilise une liste de mots (AFINN-165) et parfois les emoticons pour
donner un score.
@joel__lord#WAQ17
Analyse de sentimentsEXEMPLE DE CODE
var twit = require("twit");var sentiment = require("sentiment");
@joel__lord#WAQ17
Analyse de sentimentsEXEMPLE DE CODE
var keyword = "#waq17";var t = new twit(require("./credentials"));var stream1 = t.stream("statuses/filter", {track: keyword});
@joel__lord#WAQ17
Analyse de sentimentsEXEMPLE DE CODE
stream1.on("tweet", function (tweet) {
});
@joel__lord#WAQ17
Analyse de sentimentsEXEMPLE DE CODE
var score = sentiment(tweet.text);console.log("--- \n New Tweet\n" + tweet.text + "\n" + (score > 0 ?
"Positive" : "Negative"));
@joel__lord#WAQ17
Analyse de sentimentsEXEMPLE DE CODE
var twit = require("twit");var sentiment = require("sentiment");var keyword = "#waq17";var t = new twit(require("./credentials"));var stream1 = t.stream("statuses/filter", {track: keyword});stream1.on("tweet", function (tweet) {var score = sentiment(tweet.text);console.log("--- \n New Tweet\n" + tweet.text + "\n" + (score > 0 ?
"Positive" : "Negative"));});
Montrez moi !ANALYSE DE SENTIMENTS
@joel__lord#WAQ17
Algorithmes génétiquesÇA MANGE QUOI EN HIVER
• Moyen de trouver une solution idéaleen utilisant des solutions aléatoires
• Cas pratiques• Moteurs d’avion• Hackrod
@joel__lord#WAQ17
Algorithmes génétiquesCOMMENT ÇA FONCTIONNE
• On crée une population d’individus aléatoires• On garde les plus proches de la solution• On garde des individus aléatoires• On introduit des mutations aléatores• On crée aléatoirement des “enfants”• On arrive magiquement à une solution!
@joel__lord#WAQ17
Algorithmes génétiquesCOMMENT ÇA FONCTIONNE
• On crée une population d’individus aléatoires• On garde les plus proches de la solution• On garde des individus aléatoires• On introduit des mutations aléatores• On crée aléatoirement des “enfants”• On arrive magiquement à une solution!
@joel__lord#WAQ17
Algorithmes génétiquesL’IMPORTANCE DES MUTATIONS
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
var population = [];const TARGET = 200;const MIN = 0;const MAX = TARGET - 1;const IND_COUNT = 4;const POP_SIZE = 100;const CLOSE_ENOUGH = 0.001;var RETAIN = 0.02;var RANDOM_SELECTION = 0.05;var MUTATION_PROBABILITY = 0.01;
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Consts
function randomInt(min, max) {return Math.round(random(min, max));
}
function random(min, max) {if (max == undefined) { max = min; min = 0; }if (max == undefined) { max = 100; }return (Math.random()*(max-min)) + min;
}
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Constsfunction randomInt(min, max) {…}function random(min, max) {…}
function fitness(individual) {sum = individual.reduce((a,b) => a + b, 0);return Math.abs(TARGET - sum);
}
function sortByFitness(population) {population.sort((a, b) => {var fitA = fitness(a); var fitB = fitness(b);return fitA > fitB ? 1 : -1;
});return population;
}
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Constsfunction randomInt(min, max) {…}function random(min, max) {…}function fitness(individual) {…}function sortByFitness(population) {…}
function randomIndividual() {var individual = [];for (var i = 0; i < IND_COUNT; i++) {individual.push(random(MIN, MAX));
}return individual;
}
function randomPopulation(size) {var population = [];for (var i = 0; i < size; i++) {population.push(randomIndividual());
}return population;
}
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Constsfunction randomInt(min, max) {…}function random(min, max) {…}function fitness(individual) {…}function sortByFitness(population) {…}function randomIndividual() {…}function randomPopulation(size) {…}
function mutate(population) {for (var i=0; i < population.length; i++) {if (MUTATION_PROBABILITY > Math.random()) {var index = randomInt(population[i].length);population[i][index] = random(MIN, MAX);
}}return population;
}
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Constsfunction randomInt(min, max) {…}function random(min, max) {…}function fitness(individual) {…}function sortByFitness(population) {…}function randomIndividual() {…}function randomPopulation(size) {…}function mutate(population) {…}
function reproduce(father, mother) {var half = father.length / 2;var child = [];child = child.concat(father.slice(0, half), mother.slice(half,
mother.length));return child;
}
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Constsfunction randomInt(min, max) {…}function random(min, max) {…}function fitness(individual) {…}function sortByFitness(population) {…}function randomIndividual() {…}function randomPopulation(size) {…}function mutate(population) {…}function reproduce(father, mother) {…}
function evolve(population) {var parents = [];//Keep the best solutionsparents=sortByFitness(population).slice(0,Math.round(POP_SIZE*RETAIN));//Randomly add new elementsfor (var i = parents.length; i < POP_SIZE - parents.length; i++) {if (RANDOM_SELECTION > Math.random()) {parents.push(randomIndividual());
}}
}
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Constsfunction randomInt(min, max) {…}function random(min, max) {…}function fitness(individual) {…}function sortByFitness(population) {…}function randomIndividual() {…}function randomPopulation(size) {…}function mutate(population) {…}function reproduce(father, mother) {…}
function evolve(population) {//Random Stuffparents = mutate(parents);var rndMax = parents.length - 1;while (parents.length < POP_SIZE) {var father = randomInt(rndMax);var mother = randomInt(rndMax);if (father != mother) {father = parents[father]; mother = parents[mother];parents.push(reproduce(father, mother));
}}return parents;
}
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
//Declare Constsfunction randomInt(min, max) {…}function random(min, max) {…}function fitness(individual) {…}function sortByFitness(population) {…}function randomIndividual() {…}function randomPopulation(size) {…}function mutate(population) {…}function reproduce(father, mother) {…}function evolve(population) {…}
function findSolution() {var population = randomPopulation(POP_SIZE);var generation = 0;while (fitness(population[0]) > CLOSE_ENOUGH) {generation++;population = evolve(population);
}return {solution: population[0], generations: generation};
}
var sol = findSolution();
@joel__lord#WAQ17
Algorithmes génétiquesEXEMPLE DE CODE
var population = [];const TARGET = 200;const MIN = 0;const MAX = TARGET - 1;const IND_COUNT = 4;const POP_SIZE = 100;const CLOSE_ENOUGH = 0.001;var RETAIN = 0.02;var RANDOM_SELECTION = 0.05;var MUTATION_PROBABILITY = 0.01;
function randomInt(min, max) {return Math.round(random(min, max));
}
function random(min, max) {if (max == undefined) { max = min; min = 0; }if (max == undefined) { max = 100; }return (Math.random()*(max-min)) + min;
}
function fitness(individual) {sum = individual.reduce((a,b) => a + b, 0);return Math.abs(TARGET - sum);
}
function sortByFitness(population) {population.sort((a, b) => {var fitA = fitness(a); var fitB = fitness(b);return fitA > fitB ? 1 : -1;
});return population;
}
function randomIndividual() {var individual = [];for (var i = 0; i < IND_COUNT; i++) {individual.push(random(MIN, MAX));
}return individual;
}
function randomPopulation(size) {var population = [];for (var i = 0; i < size; i++) {population.push(randomIndividual());
}return population;
}
function mutate(population) {for (var i=0; i < population.length; i++) {if (MUTATION_PROBABILITY > Math.random()) {var index = randomInt(population[i].length);population[i][index] = random(MIN, MAX);
}}return population;
}
function reproduce(father, mother) {var half = father.length / 2;var child = [];child = child.concat(father.slice(0, half), mother.slice(half, mother.length));return child;
}
function evolve(population) {var parents = [];//Keep the best solutionsparents = sortByFitness(population).slice(0, Math.round(POP_SIZE*RETAIN));//Randomly add new elementsfor (var i = parents.length; i < POP_SIZE - parents.length; i++) {if (RANDOM_SELECTION > Math.random()) {parents.push(randomIndividual());
}}//Mutate elementsparents = mutate(parents);var rndMax = parents.length - 1;while (parents.length < POP_SIZE) {var father = randomInt(rndMax);var mother = randomInt(rndMax);if (father != mother) {father = parents[father];mother = parents[mother];parents.push(reproduce(father, mother));
}}return parents;
}
function findSolution() {var population = randomPopulation(POP_SIZE);var generation = 0;while (fitness(population[0]) > CLOSE_ENOUGH) {generation++;population = evolve(population);
}return {solution: population[0], generations: generation};
}
var sol = findSolution();console.log("Found solution in " + sol.generations + " generations.", sol.solution);
Faut le voir pour le croireALGORITHMES GÉNÉTIQUES
DOCUMENT CONFIDENTIEL, TOUT DROIT RÉSERVÉ
PRESENTED BY
That’s all folks !Questions?
JOEL LORDApril 4th, 2017
TWITTER: @JOEL__LORDGITHUB: HTTP://GITHUB.COM/JOELLORD
@joel__lord#WAQ17
QuestionIMPACT OF PARAMETERS ON GENETIC ALGORITHMS