Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Gaurav Kumar
Page 2 of 3
How to solve triangular matrix equations using Python SciPy?
The linear function named scipy.linalg.solveh_triangular is used to solve the banded matrix equation. In the below given example we will be solving the triangular system ax = b where −$$\mathrm{a} = \begin{bmatrix} 3 & 0 & 0 & 0\ 2 & 1 & 0 & 0\ 1 &0 &1 &0 \ 1& 1& 1& 1 \end{bmatrix};\; \mathrm{b} =\begin{bmatrix} 1\ 2\ 1\ 2 \end{bmatrix}$$Examplefrom scipy.linalg import solve_triangular import numpy as np a = np.array([[3, 0, 0, 0], [2, 1, 0, 0], [1, 0, 1, 0], [1, 1, 1, 1]]) b = np.array([1, 2, 1, 2]) x = solve_triangular(a, b, lower=True) print (x)Outputarray([ 0.33333333, 1.33333333, 0.66666667, -0.33333333])
Read MoreWhat is Reinforcement Learning? How is it different from supervised and unsupervised learning?
In reinforcement learning methods, a trained agent interacts with a specific environment and takes actions based upon the current state of that environment.The working of reinforcement learning is as follows −First you need to prepare an agent with some specific set of strategies.Now leave the agent to observe the current state of the environment.Based on the agent's observation, select the optimal policy, and perform suitable action.Based on the action taken, the agent will get reward or penalty.Update the set of strategies used in step 1, if needed. Repeat the process from step1-4 until the agent learns and adopts the optimal ...
Read MoreWhat are the different learning styles in machine learning algorithms?
There are four learning styles in machine learning algorithms. Let’s have a look at them −Supervised LearningSupervised learning, one of the most used methods in ML, takes both training data (also called data samples) and its associated output (also called labels or responses) during the training process. The major goal of supervised learning methods is to learn the association between input training data and their labels. For this it performs multiple training data instances.Based on machine learning based tasks, we can divide supervised learning algorithms in two classes namely Classification and Regression.Unsupervised LearningUnsupervised learning methods, (opposite to supervised learning methods) ...
Read MoreWhy is Python the most popular programming language among ML professionals?
From process automation to web development to AI-based projects to machine learning, Python is used everywhere, and it helps developers to be productive and confident about the software they are building. Today, because of the benefits like simplicity, consistency, extensive set of libraries, platform independence, flexibility, and a wide community support, Python has become one of the most favored programming languages among machine learning professionals.Simplicity and Consistency − Machine learning relies on complex algorithms and workflows, but it is Python’s simplicity that allows machine learning developers to build reliable applications. Python is so simple that the developers do not need ...
Read MoreWhat are the various challenges for machine learning practitioners?
While machine learning is rapidly evolving, it still has a long way to go. The reasons behind this are the various challenges an ML practitioner faces while developing an application. Let’s take a look at these challenges −Data collection − Data plays the most important role in developing any machine learning application. Most of the work of an ML practitioner lies in collecting good quality data. If you are a beginner and want to experiment with machine learning, you can find datasets from Kaggle or UCI ML Repository. But if you want to implement real case scenarios or need to ...
Read MoreWhat are different components of a machine learning algorithm?
To understand various components of a machine learning algorithm, we first understand the definition of machine learning given by Professor Mitchell −“A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E.”As we can see the above definition, the main components of any machine learning algorithm are Task(T), Performance(P), and Experience(E).Based on these three components, let’s simplify the definition of machine learning −Machine learning is a subset of Artificial Intelligence (AI) and a field ...
Read MoreWhich linear function of SciPy is used to solve triangular matrix equations?
The linear function named scipy.linalg.solve_triangular is used to solve the triangular matrix e8quation. The form of this function is as follows −scipy.linalg.solve_triangular(a, b, trans=0, lower=False, unit_diagonal=False, overwrite_b=False, debug=None, check_finite=True)This linear function will solve the equation ax = b for x where a is a triangular matrix.P ParametersBelow are given the parameters of the function scipy.linalg.solve_triangular() −a− (M, M) array_likeThis parameter represents the triangular matrix.b− (M, ) or (M, N)array_likeThis parameter represents the right-hand side matrix in the equation ax = b.lower− bool, optionalBy using this parameter, we will be able to use only the data that is contained in the ...
Read MoreComparing ‘cubic’ and ‘linear’ 1-D interpolation using SciPy library
Below python script will compare the ‘cubic’ and ‘linear’ interpolation on same data using SciPy library −ExampleFirst let’s generate some data to implement interpolation on that −import numpy as np from scipy.interpolate import interp1d import matplotlib.pyplot as plt A = np.linspace(0, 10, num=11, endpoint=True) B = np.cos(-A**2/9.0) print (A, B)OutputThe above script will generate the following points between 0 and 4 − [ 0. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.] [ 1. 0.99383351 0.90284967 0.54030231 -0.20550672 -0.93454613 -0.65364362 0.6683999 0.67640492 -0.91113026 0.11527995]Now, let’s plot these points as follows −plt.plot(A, B, '.') plt.show()Now, based on fixed data ...
Read MoreCalculating the Hamming distance using SciPy
Hamming distance calculates the distance between two binary vectors. Mostly we find the binary strings when we use one-hot encoding on categorical columns of data. In one-hot encoding the integer variable is removed and a new binary variable will be added for each unique integer value. For example, if a column had the categories say ‘Length’, ‘Width’, and ‘Breadth’. We might one-hot encode each example as a bitstring with one bit for each column as follows −Length = [1, 0, 0]Width = [0, 1, 0]Breadth = [0, 0, 1]The Hamming distance between any of the two categories mentioned above, can ...
Read MoreWhat is the difference between scipy.cluster.vq.kmeans() and scipy.cluster.vq.kmeans2() methods?
The scipy.cluster.vq()has two methods to implement k-means clustering namely kmeans() and kmeans2(). There is a significant difference in the working of both these methods. Let us understand it −scipy.cluster.vq.kmeans(obs, k_or_guess, iter=20, thresh=1e-05, check_finite=True)− The kmeans() method forms k clusters by performing k-means algorithm on a set of observation vectors. To determine the stability of the centroids, this method uses a threshold value to compare the change in average Euclidean distance between the observations and their corresponding centroids. The output of this method is a code book mapping centroid to codes and vice versa.scipy.cluster.vq.kmeans2(data, k, iter=10, thresh=1e-05, minit='random', missing='warn', check_finite=True)− The ...
Read More