Introduction:
If you are working on machine learning, more than often, you will need to perform different types of matrix manipulations in r/python. I will mention some of such manipulations and regarding functions to use in r and python.
condition number finding:
condition number is generally used to find the stability as well non-singularity of a matrix. It is defined to be the ratio of absolute value of highest singular value and smallest singular value ( in terms of mod value). If a matrix has condition number more than 1000, then it is generally considered to be a unstable matrix.
For finding condition number of a matrix in r, we have to use the kappa() function. For normally using kappa, you need to use two parameters. First input to kappa has to be the matrix. The second one is exact parameter. This exact is set to be FALSE in general. In this setting, a cheap (computationally) approximation of condition number is obtained and provided. If you set kappa to be TRUE, then the method uses SVD and provides the exact value.
so the usecase is condition_number = kappa( matrix, exact = FALSE)
In case of python, you can import cond from numpy.linalg, i.e. the linear algebra library. cond takes the matrix as parameter and calculates the condition number.
determinant:
For determinant, it is amazing that both numpy.linalg and R has same function, called det(). det(), in both cases takes the matrix as parameter and provides the determinant value.
Comments
Post a Comment