SlideShare a Scribd company logo
1
AI Machine Learning – The Complete
Course: for PHP & Python Developers
https://www.udemy.com/ai-machine-learning-complete-
course/
2
Section 1
Understanding AI & Machine Learning
3
Artificial IntelligenceIt is Everywhere
Top Trending Technology
Used Everywhere
• Websites
• Mobile Apps
• Chat-bots
• Search Engines
• & Much More!
4
1956
Founded as an
Academic
Discipline
Studied By
Researchers
1943
Artificial IntelligenceHistory
5
What is Artificial Intelligence?Definition
Any technology that makes
machines process or respond to
data in human like ways, so the
machine can simulate human
behavior such as learning, and
problem solving.
6
Artificial Intelligence ApproachesThere are many approaches
Machine Learning
Rule-Based AI
a.k.a. Symbolic Reasoning
a.k.a. GOFAI
There are many approaches to mimic human
intelligence, but the most common are
7
Logic & Rule Based AIThe Good Old-Fashioned AI
Set of rules, logic, like a nested “if .. Else .. “
statements
1. If someone has a "threat" (that is, two in a row), take the remaining square. Otherwise,
2. if a move "forks" to create two threats at once, play that move. Otherwise,
3. take the center square if it is free. Otherwise,
4. if your opponent has played in a corner, take the opposite corner. Otherwise,
5. take an empty corner if one exists. Otherwise,
6. take any empty square.
Example – Tic-tac-toe
8
Machine LearningThe dominant approach for AI today
A computer program finds patterns in data and
create its own rules. Basically Learns from
historical data
There are four types of machine learning algorithms:
supervised, semi-supervised, unsupervised and
reinforcement
Machine Learning can be done using many
algorithms
9
Section 2
Machine Learning Types & Algorithms
10
Machine Learning TypesJust as a reference
Supervised
Learning
Classificatio
n
Regression
Forecasting
Semi-
supervised
Learning
Unsupervised
Learning
Clustering
Dimension
Reduction
Reinforcement
Learning
11
Machine Learning AlgorithmsJust as a reference
1. Naïve Bayes
2. K Means
3. Support Vector Machine
(SVM)
4. Linear Regression
5. Logistic Regression
6. Decision Trees
7. Random Forests
8. Nearest Neighbors
9. Neural Networks
Simple Example of a Neural Network
12
What Algorithm Should I Use?
The Cheat Sheet
13
14
What to ConcludeMind Map
AI (Artificial Intelligence)
Machine Learning
Neural
Networks
SVM ...
Rule-Based
AI ...
15
Section 3
Coding Example: Dominant Color
Detector (Neural Networks Algorithm)
16
Let’s Code
The Fun Part 
17
Dominant Color DetectorReal world example for an AI Application in PHP
Our Neural Network
Each Machine Learning Program
Generally Consists of:
• Training
• Prediction
18
Dominant Color DetectorReal world example for an AI Application in PHP
For this example, we want to give the AI program the color code for any color, and it
gives us what is the dominant primary color in that color. Pretty cool.
For Example, the dominant color for this is blue
19
Dominant Color Detector - PlanningLet’s plan our code
train predict
1. Build the network
2. Read test data
3. Train the network
4. Save the trained network to
a file
1. Restore the trained network from
the file
2. Pass a completely new input
3. Observe the network output
20
Dominant Color Detector - PlanningThe Network
R
G
B
Three Inputs
Activatio
n
function
PReLU
Activatio
n
function
Sigmoid
2 Hidden Layers – 4 Neurons Each
Output is
either “red”,
“blue”, or
“green”
21
PHP-MLA wonderful Machine Learning Library
For this example, we will use a library called PHP-ML (https://github.com/php-ai/php-
ml), this library is a fresh approach to Machine Learning in PHP. Algorithms, Cross
Validation, Neural Network, Preprocessing, Feature Extraction and much more in that
library.
Requirements:
1. PHP7.1+
2. Apache
3. Composer
22
Code Lab – Dominant Color Detector
Fingers Crossed
23
Artificial IntelligenceThink of the Possibilities
YES! You have now done your
first complete AI Machine
Learning application, and using
Neural Networks!
You Can Do More!
24
Section 4
Coding Example: Language Detection
(Support Vector Machine Algorithm)
25
Language DetectionReal world example for an AI Application in PHP
Sample Data:
"sentence","language"
"Hello, do you know what time the movie is tonight?","english"
"Vérifiez la batterie, s'il vous plaît.","french"
"A che ora sara' la prossima raccolta?","italian"
CSV
26
Language DetectionFeature Extraction
Text, Image, Video, or
Voice
Numerical
Representation
27
Language DetectionFeature Extraction
Brown
Eyes
Black
Eyes
Long
Ears
Black
Fur
White
Fur
Image
1
1 0 1 1 0
Image
2
1 0 0 0 1
Image
3
0 1 1 1 0
Image
4
0 1 0 0 1
28
Language DetectionFeature Extraction
Text Data Count Vectorizer TFIDF Transformer Numerical
Vectors
Word Counter
We will use Kernel SVM Algorithm
29
Code Lab – Language Detector
Fingers Crossed
30
Applications!Tweeter Analysis
31
Section 5
Python & PHP
32
Python & PHPWhat we can do!
33
Python & PHPWhat we can do!
Python was build in a light core, and lots of packages
PHP is a powerful web development language
exec("python
mypythonscript.py",$output);
var_dump($output);
Python REST API
34
Python SyntaxCrash Course
Python files doesn’t start with anything special, just
write code directly “unlike php which requires <?php
at the beginning or something similar”. And the
Python files have the extension .py
Python files cannot run from the browser directly, it
needs a web framework, we are not going to
explain this for now, but the way you can use
Python easily “and the most common” is from
command line like this “python mypythonscript.py”
35
Python SyntaxCrash Course
You can download and install Python from the official
Python website (https://www.python.org/downloads/)
and the install is very easy, after that you can just go
to command line navigate to your Python file and run
it with the “python” command. More info on
installation from here
(https://realpython.com/installing-python/)
36
Python SyntaxCrash Course
No semi column at the end of the statement, it is
optional, but strongly recommended not to use it
New line indicates a new statement
For comments Python uses “#” at the beginning of
each line, it doesn’t have multi-line comments
37
Python SyntaxCrash Course
Some basic Python data types are Numbers, String, Tuple
“like array but immutable”, List, Dictionary. The first three
are immutable. List and Dictionary are mutable. List is
ordered, but Dictionary is not
In PHP you include files with “include, require, include_once,
require_once”, in Python you can include using “import,
__import__(), and importlib.import_module()” (for example
“import sqlite3”, no paths here, once you install the module,
you can import it like that)
Whereas PHP uses NULL, Python uses None which can be
checked by “if foo is None”
38
Python SyntaxCrash Course
Print Statement
a. In PHP
print("Hello World");
b. In Python
print("Hello World")
39
Python SyntaxCrash Course
Echo Statement
a. In PHP
echo "Hello", " World";
b. In Python (no echo inPython)
print("Hello", "World")
40
Python SyntaxCrash Course
SwitchStatement
a. In PHP
$animal = "duck";
switch ( $animal ) {
case "duck": echo "two legs"; break;
case "cow": echo "four legs"; break;
default:
echo "don't know";
}
b. In Python (there is no switchstatement in Python, but you can do it withif .. elif .. else, elif here = elseif in PHP) (Adding a column at
the end of condition statements or for loops, examine below)
animal = "duck"
if animal == "duck":
print("two legs")
elif animal == "cow":
print("four legs")
else:
print("don't know")
Instead of “switch” inPython you canalso use dictionaries as follows, much easier:
animal = "duck"
legs = { "duck": "two legs", "cow": "four legs" }
if animal in legs:
print(legs[animal])
else:
print("don't know")
41
Python SyntaxCrash Course
Multi-line IF
a. In PHP
$x = 1;
if ($x == 1) {
$a = 1;
$b = 2;
$c = 3;
}
b. In Python (no { or }, just an indentation would indicate the if scoop, indentation
and spacing is very important in Python)
if x == 1:
a = 1
b = 2
c = 3
42
Python SyntaxCrash Course
Conditional Expressions
a. In PHP
$a = 7;
$b = 10;
echo ($a < $b) ? "a is less": "not";
b. In Python
a = 7
b = 10
print ("a is less" if a < b else "not")
43
Python SyntaxCrash Course
For Loops
a. In PHP
for ( $i = 0; $i < 10; $i++ ) {
echo $i;
}
b. In Python (range provides the condition out of the box) (the second parameter of
the print here means it will not print end of line after the printable because it
does by default)
for i in range(0,10):
print(i, end="")
44
Python SyntaxCrash Course
While Loops
a. In PHP
$i = 0;
while ($i < 10) {
echo $i;
$i++;
}
b. In Python (There is no ++ operator in Python, insteadit has +=)
i = 0
while ( i < 10 ):
print(i, end="")
i += 1
45
Python SyntaxCrash Course
Loop Through List
a. In PHP
$myList = array("duck", "cow", "sheep");
foreach ($myList as $animal) {
echo($animal);
}
b. In Python
myList = ["duck", "cow", "sheep"]
for animal in myList:
print(animal)
46
Python SyntaxCrash Course
Functions
a. In PHP
function main() {
sayHello("John");
}
function sayHello($person) {
echo ("Hello " . $person);
}
main();
b. In Python (it is easyto define functions) (InPython, you have anextra check, the __name__ will be = to “__main__” only if the file
itself was executed and not imported from another file, so you can have more control on when to run the mainfunction or not)
def main():
sayHello("John")
def sayHello(person):
print("Hello", person)
if __name__ == "__main__":
main()
47
Python SyntaxCrash Course
Classes
a. In PHP
class Person {
var $name;
function __construct($name) {
$this->name = $name;
}
function sayHi() {
echo('Hello, my name is ' . $this->name);
}
}
$p = new Person('John');
$p->sayHi();
b. In Python (self is like $this, but you need to pass it in every function)
class Person:
def __init__(self, name):
self.name = name
def sayHi(self):
print('Hello, my name is', self.name)
# this is outside the class, notice indentation changed.
p = Person('John')
p.sayHi()
48
Python & PHPWell Done!
49
Section 6
Coding Example: Simple Neural
Network (Built from scratch without
libraries!)
50
Simple Neural Network - PythonTraining Machine Learning Example
51
Simple Neural Network - TrainingTraining Algorithm
L1 - Input
L2 - Output
Random
Weight
Random
Weight
Random
Weight
1. Forward Propagation
2. Back Propagation
52
Output Calculation – ForwardLet’s do the Math
1. Forward Propagation
2. Normalize Output (Between 0 and 1)
Sigmoid
3. Together, the output becomes
53
Weight Adjustment – BackwardLet’s do the Math
2. Backward
Propagation
1. Calculate Error (output is predicated output by the
network)
𝑒𝑟𝑟𝑜𝑟 = 𝑜𝑢𝑡𝑝𝑢𝑡 𝑓𝑟𝑜𝑚 𝑡𝑟𝑎𝑖𝑛𝑖𝑛𝑔 − 𝑜𝑢𝑡𝑝𝑢𝑡
54
numpyPython’s Math
• exp— the natural exponential
• array — creates a matrix
• dot — multiplies matrices
• random — gives us random numbers
training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]])
training_set_outputs = array([[0, 1, 1, 0]]).T
0 0 1
1 1 1
1 0 1
0 1 1
0
1
1
0
55
Code Lab – Simple Python Neural Network
Fingers Crossed
56
Well Done!Think of the Possibilities
And we have a neural network now done with Python! A simple
one!
What about this one?
57
XOR AssignmentFor you to workout!
58
Section 7
Important Neural Networks Concepts
59
New ConceptsThere are More!
Activation Functions
Sigmoid
60
New ConceptsThere are More!
Input Dimension
61
New ConceptsThere are More!
Dense Layer & Dropout Layer
62
New ConceptsThere are More!
63
New ConceptsThere are More!
Learning Rate
64
New ConceptsThere are More!
Model Loss
65
New ConceptsThere are More!
Epoch
Batch
1
Batch
2
Batch
3
...
Batch
n
Batch
Sample
1
Sample
2
Sample
3
...
Sample
n
Epoch & Batch Size
66
New ConceptsThere are More!
Training Data vs Validation Data vs Test Data
for each epoch
for each training data instance
- propagate error through the network
- adjust the weights
- calculate the accuracy over training data
for each validation data instance
calculate the accuracy over the validation
data
If the accuracy over the training data set
increases, but the accuracy over the validation
data set stays the same or decreases
exit training
else
continue training
67
New ConceptsThere are More!
Training Data vs Validation Data vs Test
Data
Dataset
Count
Testing Part (0.2) Training Part (0.8)
1,000 = 1,000 * 0.2 = 200 = 1,000 * 0.8 = 800
Validation Portion
(0.1)
Training Portion (0.9)
= 800 * 0.1 = 80 = 800 * 0.9 = 720
For example, if we have 1000 data samples
68
Section 8
Coding Example: Language Detection
with Google's TensorFlow (Real-world
example)
69
TensorFlowLet’s go further!
70
Language Detection - TensorFlowA real world Deep Neural Networks Example
Lots of Data
High Accuracy
Language
Detection
Deep Neural Network
71
Language DetectionFeature Extraction
Text Data Count Vectorizer
Standard Scaler
Transformation
Numerical
Vectors
Letter Counter
We will identify: English, French, Spanish, Italian, German, Slovak, Czech
72
The DataThanks Wikipedia!
Downloaded from
https://dumps.wikimedia.org/
Then Extracted to txt using
http://medialab.di.unipi.it/wiki/Wikipedia_Extractor
I generated 7 files 1 for each language, 204 MB each!!
I gave you 5 files only
73
Code Lab – TensorFlow Language Detection
Fingers Crossed
74
Data CountsTo Clarify
Training Data vs Validation Data vs Test
Data
Dataset Count per
Language
Total Dataset
Count (we have
data for 5
languages)
Testing Part (0.2) Training Part (0.8)
250,000
= 5 * 250,000 =
1,250,000
= 1,250,000 * 0.2 =
250,000
= 1,250,000 * 0.8 = 1,000,000
Validation Portion
(0.1)
Training Portion (0.9)
= 1,000,000 * 0.1 =
100,000
= 1,000,000 * 0.9 =
900,000
75
AWESOME!We did it, again!
Accuracy
98%
Machine learning train part is from lines 315-330
(just 11 lines of code!) and the predict code is from
396-406 (10 lines of code!) the remaining code is
for:
Data cleaning (custom function)
Text vectorization (custom function)
Text Transformation (from library)
Evaluation, reporting, and plotting
76
Section 9
TensorFlow Hub
77
Machine Learning is FunYou can apply it everywhere!
1. Get training data for your problem.
2. Convert those data into numerical vectors.
3. Train the network.
4. Predict!
78
TensorFlow HubDon’t Reinvent the Wheel
https://alpha.tfhub.dev/
79
Code Lab – TensorFlow Hub Examples
Fingers Crossed
80
Bonus: Section 10
Bonus Section: Building a
Neural Network using Plain
Math
81
Building Neural NetworksManually!
82
Building Neural NetworksManually!
We will walk through a simple example of training a
neural network to function as an “Exclusive OR”
(“XOR”) operation to illustrate each step in the
training process.
input | output
-------------------
0, 0 | 0
0, 1 | 1
1, 0 | 1
1, 1 | 0
83
Building Neural NetworksManually!
84
Building Neural NetworksManually!
85
Building Neural NetworksManually!
1 * 0.8 + 1 * 0.2 = 1
1 * 0.4 + 1 * 0.9 = 1.3
1 * 0.3 + 1 * 0.5 = 0.8
86
Building Neural NetworksManually!
87
Building Neural NetworksManually!
88
Building Neural NetworksManually!
S(1.0) = 0.73105857863
S(1.3) = 0.78583498304
S(0.8) = 0.68997448112
89
Building Neural NetworksManually!
0.73 * 0.3 + 0.79 * 0.5 + 0.69 * 0.9 = 1.235
S(1.235) = 0.7746924929149283
90
Building Neural NetworksManually!
Output sum margin of error = target – calculated
Target = 0
Calculated = 0.77
Output sum margin of error = Target – calculated = -
0.77
𝑆′
𝑠𝑢𝑚 =
𝑑𝑠𝑢𝑚
𝑑𝑟𝑒𝑠𝑢𝑙𝑡
𝑑𝑠𝑢𝑚
𝑑𝑟𝑒𝑠𝑢𝑙𝑡
× 𝑡𝑎𝑟𝑔𝑒𝑡 𝑟𝑒𝑠𝑢𝑙𝑡 − 𝑐𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑒𝑑 𝑟𝑒𝑠𝑢𝑙𝑡 = ∆𝑠𝑢𝑚
Delta output sum = S'(sum) * (output sum margin of error)
Delta output sum = S'(1.235) * (-0.77)
Delta output sum = -0.13439890643886018
91
Building Neural NetworksManually!
92
Building Neural NetworksManually!
𝐻𝑟𝑒𝑠𝑢𝑙𝑡 × 𝑊ℎ→𝑜 = 𝑂𝑠𝑢𝑚
𝑑𝑂𝑠𝑢𝑚
𝑑𝑤ℎ→𝑜
= 𝐻𝑟𝑒𝑠𝑢𝑙𝑡𝑠
hidden result 1 = 0.73105857863
hidden result 2 = 0.78583498304
hidden result 3 = 0.68997448112
Delta weights = delta output sum / hidden layer results
Delta weights = -0.1344 / [0.73105, 0.78583, 0.69997]
Delta weights = [-0.1838, -0.1710, -0.1920]
old w7 = 0.3
old w8 = 0.5
old w9 = 0.9
new w7 = 0.1162
new w8 = 0.329
new w9 = 0.708
𝑑𝑤ℎ→𝑜 =
𝑑𝑂𝑠𝑢𝑚
𝐻𝑟𝑒𝑠𝑢𝑙𝑡𝑠
93
Building Neural NetworksManually!
𝐻𝑟𝑒𝑠𝑢𝑙𝑡 × 𝑊ℎ→𝑜 = 𝑂𝑠𝑢𝑚
𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 =
𝑑𝑂𝑠𝑢𝑚
𝑤ℎ→𝑜
𝑆′
𝐻𝑠𝑢𝑚 =
𝑑𝐻𝑠𝑢𝑚
𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡
𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡
𝑑𝑂𝑠𝑢𝑚
=
1
𝑤ℎ→𝑜
𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 ×
𝑑𝐻𝑠𝑢𝑚
𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡
=
𝑑𝑂𝑠𝑢𝑚
𝑤ℎ→𝑜
×
𝑑𝐻𝑠𝑢𝑚
𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡
𝑑𝐻𝑠𝑢𝑚 =
𝑑𝑂𝑠𝑢𝑚
𝑤ℎ→𝑜
× 𝑆′(𝐻𝑠𝑢𝑚)
Delta hidden sum
= delta output sum / hidden-to-outer weights * S'(hidden sum
Delta hidden sum
= -0.1344 / [0.3, 0.5, 0.9] * S'([1, 1.3, 0.8])
Delta hidden sum
= [-0.448, -0.2688, -0.1493] * [0.1966, 0.1683, 0.2139]
Delta hidden sum
= [-0.088, -0.0452, -0.0319]
94
Building Neural NetworksManually!
𝐼 × 𝑤𝑖→ℎ = 𝐻𝑠𝑢𝑚
𝑑𝑤𝑖→ℎ =
𝑑𝐻𝑠𝑢𝑚
𝐼
𝑑𝐻𝑠𝑢𝑚
𝑑𝑤𝑖→ℎ
= 𝐼
input 1 = 1
input 2 = 1
Delta weights = delta hidden sum / input data
Delta weights = [-0.088, -0.0452, -0.0319] / [1, 1]
Delta weights = [-0.088, -0.0452, -0.0319, -0.088, -0.0452, -0.0319]
old w1 = 0.8 new w1 = 0.712
old w2 = 0.4 new w2 = 0.3548
old w3 = 0.3 new w3 = 0.2681
old w4 = 0.2 new w4 = 0.112
old w5 = 0.9 new w5 = 0.8548
old w6 = 0.5 new w6 = 0.4681
95
Building Neural NetworksManually!
old new
--------------------------
w1: 0.8 w1: 0.712
w2: 0.4 w2: 0.3548
w3: 0.3 w3: 0.2681
w4: 0.2 w4: 0.112
w5: 0.9 w5: 0.8548
w6: 0.5 w6: 0.4681
w7: 0.3 w7: 0.1162
w8: 0.5 w8: 0.329
w9: 0.9 w9: 0.708
96
Well Done!
You have successfully started
your AI journey! Keep going!
I would love to help
Keep in Touch
linkedin.com/in/amrshawqy
twitter.com/amrshawqy

More Related Content

What's hot

Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
Chariza Pladin
 
Python and Machine Learning
Python and Machine LearningPython and Machine Learning
Python and Machine Learning
trygub
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
Pragati Singh
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
H2Kinfosys
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Edureka!
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
Eueung Mulyana
 
Python interview question for students
Python interview question for studentsPython interview question for students
Python interview question for students
Corey McCreary
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Edureka!
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
Vijay Chaitanya
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
ParrotAI
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
MAHALAKSHMI P
 
Most Asked Python Interview Questions
Most Asked Python Interview QuestionsMost Asked Python Interview Questions
Most Asked Python Interview Questions
Shubham Shrimant
 
PyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimePyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtime
National Cheng Kung University
 
Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its Applications
Abhijeet Singh
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
Samir Mohanty
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
AkramWaseem
 
Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)
IoT Code Lab
 
C pythontalk
C pythontalkC pythontalk
C pythontalk
Nicholaus Jackson
 
Introduction of python
Introduction of pythonIntroduction of python
Introduction of python
ShehabAldeenFadelall
 
Python ppt
Python pptPython ppt
Python ppt
Rachit Bhargava
 

What's hot (20)

Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
 
Python and Machine Learning
Python and Machine LearningPython and Machine Learning
Python and Machine Learning
 
Python interview questions
Python interview questionsPython interview questions
Python interview questions
 
Python Interview Questions And Answers
Python Interview Questions And AnswersPython Interview Questions And Answers
Python Interview Questions And Answers
 
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | EdurekaPython Tutorial | Python Tutorial for Beginners | Python Training | Edureka
Python Tutorial | Python Tutorial for Beginners | Python Training | Edureka
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Python interview question for students
Python interview question for studentsPython interview question for students
Python interview question for students
 
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
Python Tutorial For Beginners | Python Crash Course - Python Programming Lang...
 
Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning Introduction to Python for Data Science and Machine Learning
Introduction to Python for Data Science and Machine Learning
 
Python_in_Detail
Python_in_DetailPython_in_Detail
Python_in_Detail
 
Most Asked Python Interview Questions
Most Asked Python Interview QuestionsMost Asked Python Interview Questions
Most Asked Python Interview Questions
 
PyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtimePyPy's approach to construct domain-specific language runtime
PyPy's approach to construct domain-specific language runtime
 
Python and its Applications
Python and its ApplicationsPython and its Applications
Python and its Applications
 
Overview of python 2019
Overview of python 2019Overview of python 2019
Overview of python 2019
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)Chapter 0 Python Overview (Python Programming Lecture)
Chapter 0 Python Overview (Python Programming Lecture)
 
C pythontalk
C pythontalkC pythontalk
C pythontalk
 
Introduction of python
Introduction of pythonIntroduction of python
Introduction of python
 
Python ppt
Python pptPython ppt
Python ppt
 

Similar to AI Machine Learning Complete Course: for PHP & Python Devs

05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
SugumarSarDurai
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425
Sapna Tyagi
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
Dozie Agbo
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
Kris Findlay
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
gmadhu8
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
Shivam Gupta
 
Python
PythonPython
Python
Shivam Gupta
 
python into.pptx
python into.pptxpython into.pptx
python into.pptx
Punithavel Ramani
 
Python Course
Python CoursePython Course
Python Course
Sourabh Sahu
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
aeberspaecher
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
KingsleyAmankwa
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
Fariz Darari
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-intro
Ishaq Ali
 
Python ppt
Python pptPython ppt
Python ppt
Rohit Verma
 
py4inf-01-intro.ppt
py4inf-01-intro.pptpy4inf-01-intro.ppt
py4inf-01-intro.ppt
RosemeireArgentiniDe1
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
Mattupallipardhu
 
Python intro
Python introPython intro
Python intro
rik0
 
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdfThe Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
ssuser8b3cdd
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
RojaPriya
 
Doing the Impossible
Doing the ImpossibleDoing the Impossible
Doing the Impossible
Alexander Loechel
 

Similar to AI Machine Learning Complete Course: for PHP & Python Devs (20)

05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425Pythonanditsapplications 161121160425
Pythonanditsapplications 161121160425
 
First Steps in Python Programming
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
 
python-160403194316.pdf
python-160403194316.pdfpython-160403194316.pdf
python-160403194316.pdf
 
Python Seminar PPT
Python Seminar PPTPython Seminar PPT
Python Seminar PPT
 
Python
PythonPython
Python
 
python into.pptx
python into.pptxpython into.pptx
python into.pptx
 
Python Course
Python CoursePython Course
Python Course
 
Python For Scientists
Python For ScientistsPython For Scientists
Python For Scientists
 
Learn Python 3 for absolute beginners
Learn Python 3 for absolute beginnersLearn Python 3 for absolute beginners
Learn Python 3 for absolute beginners
 
Python in 30 minutes!
Python in 30 minutes!Python in 30 minutes!
Python in 30 minutes!
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-intro
 
Python ppt
Python pptPython ppt
Python ppt
 
py4inf-01-intro.ppt
py4inf-01-intro.pptpy4inf-01-intro.ppt
py4inf-01-intro.ppt
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
Python intro
Python introPython intro
Python intro
 
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdfThe Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
The Python Book_ The ultimate guide to coding with Python ( PDFDrive ).pdf
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Doing the Impossible
Doing the ImpossibleDoing the Impossible
Doing the Impossible
 

Recently uploaded

Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
aymanquadri279
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
Philip Schwarz
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
Remote DBA Services
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
kalichargn70th171
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Envertis Software Solutions
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
Hornet Dynamics
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 

Recently uploaded (20)

Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
What is Master Data Management by PiLog Group
What is Master Data Management by PiLog GroupWhat is Master Data Management by PiLog Group
What is Master Data Management by PiLog Group
 
Hand Rolled Applicative User Validation Code Kata
Hand Rolled Applicative User ValidationCode KataHand Rolled Applicative User ValidationCode Kata
Hand Rolled Applicative User Validation Code Kata
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Oracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptxOracle 23c New Features For DBAs and Developers.pptx
Oracle 23c New Features For DBAs and Developers.pptx
 
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf8 Best Automated Android App Testing Tool and Framework in 2024.pdf
8 Best Automated Android App Testing Tool and Framework in 2024.pdf
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative AnalysisOdoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
Odoo ERP Vs. Traditional ERP Systems – A Comparative Analysis
 
E-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet DynamicsE-commerce Development Services- Hornet Dynamics
E-commerce Development Services- Hornet Dynamics
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
Neo4j - Product Vision and Knowledge Graphs - GraphSummit Paris
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 

AI Machine Learning Complete Course: for PHP & Python Devs

  • 1. 1 AI Machine Learning – The Complete Course: for PHP & Python Developers https://www.udemy.com/ai-machine-learning-complete- course/
  • 2. 2 Section 1 Understanding AI & Machine Learning
  • 3. 3 Artificial IntelligenceIt is Everywhere Top Trending Technology Used Everywhere • Websites • Mobile Apps • Chat-bots • Search Engines • & Much More!
  • 4. 4 1956 Founded as an Academic Discipline Studied By Researchers 1943 Artificial IntelligenceHistory
  • 5. 5 What is Artificial Intelligence?Definition Any technology that makes machines process or respond to data in human like ways, so the machine can simulate human behavior such as learning, and problem solving.
  • 6. 6 Artificial Intelligence ApproachesThere are many approaches Machine Learning Rule-Based AI a.k.a. Symbolic Reasoning a.k.a. GOFAI There are many approaches to mimic human intelligence, but the most common are
  • 7. 7 Logic & Rule Based AIThe Good Old-Fashioned AI Set of rules, logic, like a nested “if .. Else .. “ statements 1. If someone has a "threat" (that is, two in a row), take the remaining square. Otherwise, 2. if a move "forks" to create two threats at once, play that move. Otherwise, 3. take the center square if it is free. Otherwise, 4. if your opponent has played in a corner, take the opposite corner. Otherwise, 5. take an empty corner if one exists. Otherwise, 6. take any empty square. Example – Tic-tac-toe
  • 8. 8 Machine LearningThe dominant approach for AI today A computer program finds patterns in data and create its own rules. Basically Learns from historical data There are four types of machine learning algorithms: supervised, semi-supervised, unsupervised and reinforcement Machine Learning can be done using many algorithms
  • 9. 9 Section 2 Machine Learning Types & Algorithms
  • 10. 10 Machine Learning TypesJust as a reference Supervised Learning Classificatio n Regression Forecasting Semi- supervised Learning Unsupervised Learning Clustering Dimension Reduction Reinforcement Learning
  • 11. 11 Machine Learning AlgorithmsJust as a reference 1. Naïve Bayes 2. K Means 3. Support Vector Machine (SVM) 4. Linear Regression 5. Logistic Regression 6. Decision Trees 7. Random Forests 8. Nearest Neighbors 9. Neural Networks Simple Example of a Neural Network
  • 12. 12 What Algorithm Should I Use? The Cheat Sheet
  • 13. 13
  • 14. 14 What to ConcludeMind Map AI (Artificial Intelligence) Machine Learning Neural Networks SVM ... Rule-Based AI ...
  • 15. 15 Section 3 Coding Example: Dominant Color Detector (Neural Networks Algorithm)
  • 17. 17 Dominant Color DetectorReal world example for an AI Application in PHP Our Neural Network Each Machine Learning Program Generally Consists of: • Training • Prediction
  • 18. 18 Dominant Color DetectorReal world example for an AI Application in PHP For this example, we want to give the AI program the color code for any color, and it gives us what is the dominant primary color in that color. Pretty cool. For Example, the dominant color for this is blue
  • 19. 19 Dominant Color Detector - PlanningLet’s plan our code train predict 1. Build the network 2. Read test data 3. Train the network 4. Save the trained network to a file 1. Restore the trained network from the file 2. Pass a completely new input 3. Observe the network output
  • 20. 20 Dominant Color Detector - PlanningThe Network R G B Three Inputs Activatio n function PReLU Activatio n function Sigmoid 2 Hidden Layers – 4 Neurons Each Output is either “red”, “blue”, or “green”
  • 21. 21 PHP-MLA wonderful Machine Learning Library For this example, we will use a library called PHP-ML (https://github.com/php-ai/php- ml), this library is a fresh approach to Machine Learning in PHP. Algorithms, Cross Validation, Neural Network, Preprocessing, Feature Extraction and much more in that library. Requirements: 1. PHP7.1+ 2. Apache 3. Composer
  • 22. 22 Code Lab – Dominant Color Detector Fingers Crossed
  • 23. 23 Artificial IntelligenceThink of the Possibilities YES! You have now done your first complete AI Machine Learning application, and using Neural Networks! You Can Do More!
  • 24. 24 Section 4 Coding Example: Language Detection (Support Vector Machine Algorithm)
  • 25. 25 Language DetectionReal world example for an AI Application in PHP Sample Data: "sentence","language" "Hello, do you know what time the movie is tonight?","english" "Vérifiez la batterie, s'il vous plaît.","french" "A che ora sara' la prossima raccolta?","italian" CSV
  • 26. 26 Language DetectionFeature Extraction Text, Image, Video, or Voice Numerical Representation
  • 28. 28 Language DetectionFeature Extraction Text Data Count Vectorizer TFIDF Transformer Numerical Vectors Word Counter We will use Kernel SVM Algorithm
  • 29. 29 Code Lab – Language Detector Fingers Crossed
  • 32. 32 Python & PHPWhat we can do!
  • 33. 33 Python & PHPWhat we can do! Python was build in a light core, and lots of packages PHP is a powerful web development language exec("python mypythonscript.py",$output); var_dump($output); Python REST API
  • 34. 34 Python SyntaxCrash Course Python files doesn’t start with anything special, just write code directly “unlike php which requires <?php at the beginning or something similar”. And the Python files have the extension .py Python files cannot run from the browser directly, it needs a web framework, we are not going to explain this for now, but the way you can use Python easily “and the most common” is from command line like this “python mypythonscript.py”
  • 35. 35 Python SyntaxCrash Course You can download and install Python from the official Python website (https://www.python.org/downloads/) and the install is very easy, after that you can just go to command line navigate to your Python file and run it with the “python” command. More info on installation from here (https://realpython.com/installing-python/)
  • 36. 36 Python SyntaxCrash Course No semi column at the end of the statement, it is optional, but strongly recommended not to use it New line indicates a new statement For comments Python uses “#” at the beginning of each line, it doesn’t have multi-line comments
  • 37. 37 Python SyntaxCrash Course Some basic Python data types are Numbers, String, Tuple “like array but immutable”, List, Dictionary. The first three are immutable. List and Dictionary are mutable. List is ordered, but Dictionary is not In PHP you include files with “include, require, include_once, require_once”, in Python you can include using “import, __import__(), and importlib.import_module()” (for example “import sqlite3”, no paths here, once you install the module, you can import it like that) Whereas PHP uses NULL, Python uses None which can be checked by “if foo is None”
  • 38. 38 Python SyntaxCrash Course Print Statement a. In PHP print("Hello World"); b. In Python print("Hello World")
  • 39. 39 Python SyntaxCrash Course Echo Statement a. In PHP echo "Hello", " World"; b. In Python (no echo inPython) print("Hello", "World")
  • 40. 40 Python SyntaxCrash Course SwitchStatement a. In PHP $animal = "duck"; switch ( $animal ) { case "duck": echo "two legs"; break; case "cow": echo "four legs"; break; default: echo "don't know"; } b. In Python (there is no switchstatement in Python, but you can do it withif .. elif .. else, elif here = elseif in PHP) (Adding a column at the end of condition statements or for loops, examine below) animal = "duck" if animal == "duck": print("two legs") elif animal == "cow": print("four legs") else: print("don't know") Instead of “switch” inPython you canalso use dictionaries as follows, much easier: animal = "duck" legs = { "duck": "two legs", "cow": "four legs" } if animal in legs: print(legs[animal]) else: print("don't know")
  • 41. 41 Python SyntaxCrash Course Multi-line IF a. In PHP $x = 1; if ($x == 1) { $a = 1; $b = 2; $c = 3; } b. In Python (no { or }, just an indentation would indicate the if scoop, indentation and spacing is very important in Python) if x == 1: a = 1 b = 2 c = 3
  • 42. 42 Python SyntaxCrash Course Conditional Expressions a. In PHP $a = 7; $b = 10; echo ($a < $b) ? "a is less": "not"; b. In Python a = 7 b = 10 print ("a is less" if a < b else "not")
  • 43. 43 Python SyntaxCrash Course For Loops a. In PHP for ( $i = 0; $i < 10; $i++ ) { echo $i; } b. In Python (range provides the condition out of the box) (the second parameter of the print here means it will not print end of line after the printable because it does by default) for i in range(0,10): print(i, end="")
  • 44. 44 Python SyntaxCrash Course While Loops a. In PHP $i = 0; while ($i < 10) { echo $i; $i++; } b. In Python (There is no ++ operator in Python, insteadit has +=) i = 0 while ( i < 10 ): print(i, end="") i += 1
  • 45. 45 Python SyntaxCrash Course Loop Through List a. In PHP $myList = array("duck", "cow", "sheep"); foreach ($myList as $animal) { echo($animal); } b. In Python myList = ["duck", "cow", "sheep"] for animal in myList: print(animal)
  • 46. 46 Python SyntaxCrash Course Functions a. In PHP function main() { sayHello("John"); } function sayHello($person) { echo ("Hello " . $person); } main(); b. In Python (it is easyto define functions) (InPython, you have anextra check, the __name__ will be = to “__main__” only if the file itself was executed and not imported from another file, so you can have more control on when to run the mainfunction or not) def main(): sayHello("John") def sayHello(person): print("Hello", person) if __name__ == "__main__": main()
  • 47. 47 Python SyntaxCrash Course Classes a. In PHP class Person { var $name; function __construct($name) { $this->name = $name; } function sayHi() { echo('Hello, my name is ' . $this->name); } } $p = new Person('John'); $p->sayHi(); b. In Python (self is like $this, but you need to pass it in every function) class Person: def __init__(self, name): self.name = name def sayHi(self): print('Hello, my name is', self.name) # this is outside the class, notice indentation changed. p = Person('John') p.sayHi()
  • 49. 49 Section 6 Coding Example: Simple Neural Network (Built from scratch without libraries!)
  • 50. 50 Simple Neural Network - PythonTraining Machine Learning Example
  • 51. 51 Simple Neural Network - TrainingTraining Algorithm L1 - Input L2 - Output Random Weight Random Weight Random Weight 1. Forward Propagation 2. Back Propagation
  • 52. 52 Output Calculation – ForwardLet’s do the Math 1. Forward Propagation 2. Normalize Output (Between 0 and 1) Sigmoid 3. Together, the output becomes
  • 53. 53 Weight Adjustment – BackwardLet’s do the Math 2. Backward Propagation 1. Calculate Error (output is predicated output by the network) 𝑒𝑟𝑟𝑜𝑟 = 𝑜𝑢𝑡𝑝𝑢𝑡 𝑓𝑟𝑜𝑚 𝑡𝑟𝑎𝑖𝑛𝑖𝑛𝑔 − 𝑜𝑢𝑡𝑝𝑢𝑡
  • 54. 54 numpyPython’s Math • exp— the natural exponential • array — creates a matrix • dot — multiplies matrices • random — gives us random numbers training_set_inputs = array([[0, 0, 1], [1, 1, 1], [1, 0, 1], [0, 1, 1]]) training_set_outputs = array([[0, 1, 1, 0]]).T 0 0 1 1 1 1 1 0 1 0 1 1 0 1 1 0
  • 55. 55 Code Lab – Simple Python Neural Network Fingers Crossed
  • 56. 56 Well Done!Think of the Possibilities And we have a neural network now done with Python! A simple one! What about this one?
  • 58. 58 Section 7 Important Neural Networks Concepts
  • 59. 59 New ConceptsThere are More! Activation Functions Sigmoid
  • 60. 60 New ConceptsThere are More! Input Dimension
  • 61. 61 New ConceptsThere are More! Dense Layer & Dropout Layer
  • 63. 63 New ConceptsThere are More! Learning Rate
  • 64. 64 New ConceptsThere are More! Model Loss
  • 65. 65 New ConceptsThere are More! Epoch Batch 1 Batch 2 Batch 3 ... Batch n Batch Sample 1 Sample 2 Sample 3 ... Sample n Epoch & Batch Size
  • 66. 66 New ConceptsThere are More! Training Data vs Validation Data vs Test Data for each epoch for each training data instance - propagate error through the network - adjust the weights - calculate the accuracy over training data for each validation data instance calculate the accuracy over the validation data If the accuracy over the training data set increases, but the accuracy over the validation data set stays the same or decreases exit training else continue training
  • 67. 67 New ConceptsThere are More! Training Data vs Validation Data vs Test Data Dataset Count Testing Part (0.2) Training Part (0.8) 1,000 = 1,000 * 0.2 = 200 = 1,000 * 0.8 = 800 Validation Portion (0.1) Training Portion (0.9) = 800 * 0.1 = 80 = 800 * 0.9 = 720 For example, if we have 1000 data samples
  • 68. 68 Section 8 Coding Example: Language Detection with Google's TensorFlow (Real-world example)
  • 70. 70 Language Detection - TensorFlowA real world Deep Neural Networks Example Lots of Data High Accuracy Language Detection Deep Neural Network
  • 71. 71 Language DetectionFeature Extraction Text Data Count Vectorizer Standard Scaler Transformation Numerical Vectors Letter Counter We will identify: English, French, Spanish, Italian, German, Slovak, Czech
  • 72. 72 The DataThanks Wikipedia! Downloaded from https://dumps.wikimedia.org/ Then Extracted to txt using http://medialab.di.unipi.it/wiki/Wikipedia_Extractor I generated 7 files 1 for each language, 204 MB each!! I gave you 5 files only
  • 73. 73 Code Lab – TensorFlow Language Detection Fingers Crossed
  • 74. 74 Data CountsTo Clarify Training Data vs Validation Data vs Test Data Dataset Count per Language Total Dataset Count (we have data for 5 languages) Testing Part (0.2) Training Part (0.8) 250,000 = 5 * 250,000 = 1,250,000 = 1,250,000 * 0.2 = 250,000 = 1,250,000 * 0.8 = 1,000,000 Validation Portion (0.1) Training Portion (0.9) = 1,000,000 * 0.1 = 100,000 = 1,000,000 * 0.9 = 900,000
  • 75. 75 AWESOME!We did it, again! Accuracy 98% Machine learning train part is from lines 315-330 (just 11 lines of code!) and the predict code is from 396-406 (10 lines of code!) the remaining code is for: Data cleaning (custom function) Text vectorization (custom function) Text Transformation (from library) Evaluation, reporting, and plotting
  • 77. 77 Machine Learning is FunYou can apply it everywhere! 1. Get training data for your problem. 2. Convert those data into numerical vectors. 3. Train the network. 4. Predict!
  • 78. 78 TensorFlow HubDon’t Reinvent the Wheel https://alpha.tfhub.dev/
  • 79. 79 Code Lab – TensorFlow Hub Examples Fingers Crossed
  • 80. 80 Bonus: Section 10 Bonus Section: Building a Neural Network using Plain Math
  • 82. 82 Building Neural NetworksManually! We will walk through a simple example of training a neural network to function as an “Exclusive OR” (“XOR”) operation to illustrate each step in the training process. input | output ------------------- 0, 0 | 0 0, 1 | 1 1, 0 | 1 1, 1 | 0
  • 85. 85 Building Neural NetworksManually! 1 * 0.8 + 1 * 0.2 = 1 1 * 0.4 + 1 * 0.9 = 1.3 1 * 0.3 + 1 * 0.5 = 0.8
  • 88. 88 Building Neural NetworksManually! S(1.0) = 0.73105857863 S(1.3) = 0.78583498304 S(0.8) = 0.68997448112
  • 89. 89 Building Neural NetworksManually! 0.73 * 0.3 + 0.79 * 0.5 + 0.69 * 0.9 = 1.235 S(1.235) = 0.7746924929149283
  • 90. 90 Building Neural NetworksManually! Output sum margin of error = target – calculated Target = 0 Calculated = 0.77 Output sum margin of error = Target – calculated = - 0.77 𝑆′ 𝑠𝑢𝑚 = 𝑑𝑠𝑢𝑚 𝑑𝑟𝑒𝑠𝑢𝑙𝑡 𝑑𝑠𝑢𝑚 𝑑𝑟𝑒𝑠𝑢𝑙𝑡 × 𝑡𝑎𝑟𝑔𝑒𝑡 𝑟𝑒𝑠𝑢𝑙𝑡 − 𝑐𝑎𝑙𝑐𝑢𝑙𝑎𝑡𝑒𝑑 𝑟𝑒𝑠𝑢𝑙𝑡 = ∆𝑠𝑢𝑚 Delta output sum = S'(sum) * (output sum margin of error) Delta output sum = S'(1.235) * (-0.77) Delta output sum = -0.13439890643886018
  • 92. 92 Building Neural NetworksManually! 𝐻𝑟𝑒𝑠𝑢𝑙𝑡 × 𝑊ℎ→𝑜 = 𝑂𝑠𝑢𝑚 𝑑𝑂𝑠𝑢𝑚 𝑑𝑤ℎ→𝑜 = 𝐻𝑟𝑒𝑠𝑢𝑙𝑡𝑠 hidden result 1 = 0.73105857863 hidden result 2 = 0.78583498304 hidden result 3 = 0.68997448112 Delta weights = delta output sum / hidden layer results Delta weights = -0.1344 / [0.73105, 0.78583, 0.69997] Delta weights = [-0.1838, -0.1710, -0.1920] old w7 = 0.3 old w8 = 0.5 old w9 = 0.9 new w7 = 0.1162 new w8 = 0.329 new w9 = 0.708 𝑑𝑤ℎ→𝑜 = 𝑑𝑂𝑠𝑢𝑚 𝐻𝑟𝑒𝑠𝑢𝑙𝑡𝑠
  • 93. 93 Building Neural NetworksManually! 𝐻𝑟𝑒𝑠𝑢𝑙𝑡 × 𝑊ℎ→𝑜 = 𝑂𝑠𝑢𝑚 𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 = 𝑑𝑂𝑠𝑢𝑚 𝑤ℎ→𝑜 𝑆′ 𝐻𝑠𝑢𝑚 = 𝑑𝐻𝑠𝑢𝑚 𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 𝑑𝑂𝑠𝑢𝑚 = 1 𝑤ℎ→𝑜 𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 × 𝑑𝐻𝑠𝑢𝑚 𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 = 𝑑𝑂𝑠𝑢𝑚 𝑤ℎ→𝑜 × 𝑑𝐻𝑠𝑢𝑚 𝑑𝐻𝑟𝑒𝑠𝑢𝑙𝑡 𝑑𝐻𝑠𝑢𝑚 = 𝑑𝑂𝑠𝑢𝑚 𝑤ℎ→𝑜 × 𝑆′(𝐻𝑠𝑢𝑚) Delta hidden sum = delta output sum / hidden-to-outer weights * S'(hidden sum Delta hidden sum = -0.1344 / [0.3, 0.5, 0.9] * S'([1, 1.3, 0.8]) Delta hidden sum = [-0.448, -0.2688, -0.1493] * [0.1966, 0.1683, 0.2139] Delta hidden sum = [-0.088, -0.0452, -0.0319]
  • 94. 94 Building Neural NetworksManually! 𝐼 × 𝑤𝑖→ℎ = 𝐻𝑠𝑢𝑚 𝑑𝑤𝑖→ℎ = 𝑑𝐻𝑠𝑢𝑚 𝐼 𝑑𝐻𝑠𝑢𝑚 𝑑𝑤𝑖→ℎ = 𝐼 input 1 = 1 input 2 = 1 Delta weights = delta hidden sum / input data Delta weights = [-0.088, -0.0452, -0.0319] / [1, 1] Delta weights = [-0.088, -0.0452, -0.0319, -0.088, -0.0452, -0.0319] old w1 = 0.8 new w1 = 0.712 old w2 = 0.4 new w2 = 0.3548 old w3 = 0.3 new w3 = 0.2681 old w4 = 0.2 new w4 = 0.112 old w5 = 0.9 new w5 = 0.8548 old w6 = 0.5 new w6 = 0.4681
  • 95. 95 Building Neural NetworksManually! old new -------------------------- w1: 0.8 w1: 0.712 w2: 0.4 w2: 0.3548 w3: 0.3 w3: 0.2681 w4: 0.2 w4: 0.112 w5: 0.9 w5: 0.8548 w6: 0.5 w6: 0.4681 w7: 0.3 w7: 0.1162 w8: 0.5 w8: 0.329 w9: 0.9 w9: 0.708
  • 96. 96 Well Done! You have successfully started your AI journey! Keep going! I would love to help Keep in Touch linkedin.com/in/amrshawqy twitter.com/amrshawqy