Day: May 20, 2021

Machine Learning for Beginners in Python: Apply Operations To Elements

Apply Operations To Elements Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) Create Vectorized Function add_100 = lambda i: i + 100 vectorized_add_100 = np.vectorize(add_100) Apply Function To Elements vectorized_add_100(matrix) array([[101, 102, 103], [104, 105, 106], [107, 108, 109]])   Python Example for Beginners Special …

Machine Learning for Beginners in Python: How to Calculate The Average, Variance, And Standard Deviation

Calculate The Average, Variance, And Standard Deviation Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) Calculate Mean np.mean(matrix) 5.0 Calculate Variance np.var(matrix) 6.666666666666667 Calculate Standard Deviation np.std(matrix) 2.5819888974716112   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio …

Machine Learning for Beginners in Python: How to Calculate The Determinant Of A Matrix

Calculate The Determinant Of A Matrix Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) Calculate Determinant np.linalg.det(matrix) -9.5161973539299405e-16     Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio Projects for Aspiring Data Scientists: Tabular Text & Image …

Machine Learning for Beginners in Python: How to Convert A Dictionary Into A Matrix

Converting A Dictionary Into A Matrix Preliminaries from sklearn.feature_extraction import DictVectorizer Create Dictionary data_dict = [{‘Red’: 2, ‘Blue’: 4}, {‘Red’: 4, ‘Blue’: 3}, {‘Red’: 1, ‘Yellow’: 2}, {‘Red’: 2, ‘Yellow’: 2}] Feature Matrix From Dictionary dictvectorizer = DictVectorizer(sparse=False) features = dictvectorizer.fit_transform(data_dict) features array([[ 4., 2., 0.], [ 3., 4., 0.], [ 0., 1., 2.], [ …

Machine Learning for Beginners in Python: How to Create A Matrix

Create A Matrix Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 4], [2, 5]]) Note NumPy’s mat data structure is less flexible for this purposes and should be avoided.   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio Projects for Aspiring Data Scientists: Tabular Text & …

Machine Learning for Beginners in Python: How to Create A Sparse Matrix

Create A Sparse Matrix Preliminaries import numpy as np from scipy import sparse Create Dense Matrix matrix = np.array([[0, 0], [0, 1], [3, 0]]) Convert To Sparse Matrix matrix_sparse = sparse.csr_matrix(matrix) Note: There are many types of sparse matrices. In the example above we use CSR but the type we use should reflect our use …

Machine Learning for Beginners in Python: How to Create A Vector

Create A Vector Preliminaries import numpy as np Create Row Vector vector_row = np.array([1, 2, 3]) Create Column Vector vector_column = np.array([[1], [2], [3]])   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio Projects for Aspiring Data Scientists: Tabular Text & Image Data Analytics as well as …

Machine Learning for Beginners in Python: How to Describe An Array

Describe An Array Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]) View Shape matrix.shape (3, 4) View Total Elements matrix.size 12 View Number Of Dimensions matrix.ndim 2   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science …

Machine Learning for Beginners in Python: How to Find The Maximum And Minimum Of A Matrix

Find The Maximum And Minimum Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) Find Maximum Element np.max(matrix) 9 Find Minimum Element np.min(matrix) 1 Find Maximum Element By Column np.max(matrix, axis=0) array([7, 8, 9]) Find Maximum Element By Row np.max(matrix, axis=1) array([3, 6, 9])   Python …

Machine Learning for Beginners in Python: How to Flatten A Matrix

Flatten A Matrix Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) Flatten Matrix matrix.flatten() array([1, 2, 3, 4, 5, 6, 7, 8, 9])   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio Projects for Aspiring Data Scientists: …