Found 33676 Articles for Programming

How can SciPy be used to calculate the cube root of values and exponential values in Python?

AmitDiwan
Updated on 10-Dec-2020 13:36:14

566 Views

When it is required to find the cube root of values, a function present in SciPy library can be used.Syntax of ‘cbrt’ functionscipy.special.cbrt(x)The ‘x’ is the parameter that is passed to the function ‘cbrt’ that is present in ‘special’ class of ‘SciPy’ library. Here’s an example −Example Live Demofrom scipy.special import cbrt my_cb = cbrt([27, 89]) print("The cube roots are :") print(my_cb)OutputThe cube roots are : [3. 4.4647451]ExplanationThe required packages are imported.The ‘cbrt’ function is called on the list of values whose cube root needs to be computed.The output is displayed on the console.When it is required to find the 10**x ... Read More

How can scikit learn library be used to preprocess data in Python?

AmitDiwan
Updated on 10-Dec-2020 13:34:59

320 Views

Pre-processing data refers to cleaning of data, removing invalid data, noise, replacing data with relevant values and so on.This doesn’t always mean text data; it could also be images or video processing as well. It is an important step in the machine learning pipeline.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).This is done so that the learning algorithm can learn from this dataset and give relevant results with high accuracy. Since real-world ... Read More

How to apply functions element-wise in a dataframe in Python?

AmitDiwan
Updated on 10-Dec-2020 13:30:21

1K+ Views

It may sometimes be required to apply certain functions along the elements of the dataframe. All the functions can’t be vectorised. This is where the function ‘applymap’ comes into picture.This takes a single value as input and returns a single value as output.Example Live Demoimport pandas as pd import numpy as np my_df = pd.DataFrame(np.random.randn(5, 5), columns=['col_1', 'col_2', 'col_3', 'col_4', 'col_5']) print("The dataframe generated is ") print(my_df) my_df.applymap(lambda x:x*11.45) print("Using the applymap function") print(my_df.apply(np.mean))OutputThe dataframe generated is     col_1       col_2      col_3      col_4     col_5 0  -0.671510  -0.860741   0.886484   0.842158   ... Read More

How can a specific operation be applied row wise or column wise in Pandas Python?

AmitDiwan
Updated on 10-Dec-2020 13:28:19

400 Views

It may sometimes be required to apply certain functions along the axes of a dataframe. The axis can be specified, otherwise the default axis is considered as column-wise, where every column is considered as an array.If the axis is specified, then the operations are performed row-wise on the data.The ‘apply’ function can be used in conjunction with the dot operator on the dataframe. Let us see an example −Example Live Demoimport pandas as pd import numpy as np my_data = {'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20])} print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The description of ... Read More

How can data be summarized in Pandas Python?

AmitDiwan
Updated on 10-Dec-2020 13:27:07

139 Views

Lots of information about the data can be obtained by using different functions on it. But if we wish to get all information on the data, the ‘describe’ function can be used.This function will give information such as ‘count’, ‘mean’, ‘standard deviation’, the 25th percentile, the 50th percentile, and the 75th percentile.Example Live Demoimport pandas as pd my_data = {'Name':pd.Series(['Tom', 'Jane', 'Vin', 'Eve', 'Will']), 'Age':pd.Series([45, 67, 89, 12, 23]), 'value':pd.Series([8.79, 23.24, 31.98, 78.56, 90.20]) } print("The dataframe is :") my_df = pd.DataFrame(my_data) print(my_df) print("The description of data is :") print(my_df.describe())OutputThe dataframe is :    Name  Age   value 0  Tom   ... Read More

How to find the standard deviation of specific columns in a dataframe in Pandas Python?

AmitDiwan
Updated on 10-Dec-2020 13:25:13

7K+ Views

Standard deviation tells about how the values in the dataset are spread. They also tells how far the values in the dataset are from the arithmetic mean of the columns in the dataset.Sometimes, it may be required to get the standard deviation of a specific column that is numeric in nature. This is where the std() function can be used. The column whose mean needs to be computed can be indexed to the dataframe, and the mean function can be called on this using the dot operator.The index of the column can also be passed to find the standard deviation.Let ... Read More

How to get the mean of a specific column in a dataframe in Python?

AmitDiwan
Updated on 10-Dec-2020 13:23:58

2K+ Views

Sometimes, it may be required to get the mean value of a specific column that is numeric in nature. This is where the ‘mean’ function can be used.The column whose mean needs to be computed can be indexed to the dataframe, and the mean function can be called on this using the dot operator.The index of the column can also be passed to find the mean. The term mean() refers to finding the sum of all values and dividing it by the total number of values in the dataset.Let us see a demonstration of the same −Example Live Demoimport pandas as ... Read More

How can decision tree be used to construct a classifier in Python?

AmitDiwan
Updated on 10-Dec-2020 13:20:24

185 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. They are extremely popular because they are easy to understand.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 a foundation for ensemble methods such as bagging, random forests, and gradient boosting. They are also known as CART, i.e. Classification And Regression Trees. ... Read More

Discuss how the sort function can be applied on NumPy arrays in Python?

AmitDiwan
Updated on 10-Dec-2020 13:17:58

638 Views

NumPy refers to ‘Numerical’ ‘Python’. It is a library that contains multidimensional array objects and multiple methods that help in processing the arrays. NumPy can be used to perform a wide variety of operations on arrays. It is used in conjunction with packages like SciPy, Matplotlib and so on. NumPy+Matplotlib can be understood as an alternative to MatLab. It is an open source package, which means it can be used by anyone.The most important object present in NumPy package is an n-dimensional array which is known as ‘ndarray’. It defines the collection of items of the same type. These values ... Read More

How to find contours of an image using scikit-learn in Python?

AmitDiwan
Updated on 10-Dec-2020 13:16:32

1K+ 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 an open-source library hence it can be used free of cost. This library is built on Numpy, SciPy and Matplotlib libraries.The method of ‘marching squares’ is used to find the contours in an image. The function ‘find_contours’ present in the ‘measure’ class of ‘skimage’ library is used. In this, the values present in the array are interpolated in a linear manner.This way, the precision of the contours in the output image would be much better. If the ... Read More

Advertisements