Please enable JavaScript.
Coggle requires JavaScript to display documents.
Python for Machine Learning (numpy & scipy (Create an array (Generate…
Python for Machine Learning
scikit-learn
Has standard datasets
iris
from sklearn import datasets
iris = datasets.loat_iris()
iris.data.shape
(150, 4)
150 observations
4 features
digits
digits = datasets.load_digits
Features:
digits.data
data is "2D array":
(n_samples, n_features)
digits.images.shape
Target
digits.target
Estimator
SVC:
Support Vector Classification
from sklearn import svm
classifier = svm.SVC(gamma=0.001, C=100.0)
numpy & scipy
3D Point has 1 axis:
[1,2,2]
import numpy as np
Create an array
Generate an array[15]:
a = np.arange(15)
a => [0,1,...14]
Generate by step:
a = np.arange(0,2,0.2)
=> [0, 0.2, 0.4,...1.8]
Reshape(row, column):
a.reshape(3,5)
...
a.shape
Show dimension:
a.ndim => 2 means [array of array]
Operate an array:
10*np.sin(a)
"product" 2 arrays
Product elementwise(each item):
a*b
matrix product:
a @ b
Add 2 arrays vertically:
np.vstack((a,b))
Array with True, False:
a < 30
Result: [True, False, False,...]
a.itemsize => 8 means: row + column
a.size => 15 means row*column
a = np.array([1,2,3,4])
Zero Matrix - array of array:
b = np.zeros((row, column))
Set item's type of Ones Matrix:
np.ones((dimen, row, column), dtype=np.int32)
Array with random values:
np.empty((2,3))
Random values from 0 to 1:
a = np.random.random(row, column)
Linear space: 9 numbers from 0 to 2*pi
x = np.linspace(0, 2*np.pi, 9)
Array Functions
unfunc = Universal Functions
np.exp(a)
np.exp(a) => e = 2.718
Access array's index:
a[row, column]
Access range index:
a[0:5, 1]
Access last element:
a[-1]
Resize an Array:
a.resize((2,6))
Flat and iterate an array:
for element in a.flat:
Clone an array and flattern:
a.ravel()
Clone and Transpose:
a.T
Machine Learning Concepts
Supervised Learning:
Sample is (input, output)
Each sample has Features or Attributes
Classification
Discrete Form. Eg:
Male, Female
Regression
Continuous values: age, length,...
Unsupervised Learning
Sample is : (input, ?)
clustering: A group if similar examples
Training set and testing set
Name: Nguyen Duc Hoang
Youtube:
https://www.youtube.com/c/nguyenduchoang