Beginner’s Guide to Python

Machine Learning for Beginners in Python: How to Use Shi-Tomasi Corner Detector

Hits: 6 Shi-Tomasi Corner Detector Preliminaries import cv2 import numpy as np from matplotlib import pyplot as plt Load image image_bgr = cv2.imread(‘images/plane_256x256.jpg’) image_gray = cv2.cvtColor(image_bgr, cv2.COLOR_BGR2GRAY) Define Corner Parameters corners_to_detect = 10 minimum_quality_score = 0.05 minimum_distance = 25 Detect Corners corners = cv2.goodFeaturesToTrack(image_gray, corners_to_detect, minimum_quality_score, minimum_distance) corners = np.float32(corners) Mark Corners for corner in …

Machine Learning for Beginners in Python: How to Save Images

Hits: 4 Save Images Preliminaries import cv2 import numpy as np from matplotlib import pyplot as plt Load Image As Greyscale image = cv2.imread(‘images/plane.jpg’, cv2.IMREAD_GRAYSCALE) plt.imshow(image, cmap=’gray’), plt.axis(“off”) plt.show()   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 Load Images

Hits: 12 Load Images Preliminaries import cv2 import numpy as np from matplotlib import pyplot as plt Load Image As Greyscale image = cv2.imread(‘images/plane.jpg’, cv2.IMREAD_GRAYSCALE) plt.imshow(image, cmap=’gray’), plt.axis(“off”) plt.show()   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 Binarize Images

Hits: 2 Binarize Images Preliminaries import cv2 import numpy as np from matplotlib import pyplot as plt Load Image As Greyscale image_grey = cv2.imread(‘images/plane_256x256.jpg’, cv2.IMREAD_GRAYSCALE) Apply Adaptive Thresholding max_output_value = 255 neighorhood_size = 99 subtract_from_mean = 10 image_binarized = cv2.adaptiveThreshold(image_grey, max_output_value, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, neighorhood_size, subtract_from_mean) View Image plt.imshow(image_binarized, cmap=’gray’), plt.axis(“off”) plt.show() Python Example for Beginners …

Machine Learning for Beginners in Python: How to Rescale A Feature

Hits: 5 Rescale A Feature Preliminaries from sklearn import preprocessing import numpy as np Create Feature x = np.array([[-500.5], [-100.1], [0], [100.1], [900.9]]) Rescale Feature Using Min-Max minmax_scale = preprocessing.MinMaxScaler(feature_range=(0, 1)) x_scale = minmax_scale.fit_transform(x) x_scale array([[ 0. ], [ 0.28571429], [ 0.35714286], [ 0.42857143], [ 1. ]])   Python Example for Beginners Special 95% discount …

Machine Learning for Beginners in Python: How to Get The Diagonal Of A Matrix

Hits: 4 Getting The Diagonal Of A Matrix Preliminaries import numpy as np Create Matrix matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) Get The Diagonal matrix.diagonal() array([1, 5, 9]) Calculate The Trace matrix.diagonal().sum() 15   Python Example for Beginners Special 95% discount 2000+ Applied Machine Learning & Data Science Recipes Portfolio …

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

Hits: 4 Reshape An Array Preliminaries import numpy as np Create Array matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]) Reshape Array matrix.reshape(2, 6) array([[ 1, 2, 3, 4, 5, 6], [ 7, 8, 9, 10, 11, 12]])   Python Example for Beginners Special 95% discount 2000+ Applied Machine …

Machine Learning for Beginners in Python: How to Select Elements in An Array

Hits: 0 Selecting Elements In An Array Preliminaries # Load library import numpy as np Create Vector # Create row vector vector = np.array([1, 2, 3, 4, 5, 6]) Select Element # Select second element vector[1] 2 Create Matrix # Create matrix matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) Select Element …

Machine Learning for Beginners in Python: How to save Machine Learning Models

Hits: 3 Saving Machine Learning Models In scikit there are two main ways to save a model for future use: a pickle string and a pickled model as a file. Preliminaries from sklearn.linear_model import LogisticRegression from sklearn import datasets import pickle from sklearn.externals import joblib Load Data # Load the iris data iris = datasets.load_iris() …

Machine Learning for Beginners in Python: Make Simulated Data For Clustering

Hits: 40 Make Simulated Data For Clustering Preliminaries from sklearn.datasets import make_blobs import matplotlib.pyplot as plt Make Data /* Make the features (X) and output (y) with 200 samples, */ X, y = make_blobs(n_samples = 200, n_features = 2, centers = 3, cluster_std = 0.5, shuffle = True) View Data /* Create a scatterplot of …

Machine Learning for Beginners in Python: Loading scikit-learn’s Iris Dataset

Hits: 39 Loading scikit-learn’s Iris Dataset Preliminaries # Load libraries from sklearn import datasets import matplotlib.pyplot as plt Load Iris Dataset The Iris flower dataset is one of the most famous databases for classification. It contains three classes (i.e. three species of flowers) with 50 observations per class. # Load digits dataset iris = datasets.load_iris() # Create …

Machine Learning for Beginners in Python: Loading scikit-learn’s Digits Dataset

Hits: 5 Loading scikit-learn’s Digits Dataset Preliminaries # Load libraries from sklearn import datasets import matplotlib.pyplot as plt Load Digits Dataset Digits is a dataset of handwritten digits. Each feature is the intensity of one pixel of an 8 x 8 image. # Load digits dataset digits = datasets.load_digits() # Create feature matrix X = …

Machine Learning for Beginners in Python: Loading scikit-learn’s Boston Housing Dataset

Hits: 2 Loading scikit-learn’s Boston Housing Dataset Preliminaries # Load libraries from sklearn import datasets import matplotlib.pyplot as plt Load Boston Housing Dataset The Boston housing dataset is a famous dataset from the 1970s. It contains 506 observations on housing prices around Boston. It is often used in regression examples and contains 15 features. # Load digits …

Machine Learning for Beginners in Python: Loading Features From Dictionaries

Hits: 3 Loading Features From Dictionaries from sklearn import datasets import numpy as np iris = datasets.load_iris() X = iris.data[:, [2, 3]] X array([[1.4, 0.2], [1.4, 0.2], [1.3, 0.2], [1.5, 0.2], [1.4, 0.2], [1.7, 0.4], [1.4, 0.3], [1.5, 0.2], [1.4, 0.2], [1.5, 0.1], [1.5, 0.2], [1.6, 0.2], [1.4, 0.1], [1.1, 0.1], [1.2, 0.2], [1.5, 0.4], …

Python Built-in Methods – Python Dictionary values() Method

Hits: 16 Python Dictionary values() Method Returns a list of values from a dictionary Usage The values() method returns a list of values from a dictionary. Syntax dictionary.values() Examples # Print all values from the dictionary D = {‘name’: ‘Bob’, ‘age’: 25} L = D.values() print(L) # Prints dict_values([25, ‘Bob’]) values() method is generally used to iterate through all …

Python Built-in Methods – Python Dictionary update() Method

Hits: 5 Python Dictionary update() Method Updates/Adds multiple items to the dictionary Usage The update() method updates the dictionary with the key:value pairs from element. If the key is already present in the dictionary, value gets updated. If the key is not present in the dictionary, a new key:value pair is added to the dictionary. element can be either another dictionary …