Found 26504 Articles for Server Side Programming

Explain the basics of scikit-learn library in Python?

AmitDiwan
Updated on 11-Dec-2020 10:16:02

394 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. 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. This library is built on Numpy, SciPy and Matplotlib libraries.It can be installed using the ‘pip’ command as shown below −pip install scikit-learnThis library focuses on data modelling.There are many models ... Read More

Explain how Nelder-Mead algorithm can be implemented using SciPy Python?

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

717 Views

SciPy library can be used to perform complex scientific computations at speed, with high efficiency. Nelder-Mead algorithm is also known as simple search algorithm.It is considered to be one of the best algorithms that can be used to solve parameter estimation problems, and statistical problems. Relevant to use this algorithm in situations where the values of functions are uncertain or have lots of noise associated with it.This algorithm can also be used to work with discontinuous functions which occur frequently in statistics. It is a simple algorithm and it is easy to understand as well. Used to minimize the parameters ... Read More

Explain how the minimum of a scalar function can be found in SciPy using Python?

AmitDiwan
Updated on 10-Dec-2020 13:45:53

182 Views

Finding the minimum of a scalar function is an optimization problem. Optimization problems help improve the quality of the solution, thereby yielding better results with higher performances. Optimization problems are also used for curve fitting, root fitting, and so on.Let us see an example −Exampleimport matplotlib.pyplot as plt from scipy import optimize import numpy as np print("The function is defined") def my_func(a):    return a*2 + 20 * np.sin(a) plt.plot(a, my_func(a)) print("Plotting the graph") plt.show() print(optimize.fmin_bfgs(my_func, 0))OutputOptimization terminated successfully.    Current function value: -23.241676    Iterations: 4    Function evaluations: 18    Gradient evaluations: 6 [-1.67096375]ExplanationThe required packages are imported.A ... Read More

How can discrete Fourier transform be performed in SciPy Python?

AmitDiwan
Updated on 10-Dec-2020 13:44:39

556 Views

Discrete Fourier Transform, or DFT is a mathematical technique that helps in the conversion of spatial data into frequency data.Fast Fourier Transformation, or FTT is an algorithm that has been designed to compute the Discrete Fourier Transformation of spatial data.The spatial data is usually in the form of a multidimensional array. Frequency data refers to data that contains information about the number of signals or wavelengths in a specific period of time.Let us see how this DFT can be achieved using the ‘SciPy’ library.The graph is created using the matplotlib library and data is generated using the Numpy library −ExampleFrom ... Read More

How can SciPy be used to calculate the eigen values and eigen vectors of a matrix in Python?

AmitDiwan
Updated on 10-Dec-2020 13:42:50

2K+ Views

Eigen vectors and Eigen values find their uses in many situations. The word ‘Eigen’ in German means ‘own’ or ‘typical’. An Eigen vector is also known as a ‘characteristic vector’. Suppose we need to perform some transformation on a dataset but the given condition is that the direction of data in the dataset shouldn’t change. This is when Eigen vectors and Eigen values can be used.Given a square matrix (a matrix where the number of rows is equal to the number of columns), an Eigen value and an Eigen vector fulfil the below equation.Eigen vectors are computed after finding the ... Read More

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

AmitDiwan
Updated on 10-Dec-2020 13:40:49

126 Views

We have previously used slicing with the help of operator ‘:’, which is used in the case of extracting top ‘n’ elements from series structure. It helps assign a range to the series elements that will later be displayed.Let us see an example −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("Top 3 elements are :") print(my_series[:n])OutputThe series contains following elements ab  34 mn  56 gh  78 kl  90 wq  123 az ... Read More

Explain the different ways in which data from a series data structure can be accessed in Python?

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

129 Views

The ability to index elements and access them using their positional index values serves a great purpose when we need to access specific values.Let us see how series data structure can be index to get value from a specific index.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) print("The second element (zero-based indexing)") print(my_series[2]) print("Elements from 2 to the last element are") print(my_series[2:])OutputThe series contains following elements ab  34 mn  56 gh  78 kl  90 wq ... Read More

Explain how series data structure in Python can be created using dictionary and explicit index values?

AmitDiwan
Updated on 10-Dec-2020 13:37:38

178 Views

Let us understand how series data structure can be created using dictionary, as well as specifying the index values, i.e., customized index values to the series.Dictionary is a Python data structure that has a mapping kind of structure- a key, value pair.Example Live Demoimport pandas as pd my_data = {'ab' : 11., 'mn' : 15., 'gh' : 28., 'kl' : 45.} my_index = ['ab', 'mn' ,'gh', 'kl'] my_series = pd.Series(my_data, index = my_index) print("This is series data structure created using dictionary and specifying index values") print(my_series)OutputThis is series data structure created using dictionary and specifying index values ab  11.0 mn  15.0 ... Read More

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

567 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

321 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

Advertisements