Machine learning is teaching the computer how to learn by itself. It is far easier to be done, especially when you have small data set and a good level of expertise in your field. Classifying objects, predicting who will buy, spotting comments in code is achieved with grassy algorithms like neural networks, genetic algorithms or ant herding. PHP is in good position to make use of such teachings, and take advantages of related technologies like fann. By the end of the session, you'll know where you want to try it.
4. MachineLearning
• Teaching the machine
• Supervised learning : learning then applying
• Application build its own model : training phase
• It applies its model to real cases : applying phase
5. Applications
• Play go, chess, tic-tac-toe and beat everyone else
• Fraud detection and risk analysis
• Automated translation or automated transcription
• OCR and face recognition
• Medical diagnostics
• Walk, welcome guest at hotels, play football
• Finding good PHP code
7. RealUseCase
• Identify code in comments
• Classic problem
• Good problem for machine learning
• Complex, no simple solution
• A lot of data and expertise are available
14. PreparingData
Raw data Extract Filter Human review Fann ready
• Extract data from raw source
• Remove any useless data from extract
• Apply some human review to filtered data
• Format data for FANN
15. ExpertAtWork
// Test if the if is in a compressed format
// nie mowie po polsku
// There is a parser specified in `Parser::$KEYWORD_PARSERS`
// $result should exist, regardless of $_message
// TODO : fix this; var_dump($var);
// $a && $b and multidimensional
// numGlyphs + 1
//$annots .= ' /StructParent ';
// $cfg['Servers'][$i]['controlpass'] = 'pmapass';
// if(ob_get_clean()){
16. InputVector
• 'length' : size of the comment
• 'countDollar' : number of $
• 'countEqual' : number of =
• 'countObjectOperator' number of -> operator ($o->p)
• 'countSemicolon' : number of semi-colon ;
17. InputData
47 5 1
825 0 0 0 1
0
37 2 0 0 0
0
55 2 2 0 1
1
61 2 1 3 1
1
...
NumberOfInput
NumberOfIncomingData
NumberOfOutgoingData
* (at your option) any later v
*
* Exakat is distributed in the
* but WITHOUT ANY WARRANTY; wi
* MERCHANTABILITY or FITNESS F
* GNU Affero General Public Li
*
* You should have received a c
* along with Exakat. If not,
*
* The latest code can be found
*
*/
// $x[3] or $x[] and multidimen
//if ($round == 3) { die('Round
//$this->errors[] = $this->lang
26. Results>0.8
• Answer between 0 and 1
• Values ranges from -14 to 0,999
• The closer to 1, the safer. The closer to 0, the safer.
• Is this a percentage? Is this a carrots count ?
• It's a mix of counts…
33. Results
• 1960 issues
• 50+% of false positive
• With an easy clean, 822 issues reported
• 14k comments, analyzed in 68 ms (367ms in PHP5)
• Total time of coding : 27 mins.
// = ( 59 X 84 ) Mm = ( 2.32 X 3.31 ) In
/* Vim: Set Expandtab Sw=4 Ts=4 Sts=4: */
34. Learn Better,NotHarder
• Better training data
• Improve characteristics
• Configure the neural network
• Change algorithm
• Automate learning
• Update constantly
Real data
History
data
Training
Model Results
Retroaction
35. BetterTrainingData
• More data, more data, more data
• Varied situations, real case situations
• Include specific cases
• Experience is capital
• https://homes.cs.washington.edu/~pedrod/papers/
cacm12.pdf
36. ImproveCharacteristics
• Add new characteristics
• Remove the one that are less interesting
• Find the right set of characteristics
38. ChangeAlgorithm
• First add more data before changing algorithm
• Try cascade2 algorithm from FANN
• 0.6 => 0 found
• 0.5 => 2 found
• Not found by the first algorithm
• Ant colony, genetics algorithm, gravitational search,
artificial immune, nie mowie po polsku, annealing,
harmony search, interior point search, taboo search
42. Conclusion
• Machine learning is about data, not code
• There are tools to use it with PHP
• Fast to try, easy results or fast fail
• Use it for complex problems, that accepts error