02 Phan Tich Dau Tu Nang Cao - Co So Ve Lap Trinh Python
02 Phan Tich Dau Tu Nang Cao - Co So Ve Lap Trinh Python
Python Programming 2
Foundations of Investment Analysis in Python 3
3
Asset
Banking Insurance
Management
https://www.youtube.com/watch?v=kBwOy-6CtAQ
5
S&P 500 - a stock market index tracking the stock performance of 500 of the largest companies listed
on stock exchanges in the United States
6
In 2004-2014, it accounted
• Lost of interesting jobs for 12.5% of all employment
income and 26.1% of all
corporare profits
• B2B customers
Worldwide spending on
information technology (IT) by
financial services, $440 billion
• Your personal finances in 2018. And growing…
7
Trading Systems
Finance Information System
• Front Arena
• Huge & complex – multi
• Python embedded since 1999
million line, PhD Math
• Used for business logic and
customization
• Expensive, $2000 • Courses to certify 1000+ in
USD/user & month range Python based development
• Need to be customized
9
Workflow
• Generate ideas
• Evaluate
• Execute
Ways to be fast
11
Open Bank
We use Python to quickly develop new
Machine Learning models that power our
data-driven products
• Optimize for fast experimentation and
model development, Python enables
very fast iteration cycles
• Offer most support for ML purposes
• Enable our data scientists to build
complex model while providing a low
entry barrier
• Share code between training and
serving ML models in production.
13
Startups
We need to…
All your Investments,
Connect and glue data
Savings and Pensions Python + Requestes +
in one app ‘batteries’
Server APIs
Django + Channels / Sanic
Source: http://nbviewer.jupyter.org/format/slides/github/quantopian/pyfolio/blob/master/pyfolio/examples/overview_slides.ipynb#/5
16
Source: https://github.com/yhilpisch/aiif
https://github.com/yhilpisch/aiif
17
Source: https://github.com/yhilpisch/aiif/tree/main/code
https://github.com/yhilpisch/aiif/tree/main/code
18
33
34
34
35
Python Programming
37
https://spectrum.ieee.org/the-top-programming-languages-2023
38
Python is an
interpreted,
object-oriented,
high-level
programming language
with
dynamic semantics.
Source: https://www.python.org/doc/essays/blurb/
39
Source: https://medium.com/pyfinance/why-python-is-best-choice-for-financial-data-modeling-in-2019-c0d0d1858c45
40
Source:https://duchesnay.github.io/pystatsml/introduction/python_ecosystem.html
41
Source: http://nbviewer.jupyter.org/format/slides/github/quantopian/pyfolio/blob/master/pyfolio/examples/overview_slides.ipynb#/5
42
Numpy
NumPy
Base
N-dimensional array
package
43
Python
matplotlib
Source: https://matplotlib.org/
44
Python
Pandas
http://pandas.pydata.org/
45
W3Schools Python
https://www.w3schools.com/python/
46
W3Schools Python
https://www.w3schools.com/python/
47
W3Schools Python
https://www.w3schools.com/python/
48
https://www.w3schools.com/python/trypython.asp?filename=demo_default
49
LearnPython.org
https://www.learnpython.org/
50
https://developers.google.com/edu/python
51
Google Colab
https://colab.research.google.com/notebooks/welcome.ipynb
52
Google Colab
54
Google Colab
55
Google Colab
57
Google Colab
58
Google Colab
59
Python3 GPU
Google Colab
60
print('Hello World')
61
Python
Programming
63
print("Hello World")
print("Hello World")
63
64
Python Syntax
# comment
# comment
64
65
Python Syntax
Indentation
the spaces at the beginning of a code line
4 spaces
score = 80
if score >=60 :
print("Pass")
65
66
Python Variables
# Python Variables
x = 2
price = 2.5
word = 'Hello'
word = 'Hello'
word = "Hello"
word = '''Hello'''
67
Python Variables
x = 2
y = x + 1
67
68
python_version()
# comment
from platform import python_version
print("Python Version:", python_version())
69
70
70
71
x = True #bool
x = b"Hello" #bytes
x = bytearray(5) #bytearray
x = memoryview(bytes(5)) #memoryview
x = None #NoneType
71
72
Python Casting
72
73
Python Numbers
x = 2 # int
y = 3.4 # float
z = 7j #complex
print(x, type(x))
print(y, type(y))
print(z, type(z))
2 <class 'int’>
3.4 <class 'float’>
7j <class 'complex'>
73
74
74
75
print('7 + 2 =', 7 + 2) 7 + 2 = 9
print('7 - 2 =', 7 - 2) 7 - 2 = 5
print('7 * 2 =', 7 * 2) 7 * 2 = 14
print('7 / 2 =', 7 / 2) 7 / 2 = 3.5
print('7 // 2 =', 7 // 2) 7 // 2 = 3
print('7 % 2 =', 7 % 2) 7 % 2 = 1
print('7 ** 2 =', 7 ** 2) 7 ** 2 = 49
75
76
76
77
77
78
Future value
of a specified
principal amount,
rate of interest, and
a number of years
Source: https://www.w3resource.com/python-exercises/python-basic-exercise-39.php
79
fv = 194.87
79
80
Future Value
# Future Value
pv = 100
r = 0.1
n = 7
fv = pv * ((1 + (r)) ** n)
print(round(fv, 2))
194.87
80
81
Future Value
# Future Value
amount = 100
interest = 10 #10% = 0.01 * 10
years = 7
81
82
Summary
• Python Syntax
• Python Comments
• Python Variables
• Python Data Types
• Python Numbers
• Python Casting
• Python Strings
• Python Operators
• Python Booleans
83
Python
Data Structures
84
84
85
Python Collections
• There are four collection data types in the Python programming
language
• List []
• a collection which is ordered and changeable. Allows duplicate
members.
• Tuple ()
• a collection which is ordered and unchangeable. Allows duplicate
members.
• Set {}
• a collection which is unordered, unchangeable, and unindexed. No
duplicate members.
• Dictionary {k:v}
• a collection which is ordered and changeable. No duplicate
members.
85
86
Lists []
Lists []
• len(): how many items
• type(): data type
• list() constructor: creating a new list
89
Tuples ()
Source: http://pythonprogramminglanguage.com/tuples/
91
Sets {}
Python Dictionary
Key Value
'EN’ 'English’
'FR’ 'French'
k = { 'EN':'English', 'FR':'French' }
print(k['EN'])
English
Source: http://pythonprogramminglanguage.com/dictionary/
93
# Python Lists
expenses = [72.50, 80.75, 50.00, 90.25]
total_expenses = sum(expenses)
print("Total expenses:", total_expenses)
Total expenses: 293.5
95
# Python Tuples
accounts = (("Cash", 1001), ("Accounts Receivable", 1002),
("Inventory", 1003))
for account in accounts:
print("Account name:", account[0], "Account number:", account[1])
# Python Sets
account_numbers = {1001, 1002, 1003}
new_account_number = 1004
if new_account_number not in account_numbers:
print("Account number", new_account_number, "is not in use.")
# Python Dictionaries
accounts = {"1001": {"name": "Cash", "balance": 500.00, "type": "Asset"},
"1002": {"name": "Accounts Receivable", "balance": 1000.00, "type": "Asset"},
"2001": {"name": "Accounts Payable", "balance": 750.00, "type": "Liability"}}
for account_number, account_info in accounts.items():
print("Account number:", account_number)
print("Account name:", account_info["name"])
print("Account balance:", account_info["balance"])
print("Account type:", account_info["type"])
Account number: 1001
Account name: Cash Account number: 2001
Account balance: 500.0
Account type: Asset Account name: Accounts Payable
Account
Account
number: 1002
name: Accounts Receivable
Account balance: 750.0
Account
Account
balance: 1000.0
type: Asset
Account type: Liability
98
Summary
• Python Data Structures
• Python Lists []
• Python Tuples ()
• Python Sets {}
Python
Control Logic
and
Loops
100
Python if...else
• Python if...else
• if elif else
• Booleans: True, False
• Operators: ==, !=, >, <, >=, <=, and, or, not
102
Source: https://www.w3schools.com/python/python_operators.asp
104
Source: https://www.w3schools.com/python/python_operators.asp
105
Python if
# Python if
score = 80
if score >=60 :
print("Pass")
106
Python if else
# Python if else
score = 80
if score >=60 :
print("Pass")
else:
print("Fail")
107
score = 95
if score >= 90 :
print("A")
elif score >=60 :
print("Pass")
else:
print("Fail")
108
for i in range(1,6):
print(i)
1
2
3
4
5
110
# for loops
for i in range(1,10):
for j in range(1,10):
print(i, ' * ' , j , ' = ', i*j)
111
# while loops
age = 10
while age < 20:
print(age)
age = age + 1
113
Summary
• Python if else
• if elif else
• Booleans: True, False
• Operators: ==, !=, >, <, >=, <=, and, or, not
• Python for Loops
• for
• Python while Loops
• while
• break
• continue
114
Python
Functions
115
Python Functions
• A function is a block of code which only runs when it is called.
• You can pass data, known as parameters, into a function.
• A function can return data as a result.
• Creating a Function
• In Python a function is defined using the def keyword:
116
Future value
of a specified
principal amount,
rate of interest, and
a number of years
Source: https://www.w3resource.com/python-exercises/python-basic-exercise-39.php
118
Future Value
# Future Value
pv = 100
r = 0.1
n = 7
fv = pv * ((1 + (r)) ** n)
print(round(fv, 2))
194.87
120
Future Value
# Future Value
amount = 100
interest = 10 #10% = 0.01 * 10
years = 7
Python Function
Python
Classes/Objects
class MyClass:
123
Python Classes/Objects
• Python is an object oriented programming language.
• Almost everything in Python is an object, with its properties and methods.
• A Class is like an object constructor, or a "blueprint" for creating objects.
• Create a Class:
• To create a class, use the keyword class:
Python Classes/Objects
124
class MyClass:
# Python class
class MyClass:
x = 5
c1 = MyClass()
print(c1.x)
https://www.w3schools.com/python/python_classes.asp
125
Python Classes/Objects
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
p1 = Person("Alan", 20)
print(p1.name) Alan
print(p1.age) 20
126
Python Classes/Objects
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
p1 = Person("Alan", 20)
p1.myfunc()
127
Python Classes/Objects
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
def myfunc(self):
print("Hello my name is " + self.name)
p1 = Person("Alan", 20)
p1.myfunc() Hello my name is Alan
print(p1.name) Alan
print(p1.age) 20
128
class Vehicle:
name = ""
kind = "car"
color = ""
value = 100.00
def description(self):
desc_str = "%s is a %s %s worth $%.2f." %
(self.name, self.color, self.kind, self.value)
return desc_str
129
Python
Modules
131
Python Modules
• Consider a module to be the same as a code library.
• A file containing a set of functions you want to include in your application.
• Create a Module
• To create a module just save the code you want in a file with the file extension .py:
• Use a Module
• import module
132
Python Modules
# mymodule.py
def greeting(name):
print("Hello, " + name)
import mymodule
mymodule.greeting("Alan")
mymodule.py
def greeting(name):
print("Hello, " + name)
133
Python Modules
import mymodule
# mymodule.py
def greeting(name):
print("Hello, " + name)
import mymodule
mymodule.greeting("Alan")
Hello, Alan
136
if __name__ == "__main__":
main()
137
Summary
• Python Functions
• def myfunction():
• Python Classes/Objects
• class MyClass:
• Python Modules
• mymodule.py
• import mymodule
138
Files
and
Exception Handling
139
• f = open("myfile.txt")
File Handling
• The key function for working with files in Python is the open() function.
• The open() function takes two parameters; filename, and mode.
• There are four different methods (modes) for opening a file:
• "r" - Read - Default value. Opens a file for reading, error if the file does not exist
• "a" - Append - Opens a file for appending, creates the file if it does not exist
• "w" - Write - Opens a file for writing, creates the file if it does not exist
• "x" - Create - Creates the specified file, returns an error if the file exists
141
f = open("myfile.txt", "w")
f.write("Hello World")
f.close()
f = open("myfile.txt", "r")
text = f.read()
print(text)
f.close()
Hello World
142
Hello World
143
Python Files
Python Files
Python Files
myfile.txt sample_data
146
import os
cwd = os.getcwd()
print(cwd)
/content
147
os.listdir()
os.listdir(cwd)
['.config',
'myfile.txt',
'sample_data']
148
os.path.join()
/content/sample_data
['README.md', 'anscombe.json',
'mnist_train_small.csv',
'mnist_test.csv',
'california_housing_train.csv',
'california_housing_test.csv']
149
import time
time.sleep(1) # time sleep 1 second
files.download('io_file_myday.txt')
print('downloaded')
downloaded
150
Python Files
for fn in uploaded.keys():
print('User uploaded file "{name}"
with length {length} bytes'.format(
name=fn, length=len(uploaded[fn])))
os.remove()
import os
if os.path.exists("myfile.txt"):
os.remove("myfile.txt")
print("myfile.txt removed")
else:
print("The file does not exist")
myfile.txt removed
152
os.mkdir("myfolder1")
os.rmdir("myfolder1")
import os
os.listdir()
os.mkdir("myfolder1")
os.listdir()
os.rmdir("myfolder1")
os.listdir()
153
try: except:
try:
print("Hello")
except:
print("Exception Error")
else:
print("No exception")
finally:
print("Finally process")
Hello
No exception
Finally process
158
try:
price = float(input("Enter the price of the stock (e.g. 10):"))
shares = int(input("Enter the number of shares (e.g. 2):"))
total = price * shares
except Exception as e:
print("Exception error:", str(e))
else:
print("The total value of the shares is:", total)
finally:
print("Thank you.")
Enter the price of the stock (e.g. 10):10
Enter the number of shares (e.g. 2):2
The total value of the shares is: 20.0
Thank you.
159
try:
file = open("myfile.txt")
file.write("Python write file")
print("file saved")
except:
print("Exception file Error")
try:
file = open("myfile.txt")
file.write("Python write file")
print("file saved")
except:
print("Exception file Error")
finally:
file.close()
print("Finally process")
Exception file Error
Finally process
161
try:
file = open("myfile.txt", 'w’)
file.write("Python write file")
print("file saved")
except:
print("Exception file Error")
finally:
file.close()
print("Finally process")
file saved
Finally process
162
Summary
• Python Files (File Handling)
• open()
• f = open("myfile.txt")
Foundations of
Investment Analysis
in Python
Outline
164
• Numpy
•Scientific computing
• Pandas
• Data structures and data analysis
tools
165
The Quant Finance PyData Stack
Source: http://nbviewer.jupyter.org/format/slides/github/quantopian/pyfolio/blob/master/pyfolio/examples/overview_slides.ipynb#/5
166
167
168
Python is an
interpreted,
object-oriented,
high-level
programming language
with
dynamic semantics.
Source: https://www.python.org/doc/essays/blurb/
169
Google Colab
https://colab.research.google.com/notebooks/welcome.ipynb
Python in Google Colab (Python101) 170
https://colab.research.google.com/drive/1FEG6DnGvwfUbeo4zJ1zTunjMqf2RkCrT
https://tinyurl.com/imtkupython101
Numpy
171
NumPy
Base
N-dimensional array
package
Python
172
matplotlib
Source: https://matplotlib.org/
173
Python
Pandas
http://pandas.pydata.org/
Iris flower data set
174
Source: https://en.wikipedia.org/wiki/Iris_flower_data_set
Source: http://suruchifialoke.com/2016-10-13-machine-learning-tutorial-iris-classification/
Iris Classfication
175
Source: http://suruchifialoke.com/2016-10-13-machine-learning-tutorial-iris-classification/
176
iris.data
https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data
5.1,3.5,1.4,0.2,Iris-setosa setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
4.6,3.4,1.4,0.3,Iris-setosa
5.0,3.4,1.5,0.2,Iris-setosa
4.4,2.9,1.4,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa
5.4,3.7,1.5,0.2,Iris-setosa virginica
4.8,3.4,1.6,0.2,Iris-setosa
4.8,3.0,1.4,0.1,Iris-setosa
4.3,3.0,1.1,0.1,Iris-setosa
5.8,4.0,1.2,0.2,Iris-setosa
5.7,4.4,1.5,0.4,Iris-setosa
5.4,3.9,1.3,0.4,Iris-setosa
5.1,3.5,1.4,0.3,Iris-setosa
5.7,3.8,1.7,0.3,Iris-setosa versicolor
5.1,3.8,1.5,0.3,Iris-setosa
5.4,3.4,1.7,0.2,Iris-setosa
5.1,3.7,1.5,0.4,Iris-setosa
4.6,3.6,1.0,0.2,Iris-setosa
5.1,3.3,1.7,0.5,Iris-setosa
4.8,3.4,1.9,0.2,Iris-setosa
5.0,3.0,1.6,0.2,Iris-setosa
177
Iris Data Visualization
Source: https://seaborn.pydata.org/generated/seaborn.pairplot.html
178
Connect Google Colab in Google Drive
179
Google Colab
180
Google Colab
181
Connect Colaboratory to Google Drive
182
Google Colab
183
Google Colab
184
Google Colab
185
Source: https://seaborn.pydata.org/generated/seaborn.pairplot.html
import seaborn as sns 188
sns.set(style="ticks", color_codes=True)
iris = sns.load_dataset("iris")
g = sns.pairplot(iris, hue="species")
Source: https://seaborn.pydata.org/generated/seaborn.pairplot.html
https://colab.research.google.com/drive/1KRqtEUd2Hg4dM2au9bfVQKrxWnWN3O9- 189
import numpy as np
import pandas as pd
%matplotlib inline
import matplotlib.pyplot as plt
import seaborn as sns
from pandas.plotting import scatter_matrix
# Load dataset
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
df = pd.read_csv(url, names=names)
print(df.head(10))
print(df.tail(10))
print(df.describe())
print(df.info())
print(df.shape)
print(df.groupby('class').size())
plt.rcParams["figure.figsize"] = (10,8)
df.plot(kind='box', subplots=True, layout=(2,2), sharex=False, sharey=False)
plt.show()
df.hist()
plt.show()
scatter_matrix(df)
plt.show()
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
df = pd.read_csv(url, names=names)
print(df.head(10))
df.tail(10)
192
df.describe()
193
194
print(df.info())
print(df.shape)
195
df.groupby('class').size()
196
plt.rcParams["figure.figsize"] = (10,8)
df.plot(kind='box', subplots=True, layout=(2,2), sharex=False, sharey=False)
plt.show()
df.hist()
197
plt.show()
scatter_matrix(df)
198
plt.show()
199
sns.pairplot(df, hue="class", size=2)
200
Anaconda
The Most Popular
Python
Data Science Platform
Source: https://www.anaconda.com/
201
Download Anaconda
https://www.anaconda.com/download
202
HelloWorld
Anaconda-Navigator
203
Launchpad
Anaconda Navigator
204
Jupyter Notebook
205
Jupyter Notebook 206
New Python 3
207
print("hello, world")
208
NumPy
Base
N-dimensional array
package
211
NumPy
is the
fundamental package
for
scientific computing
with Python.
Source: http://www.numpy.org/
212
NumPy
NumPy
• NumPy provides a
multidimensional array object
to store homogenous or
heterogeneous data;
it also provides
optimized functions/methods to
operate on this array object.
Source: Yves Hilpisch (2014), Python for Finance: Analyze Big Financial Data, O'Reilly
213
NumPy
http://www.numpy.org/
214
NumPy ndarray
One-dimensional Array
NumPy
(1-D Array)
0 1 n-1
1 2 3 4 5
Two-dimensional Array
(2-D Array)
0 1 n-1
0 1 2 3 4 5
1 6 7 8 9 10
11 12 13 14 15
m-1 16 17 18 19 20
215
NumPy
NumPy
v = list(range(1, 6))
v
2 * v
import numpy as np
v = np.arange(1, 6)
v
2 * v
Source: Yves Hilpisch (2014), Python for Finance: Analyze Big Financial Data, O'Reilly
216
NumPy
Base
N-dimensional
array package
217
NumPy
NumPy Create Array
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = a * b
c
Source: Yves Hilpisch (2014), Python for Finance: Analyze Big Financial Data, O'Reilly
218
NumPy
NumPy
Source: http://cs231n.github.io/python-numpy-tutorial/
Numpy Quickstart Tutorial
219
https://docs.scipy.org/doc/numpy-dev/user/quickstart.html
import numpy as np
220
a = np.arange(15).reshape(3, 5)
a.shape
a.ndim
a.dtype.name
Source: https://docs.scipy.org/doc/numpy-dev/user/quickstart.html
221
Matrix
Source: https://simple.wikipedia.org/wiki/Matrix_(mathematics)
222
NumPy ndarray:
Multidimensional Array Object
223
NumPy ndarray
One-dimensional Array
(1-D Array)
0 1 n-1
1 2 3 4 5
Two-dimensional Array
(2-D Array)
0 1 n-1
0 1 2 3 4 5
1 6 7 8 9 10
11 12 13 14 15
m-1 16 17 18 19 20
import numpy as np
224
a = np.array([1,2,3,4,5])
One-dimensional Array
(1-D Array)
0 1 n-1
1 2 3 4 5
225
a = np.array([[1,2,3,4,5],[6,7,8,9,10],[11,12,13,14,15],[16,17,18,19,20]])
Two-dimensional Array
(2-D Array)
0 1 n-1
0 1 2 3 4 5
1 6 7 8 9 10
11 12 13 14 15
m-1 16 17 18 19 20
226
import numpy as np
a = np.array([[0, 1, 2, 3],
[10, 11, 12, 13],
[20, 21, 22, 23]])
a
0 1 2 3
10 11 12 13
20 21 22 23
227
a = np.array ([[0, 1, 2, 3], [10, 11, 12, 13], [20, 21, 22, 23]])
0 1 2 3
10 11 12 13
20 21 22 23
228
NumPy Basics:
Arrays and Vectorized
Computation
Source: https://www.safaribooksonline.com/library/view/python-for-data/9781449323592/ch04.html
229
NumPy Array
Source: https://www.safaribooksonline.com/library/view/python-for-data/9781449323592/ch04.html
Numpy Array 230
Source: https://www.safaribooksonline.com/library/view/python-for-data/9781449323592/ch04.html
Wes McKinney (2017), "Python for Data Analysis: Data Wrangling with Pandas,
231
NumPy, and IPython", 2nd Edition, O'Reilly Media.
https://github.com/wesm/pydata-book
Wes McKinney (2017), "Python for Data Analysis: Data Wrangling with Pandas,
232
NumPy, and IPython", 2nd Edition, O'Reilly Media.
Source: https://github.com/wesm/pydata-book/blob/2nd-edition/ch04.ipynb
233
Python
Pandas
234
Python Pandas
for Finance
Source: https://mapattack.wordpress.com/2017/02/12/using-python-for-stocks-1/
235
plt.figure(figsize=(12,9))
sns.distplot(df['Adj Close'].dropna(),
bins=50, color='purple')
244
245
plt.figure(figsize=(12,9))
sns.distplot(df['Adj Close'].dropna(), bins=50, color='purple')
Source: https://www.quandl.com/tools/python
250
The Quant Finance PyData Stack
Source: http://nbviewer.jupyter.org/format/slides/github/quantopian/pyfolio/blob/master/pyfolio/examples/overview_slides.ipynb#/5
Summary
251
• Foundations of
AI Investment Analysis in Python
• Python
• Programming language
• Numpy
• Scientific computing
• Pandas
• Data structures and data analysis
tools
252
References
• Wes McKinney (2017), "Python for Data Analysis: Data Wrangling with Pandas,
NumPy, and IPython", 2nd Edition, O'Reilly Media.
https://github.com/wesm/pydata-book
• Ties de Kok (2017), Learn Python for Research,
https://github.com/TiesdeKok/LearnPythonforResearch
• Avinash Jain (2017), Introduction To Python Programming, Udemy,
https://www.udemy.com/pythonforbeginnersintro/
• Python Programming, https://pythonprogramming.net/
• Python, https://www.python.org/
• Python Programming Language, http://pythonprogramminglanguage.com/
• Numpy, http://www.numpy.org/
• Pandas, http://pandas.pydata.org/
• Skikit-learn, http://scikit-learn.org/
• Data School (2015), Machine learning in Python with scikit-learn,
https://www.youtube.com/playlist?list=PL5-
da3qGB5ICeMbQuqbbCOQWcS6OYBr5A
• Jason Brownlee (2016), Your First Machine Learning Project in Python Step-By-Step,
https://machinelearningmastery.com/machine-learning-in-python-step-by-step/
253
CÁM ƠN ĐÃ LẮNG
NGHE!