Michael C.
June 09, 2018
170

# Machine Learning and Trend Analysis in PHP - DPC 18

June 09, 2018

## Transcript

1. TREND ANALYSIS AND MACHINE
LEARNING IN PHP
DUTCH PHP CONFERENCE 2018
@MICHAELCULLUMUK

2. TREND ANALYSIS AND MACHINE
LEARNING IN PHP
DUTCH PHP CONFERENCE 2018
@MICHAELCULLUMUK

3. @MICHAELCULLUMUK
ME?

4. MICHAEL CULLUM
@MICHAELCULLUMUK

5. @MICHAELCULLUMUK
ARTIFICIAL
INTELLIGENCE

6. @MICHAELCULLUMUK
MACHINE LEARNING

7. @MICHAELCULLUMUK
MACHINE LEARNING

8. @MICHAELCULLUMUK
LEARNING
Cause
&
Effect
Context
Process Knowledge

9. @MICHAELCULLUMUK
USING
Cause
Knowledge
Process
Prediction
of an
effect

10. @MICHAELCULLUMUK
Cause
Knowledge
Process
Process
Cause
Predicted
effect
Effect

11. @MICHAELCULLUMUK
EXAMPLE
1+1= 2
1+2= 3
1+3= 4
2+1= 3
3+1= 4
Cause Effect

12. @MICHAELCULLUMUK
EXAMPLE
1+1= 2
1+2= 3
1+3= 4
2+1= 3
3+1= 4
Knowledge

13. @MICHAELCULLUMUK
EXAMPLE
1+1= 2
1+2= 3
1+3= 4
2+1= 3
3+1= 4
Cause
3+1=
Predicted Effect
4
Knowledge

14. @MICHAELCULLUMUK
INFERENCE
1x + 3 = 4
1x + 4 = 6
1x + 3 = 5
2 + 3x = 8
1x + 4 = ?
x = 10
Multiply by 2
Multiply by 1 Multiply by 2
Multiply by 2

15. @MICHAELCULLUMUK
INFERENCE
“eggs”

16. @MICHAELCULLUMUK
MACHINE LEARNING AS
A 4-STEP PROCESS

17. @MICHAELCULLUMUK
1. ACQUIRE DATA

18. @MICHAELCULLUMUK
2. TRAIN MODEL

19. @MICHAELCULLUMUK

20. @MICHAELCULLUMUK
4. GET PREDICTED

21. @MICHAELCULLUMUK
1. ACQUIRE DATA

22. @MICHAELCULLUMUK
GOOD LUCK

23. @MICHAELCULLUMUK
2. TRAIN MODEL

24. @MICHAELCULLUMUK
SUPERVISED LEARNING
UNSUPERVISED LEARNING

25. @MICHAELCULLUMUK
SUPERVISED LEARNING

26. @MICHAELCULLUMUK
KNOWN OUTCOMES

27. @MICHAELCULLUMUK
QUANTATIVE - CLASSIFICATION
QUALITATIVE - REGRESSION

28. @MICHAELCULLUMUK
QUANTATIVE - CLASSIFICATION
QUALITATIVE - REGRESSION

29. @MICHAELCULLUMUK
CLASSIFICATION
Rating Conclusion
100 Good
50 Good

30. @MICHAELCULLUMUK
CLASSIFICATION
Rating Conclusion
100 Good
50 Good

31. @MICHAELCULLUMUK
LINEAR CLASSIFIER
Item Value
Black
PHP
Devs
White Sales
Sales Test
PHP Test

32. @MICHAELCULLUMUK
QUANTATIVE - CLASSIFICATION
QUALITATIVE - REGRESSION

33. @MICHAELCULLUMUK
REGRESSION
Price Size
5.00 8.25
6.00 10
4.00 6.75
3.00 5
0
2.5
5
7.5
10
0 1.5 3 4.5 6
Price
Size

34. @MICHAELCULLUMUK
REGRESSION
Price Size
5.00 8.25
6.00 10
4.00 6.75
3.00 5
0
2.5
5
7.5
10
0 1.5 3 4.5 6
Price
Price
Size

35. @MICHAELCULLUMUK
UNSUPERVISED
LEARNING

36. @MICHAELCULLUMUK
DISCOVERY

37. @MICHAELCULLUMUK
ASSOCIATION
CLUSTERING

38. @MICHAELCULLUMUK
ASSOCIATION
CLUSTERING

39. @MICHAELCULLUMUK
ASSOCIATION
Item 1 Item 2
T-shirt Shorts
Shorts T-shirt
Suit Black Shoes
Socks Underwear
Item 1 Item 2
Black shoes Suit
Socks Underwear
Underwear Socks
T-shirt Socks

40. @MICHAELCULLUMUK
ASSOCIATION
Item 1 Item 2
T-shirt Shorts
Shorts T-shirt
Suit Black Shoes
Socks Underwear
Item 1 Item 2
Black shoes Suit
Socks Underwear
Underwear Socks
T-shirt Socks
socks

41. @MICHAELCULLUMUK
ASSOCIATION
Item 1 Item 2
T-shirt Shorts
Shorts T-shirt
Suit Black Shoes
Socks Underwear
Item 1 Item 2
Black shoes Suit
Socks Underwear
Underwear Socks
T-shirt Socks
socks

42. @MICHAELCULLUMUK
ASSOCIATION
Item 1 Item 2
T-shirt Shorts
Shorts T-shirt
Suit Black Shoes
Socks Underwear
Item 1 Item 2
Black shoes Suit
Socks Underwear
Underwear Socks
T-shirt Socks
socks

43. @MICHAELCULLUMUK
ASSOCIATION
CLUSTERING

44. @MICHAELCULLUMUK
CLUSTER ANALYSIS IS THE TASK OF
GROUPING A SET OF OBJECTS IN SUCH A
WAY THAT OBJECTS IN THE SAME GROUP
ARE MORE SIMILAR TO EACH OTHER
THAN TO THOSE IN OTHER GROUPS.

45. @MICHAELCULLUMUK
CLUSTER ANALYSIS

46. @MICHAELCULLUMUK
3. QUESTION

47. @MICHAELCULLUMUK
ALGORITHMS

48. @MICHAELCULLUMUK
LEAST SQUARES

49. @MICHAELCULLUMUK
LEAST SQUARES REGRESSION LINE

50. @MICHAELCULLUMUK
MATHS

51. @MICHAELCULLUMUK
A+BX=Y

52. @MICHAELCULLUMUK
▸ Each point has an x and y value
▸ We need an equation of a line
▸ We move the line an inﬁnite number of times
▸ Each time, we draw a box between every point, and the line, with one corner
on the line, and another on the point
▸ The correct line is the one where the sum of the area of all the squares is
smallest
PROCESS

53. @MICHAELCULLUMUK
DEMO

54. @MICHAELCULLUMUK
PHP

55. @MICHAELCULLUMUK
DEMO

56. @MICHAELCULLUMUK
DEMOS
php-ai/php-ml

57. @MICHAELCULLUMUK
CODE
\$samples = [[60], [61], [62], [63], [65]];
\$targets = [3.1, 3.6, 3.8, 4, 4.1];
\$regression = new LeastSquares();
\$regression->train(\$samples, \$targets);
echo \$regression->predict([64]);

58. @MICHAELCULLUMUK
STEPS
▸ Turn samples into a matrix (X)
▸ Turn targets into a matrix (y)
▸ Transpose the samples matrix (XT)
▸ Multiply it by itself (XTX) and then inverse the matrix ((XTX)-1); and multiply the
transposed samples matrix (XT) by the targets matrix (XTy)
▸ Multiply those two matrices together ((XTX)-1 (XTy)) and read off the ﬁrst
column to get your coefﬁcent(s) and intercept (β1
)

59. @MICHAELCULLUMUK
NEAREST NEIGHBOUR

60. @MICHAELCULLUMUK
NEAREST NEIGHBOUR

61. @MICHAELCULLUMUK
3-NEAREST NEIGHBOUR

62. @MICHAELCULLUMUK
5-NEAREST NEIGHBOUR

63. @MICHAELCULLUMUK
MATHS

64. @MICHAELCULLUMUK
PHP

65. @MICHAELCULLUMUK
DEMO

66. @MICHAELCULLUMUK
DEMO
0
1
2
3
4
0 1 2 3 4
A - red
B - blue

67. @MICHAELCULLUMUK
DEMO
0
1.25
2.5
3.75
5
0 1 2 3 4
A - red
B - blue

68. @MICHAELCULLUMUK
DEMO
\$samples = [[1, 3], [1, 4], [2, 4], [3, 1], [4, 1], [4, 2]];
\$labels = ['a', 'a', 'a', 'b', 'b', 'b'];
\$classifier = new KNearestNeighbors();
\$classifier->train(\$samples, \$labels);
echo \$classifier->predict([3, 2]);

69. @MICHAELCULLUMUK
USES OF MACHINE
LEARNING

70. @MICHAELCULLUMUK
NUMERICAL ANALYSIS

71. @MICHAELCULLUMUK
EXCEPTIONS

72. @MICHAELCULLUMUK
E-COMMERCE

73. @MICHAELCULLUMUK
FAULT DETECTION

74. @MICHAELCULLUMUK
ROOT CAUSE ANALYSIS

75. @MICHAELCULLUMUK
CLASSIFICATION

76. @MICHAELCULLUMUK
NATURAL LANGUAGE
PROCESSING

77. @MICHAELCULLUMUK
ANALYSIS OF SUPPORT
QUERIES

78. @MICHAELCULLUMUK
ANALYSIS OF LARGE
NUMBERS OF DOCUMENTS

79. @MICHAELCULLUMUK
FUN

80. THANKS - DANK JE
@MICHAELCULLUMUK

81. @MICHAELCULLUMUK
ANY QUESTIONS?

82. TREND ANALYSIS AND MACHINE
LEARNING IN PHP
DUTCH PHP CONFERENCE 2018
@MICHAELCULLUMUK