Server Side Programming Articles - Page 466 of 2650

How to generate a symmetric positive-definite matrix using Python Scikit-Learn?

Gaurav Leekha
Updated on 04-Oct-2022 08:12:58

3K+ Views

Python Scikit-learn provides us make_spd_matrix() function with the help of which we can generate a random symmetric positive-definite matrix. In this tutorial, we will generate symmetric positive-definite and sparse spd matrices using Scikit-learn (Sklearn) in Python. To do so, we can follow the below given steps − Step 1 − Import the libraries sklearn.datasets.make_spd_matrix, matplotlib, and seaborn which are necessary to execute the program. Step 2 − Create an object of make_spd_matrix() and provide the value of n_dim parameter which represents the matrix dimension. Step 3 − Use matplotlib lib to set the size of the output figure. Step 4 − Use seaborn ... Read More

How to generate random regression problems using Python Scikit-learn?

Gaurav Leekha
Updated on 04-Oct-2022 08:09:59

1K+ Views

Python Scikit-learn provides us make_regression() function with the help of which we can generate a random regression problem. In this tutorial, we will learn to generate random regression problems and random regression problems with sparse uncorrelated design. Random Regression Problem To generate a random regression problem using Python Scikit-learn, we can follow the below given steps − Step 1 − Import the libraries sklearn.datasets.make_regression and matplotlib which are necessary to execute the program. Step 2 − Provide the number of samples and other parameters. Step 3 − Use matplotlib library to set the size and style of the output figure. Step 4 − ... Read More

How to generate and plot classification dataset using Python Scikit-learn?

Gaurav Leekha
Updated on 04-Oct-2022 08:06:35

4K+ Views

Scikit-learn provides us make_classification() function with the help of which we can plot randomly generated classification datasets with different numbers of informative features, clusters per class and classes. In this tutorial, we will learn how to generate and plot classification dataset using Python Scikit-learn. Dataset with One Informative Feature and One Cluster per Class To generate and plot classification dataset with one informative feature and one cluster, we can take the below given steps − Step 1 − Import the libraries sklearn.datasets.make_classification and matplotlib which are necessary to execute the program. Step 2 − Create data points namely X and y ... Read More

How to generate an array for bi-clustering using Scikit-learn?

Gaurav Leekha
Updated on 04-Oct-2022 08:03:14

427 Views

In this tutorial, we will learn how to generate an array with a constant block diagonal structure and with a block checkerboard structure for bi-clustering using Python Scikit-learn (Sklearn). Generating an Array with a Constant Block Diagonal Structure To generate an array with constant block diagonal structure for biclustering, we can take the following steps − Step 1 − Import sklearn.datasets.make_biclusters and matplotlib. Step 2 − Set the figure size Step 3 − Create data points namely data, row, and column. Step 4 − Create a plotter to show the array with constant block diagonal structure. Step 5 − Provide ... Read More

How to create a sample dataset using Python Scikit-learn?

Gaurav Leekha
Updated on 04-Oct-2022 07:59:33

856 Views

In this tutorial, we will learn how to create a sample dataset using Python Scikit-learn. There are various built-in scikit-learn datasets which we can use easily for our ML model but sometimes we need some toy dataset. For this purpose, scikit-learn python library provides us a great sample dataset generator. Creating Sample Blob Dataset using Scikit-Learn For creating sample blob dataset, we need to import sklearn.datsets.make_blobs which is very fast and easy to use. Example In the below given example, let’s see how we can use this library to create sample blob dataset. # Importing libraries from sklearn.datasets import make_blobs ... Read More

How to Install Python Scikit-learn on Different Operating Systems?

Gaurav Leekha
Updated on 04-Oct-2022 07:47:09

12K+ Views

Scikit-learn, also known as Sklearn, is the most useful and robust open-source Python library that implements machine learning and statistical modeling algorithms including classification, regression, clustering, and dimensionality reduction using a unified interface. Scikit-learn library is written in Python and is built upon other Python packages such as NumPy (Numerical Python), and SciPy (Scientific Python). Installing Scikit-learn on Windows using pip To install Scikit-learn on Windows, follow the steps given below − Step1-Make Sure Python and pip is preinstalled Open the command prompt on your system and type the following commands to check whether Python and pip is installed or ... Read More

How to find the solidity and equivalent diameter of an object in an image using OpenCV Python?

Shahid Akhtar Khan
Updated on 28-Sep-2022 12:13:35

1K+ Views

The solidity of an object is computed as the ratio of contour area to its convex hull area. So to compute the solidity, we first have to find the contour area and convex hull area. The contour area of an object can be found using cv2.contourArea() function. Equivalent Diameter is the diameter of the circle whose area is the same as the contour area. The solidity and equivalent diameter can be computed as below − Syntax area = cv2.contourArea(cnt) hull = cv2.convexHull(cnt) hull_area = cv2.contourArea(hull) solidity = float(area)/hull_area equi_diameter = np.sqrt(4*area/np.pi) Where, cnt is a numpy array of the ... Read More

How to compute the aspect ratio of an object in an image using OpenCV Python?

Shahid Akhtar Khan
Updated on 28-Sep-2022 12:03:24

5K+ Views

The aspect ratio of an object is computed as the ratio between the width and height of the bounding rectangle of the object. So, to compute the aspect ratio, we first have to find the bounding rectangle of the object. Bounding rectangle of an object can be found using cv2.boundingRect() function. It accepts the contour points of the object and returns top-left coordinate (x, y) and (width, height) of the bounding rectangle. We use the width and height to compute the aspect ratio. Syntax x, y, w, h = cv2.boundingRect(cnt) aspect_ratio = float(w)/h Here, "cnt" is a numpy array ... Read More

How to compute the extent of an object in image using OpenCV Python?

Shahid Akhtar Khan
Updated on 28-Sep-2022 12:05:42

1K+ Views

The extent of an object is computed as the ratio of contour area to its bounding rectangle area. So, to compute the extent, we first have to find the contour area and bounding rectangle area. The contour area of an object can be found using cv2.contourArea() function. Syntax The extent can be computed as follows − area = cv2.contourArea(cnt) x, y, w, h = cv2.boundingRect(cnt) rect_area = w*h extent = float(area)/rect_area Here, "cnt" is a numpy array of the contour points of an object in the image. Steps You can use the following steps to compute extent of an ... Read More

How to perform bilateral filter operation on an image in OpenCV using Python?

Shahid Akhtar Khan
Updated on 28-Sep-2022 10:16:11

2K+ Views

A bilateral filter operation is highly effective in smoothing the image and removing noises. The main advantage of the bilateral filtering is that it preserves the edges unlike in average and median filtering. Bilateral filtering operation is slower in comparison to other filters. We can perform bilateral filtering on an image using the cv2.bilateralFilter() method. Syntax Following is the syntax of this method. cv2.bilateralFilter(img, d, sigmaColor, sigmaSpace) This method accepts the following parameters − img − The input image on which the bilateral filter operation to be applied. d − A variable of the type integer representing the ... Read More

Advertisements