Found 10476 Articles for Python

Explain how L2 Normalization can be implemented using scikit-learn library in Python?

AmitDiwan
Updated on 11-Dec-2020 10:32:57

5K+ Views

The process of converting a range of values into standardized range of values is known as normalization. These values could be between -1 to +1 or 0 to 1. Data can be normalized with the help of subtraction and division as well.Let us understand how L2 normalization works. It is also known as ‘Least Squares’. This normalization modifies the data in such a way that the sum of the squares of the data remains as 1 in every row.Let us see how L2 normalization can be implemented using Scikit learn in Python −Exampleimport numpy as np from sklearn import preprocessing ... Read More

How can non-linear data be fit to a model in Python?

AmitDiwan
Updated on 11-Dec-2020 10:31:56

279 Views

We will be using the Seaborn library, that helps in visualizing data.When regression models are being built, multicollinearity is checked for. This is because we need to understand the correlation present between all different combinations of continuous variables. If multicollinearity exists between the variables, we have to make sure that it is removed from the data. The data in real world is usually non-linear.We need to find mechanisms to fit such non-linear data to the model. We will be using Anscombe’s dataset to visualize this data. The ‘implot’ function is used with this non-linear data.Here’s the example −Exampleimport pandas as ... Read More

How can SciPy be used to calculate the inverse of a matrix in Python?

AmitDiwan
Updated on 11-Dec-2020 10:30:59

750 Views

Sometimes, it may be required to mathematically compute the inverse of a matrix and use the result of the operation for other purposes. Below are the steps to manually find the inverse of a matrix.Calculate the value of ‘minors’In this calculation, the values of current row and column are ignored, and the determinant of the remaining values are found. The calculated minors are stored in a matrix.The next step is to find the cofactors, wherein the alternate sign of values in the ‘minors’ matrix are changed from ‘+’ to ‘-‘ and vice-versa.Next, the matrix is transposed, i.e the rows are ... Read More

Explain how the bottom ‘n’ elements can be accessed from series data structure in Python?

AmitDiwan
Updated on 11-Dec-2020 10:30:17

118 Views

Let us understand how the slicing operator ‘:’ can be used to access elements within a certain range.Example Live Demoimport pandas as pd my_data = [34, 56, 78, 90, 123, 45] my_index = ['ab', 'mn' ,'gh', 'kl', 'wq', 'az'] my_series = pd.Series(my_data, index = my_index) print("The series contains following elements") print(my_series) n = 3 print("Bottom 3 elements are :") print(my_series[n:])OutputThe series contains following elements ab 34 mn 56 gh 78 kl 90 wq 123 az 45 dtype: int64 Bottom 3 elements are : kl 90 wq 123 az 45 dtype: int64ExplanationThe required libraries are imported, and given alias names for ease ... Read More

How can SciPy be used to calculate the determinant value of a matrix in Python?

AmitDiwan
Updated on 11-Dec-2020 10:29:18

922 Views

The determinant value can be calculated on a matrix or on an array that has more than one dimension.It may sometimes be required to understand the marix/array better. This is where the determinant operation would be needed.SciPy offers a function named ‘det’ that is present in the ‘linalg’ class which is short for ‘Linear Algebra’.Syntax of ‘det’ functionscipy.linalg.det(matrix)The ‘matrix’ is the parameter that is passed to the ‘det’ function to find its determinant value.This function can be called by passing the matrix/array as an argument.In the above picture, assume that ‘a’, ‘b’, ‘c’ and ‘d’ are numeric values of a ... Read More

Explain how L1 Normalization can be implemented using scikit-learn library in Python?

AmitDiwan
Updated on 11-Dec-2020 10:28:12

5K+ Views

The process of converting a range of values into standardized range of values is known as normalization. These values could be between -1 to +1 or 0 to 1. Data can be normalized with the help of subtraction and division as well.Data fed to the learning algorithm as input should remain consistent and structured. All features of the input data should be on a single scale to effectively predict the values. But in real-world, data is unstructured, and most of the times, not on the same scale.This is when normalization comes into picture. It is one of the most important ... Read More

How can data be scaled using scikit-learn library in Python?

AmitDiwan
Updated on 11-Dec-2020 10:26:58

404 Views

Feature scaling is an important step in the data pre-processing stage in building machine learning algorithms. It helps normalize the data to fall within a specific range.At times, it also helps in increasing the speed at which the calculations are performed by the machine.Why it is needed?Data fed to the learning algorithm as input should remain consistent and structured. All features of the input data should be on a single scale to effectively predict the values. But in real-world, data is unstructured, and most of the times, not on the same scale.This is when normalization comes into picture. It is ... Read More

How to eliminate mean values from feature vector using scikit-learn library in Python?

AmitDiwan
Updated on 11-Dec-2020 10:25:51

402 Views

Pre-processing data refers to cleaning of data, removing invalid data, noise, replacing data with relevant values and so on.Data pre-processing basically refers to the task of gathering all the data (which is collected from various resources or a single resource) into a common format or into uniform datasets (depending on the type of data). The output of one step becomes the input to the next step and so on.Mean values might have to be removed from input data to get specific result. Let us understand how it can be achieved using scikit-learn library.Exampleimport numpy as np from sklearn import preprocessing ... Read More

How can decision tree be used to implement a regressor in Python?

AmitDiwan
Updated on 11-Dec-2020 10:25:05

193 Views

Decision tree is the basic building block of the random forest algorithm. It is considered as one of the most popular algorithms in machine learning and is used for classification purposes. The decision given out by a decision tree can be used to explain why a certain prediction was made. This means the in and out of the process would be clear to the user. They are also known as CART, i.e Classification And Regression Trees. It can be visualized as a binary tree (the one studied in data structures and algorithms).Every node in the tree represents a single input ... Read More

Explain how scikit-learn library can be used to split the dataset for training and testing purposes in Python?

AmitDiwan
Updated on 11-Dec-2020 10:24:12

260 Views

Scikit-learn, commonly known as sklearn is a library in Python that is used for the purpose of implementing machine learning algorithms. It is powerful and robust, since it provides a wide variety of tools to perform statistical modelling.This includes classification, regression, clustering, dimensionality reduction, and much more with the help of a powerful, and stable interface in Python. Built on Numpy, SciPy and Matplotlib libraries.Before passing the input data to the Machine Learning algorithm, it has to be split into training and test dataset.Once the data is fit to the chosen model, the input dataset is trained on this model. ... Read More

Advertisements