Showing posts with label pandas. Show all posts
Showing posts with label pandas. Show all posts

Monday, July 12, 2021

Infographic Note on Correlation Analysis using corr() function over a Pandas dataframe in Python

 


Infographic Note on Correlation Analysis of numerical attributes of a Pandas Dataframe in Python



 

Infographic Note on Python Code Analysis of a Sample Outliers Detection function over a numerical attribute in a pandas dataframe

 


Infographic Note on Outliers Detection , finding Inter-Quartile ranges and Interpreting Box-Plot diagrams over Pandas Dataframe in Python

 




Infographic Note on steps to perform Count , filter , group and aggregate numerical values over a dataset using Numpy and Pandas in Python using Jupyter Notebook IDE

 




Infographic Note on steps to formulate and perform a Hypothesis Test using Numpy , Pandas and Scipy Libraries of Python


 

Monday, June 7, 2021

Lists and Dictionaries in Python Dictionaries in Python

 When should one use dictionaries and when should one use lists in Python

 =====================================================

 *  Lists are the most widely used data when the data is stored in the form of integral indexes with some starting position to some given position within the Python list

 *  Lists are also mostly used when the data that needs to be maintained in a certain specific manner or  where the data needs to be sorted where finding  some data is only good enough when the user of the given set of code is knowing the exact index or position of the item element where the list item needs to be searched or retrieved

 *  Lists are also used when the ordering of items within the List item object is irrelevant as any given element within a list can be searched and retrieved just by using some conditional loops which will iterate over the list item object and then the item could be put to use directly without any form of replacement or elimination within the data structure

 *  One of the main highlighting important points about Lists as a data structure for item storage is that Lists can be used for storage of other lists and tuples as a data storage within it because of which the main list containing the sub-lists within it could act as a parent list object which can keep within it other child objects for storage and retrieval as well

 *   Now coming to dictionaries and what they are used for :-

 *  Dictionaries are perfect storage objects when the data is to be stored on the basis of positonal indexes coupled with an adjoining value associated for that index position . Here also the ordering of the data is not of great matter and does not need to sort the stored data . Finding any associated data of the dictionary object needs only a key value of that object 


*   Example where a List is used for data storage is an example of a shopping cart where any stored item object's storage does not matter .


*  Example where a Dictionary Item object is used as a storage object is that of a an examination roll / rank number sheet ( parikhya patra ) where people are arranged on the basis of their marks obtained in some examination from Rank 1 to the last rank in the exam . Usually the person who obtains the highest marks in a given exam is attributted the 1st rank and the first roll number for that examination is also alloted to the first rank holder after the results are out , the successive role numbers are also attributed according the net marks obtained  by an examiner in the considered case of the examination till the last rank/roll number of the examiner .

 

*  A dictionary is very useful data storage object where one may need to access a given data based on the item that is present over a given index position within the storage object of the data structure .

 *  As a measure of how important the dictionaries are - every module , class , function and method written in Python in the form of dictionaries where all the attribute names are in the form of Keys and all the attribute values there in can be found quickly .

 *  Therefore when one wants to decide upon which data structure to be used for a certain type of data object one might need to consider the best use cases of both these data structure objects : Lists and Dictionary Items .


 ======================================

To sum up once again for Lists and Dictionaries

 =====================================

 

*  Lists are ordered data structure objects that means that the program has control over the order in which the data is stored . This data is also sortable that means that the program can sort the data into whatever order when the data is needed to be fetched and retrieved , the list is also containing a list of iterable items i,e items that can be accessed one item at a time when the list object is iterated or executed within a loop .

 

*  Dictionaries are like the partially ordered data structures that can control the order or the manner in which the data items are inserted and stored within the object in the form of keys and attributes . Dictionaries are non-sortable and iterable in pairs of both keys and associated value objects .



 

 

 

 

 

 

 

 

 

Last modified: 18:49

Monday, April 19, 2021

Advanced Matrix Operations – A theoretical view

                     


  Advanced Matrix Operations – A theoretical view               ========================================

 

* One may encounter some important matrix operations using algorithmic formulations

 

* The advanced matrix operations are formulating the transpose and inverse of any given matrix form of dataset

 

* Transposition occurs when a matrix of shape n x m is transformed into a matrix in the form of m x n by exchanging the rows with the columns

 

* Most of the tests indicate the operation using the superscript T in the form of A( transpose )

 

* One can apply " matrix inversion " over matrices of shape m x m , which are square matrices that have the same number of rows and columns . In mathematical language , this form of square ordering of matrices is said that the matrix has m rows and m columns .

 

* The above operation is important for the sake of finding the immediate resolution of the various equations which involve matrix multiplication such as y = bX where one has to discover the values in the vector b . More on Matrix multiplications with more conceptual examples would be showcased in another article in which I shall try to cover how the Matrix Multiplication of different Matrices occur and how this Multiplication is used to solve more important / complex problems .

 

 

* Since most scalar numbers (exceptions including zero) have a number whose multiplication results in a value of 1 , the idea is to find a matrix inverse whose multiplication would result in a special matrix called the identity matrix whose elements are zero , except the diagonal elements

 ( the elements in positions where the index 1 is equal to the index j)

* Now , if one wants to find the inverse of a scalar quantity , then one can do so by finding the inverse of a scalar . (The scalar number n has an inverse value that is n to the power minus 1 which can be represented by 1/n that is 1 upon n )

 

* Sometimes, finding the inverse of a matrix is impossible and hence the inverse of a matrix A is indicated as A to the power minus 1

 

* When a matrix cannot be inverted, it is referred to "singular matrix" or a "degenerate matrix" . Singular matrices are usually not found in isolation, rather are quite rare to occur and generalise .

Friday, April 16, 2021

Static Methods in Python - Example of a Static Method in a Class in Python

 


    Static Methods in Python


* One can use Static Methods while the class level but one may not involve the class or the constituting instances .

 

* Static Methods are used when one wants to process an element in relation to a class but does not need the class or its instance to perform any work .

 

* Example :

writing the environmental variables that go inside creation of a class , counting the number of instances of the class or changing an attribute in another class are the tasks related to a class .. such tasks can be handled by Static Methods

 

* Static Methods can be used to accept some values , process the values and then return the result .

 

* Also one could use Static Methods to accept some values , process the values and then return the result

 

* In this case , the involvement of neither the class nor the objects is of paramount importance .

 

* Static methods are written with a decorator @staticmethod above the methods

 

* Static Methods are called in the form of classname,method()

 

* In the following method , one is creating a static method "noObjects()" that counts the number of objects or instances created in MyClass . In MyClass , one can write a constructor that increments the class variable 'n' everytime an instance of the class is created . This incremented value of 'n' gets displayed by the "noObject()" method

  


 

Class Methods in Python - An example of creation of a Class Method in Python along with sample code

 


    Class Methods in Python


* These are the set of Methods are act on class level . Class Methods are the methods which act on the class variables or static variables .

 

* The Class Methods can be written using @classmethod decorator above them .

 

* For example , 'cls.var' is the format to refer to the class variable which includes methods which can be generally called using the classname.method()

 

* The process which is commonly needed by all the instances of the class is handled by the class methods

 

* In the given example below, one can see the instance of the class which is handled by the class methods . The same program can be developed using an example class which can be used in the following manner .

 

* In the example , one can refer to a sample Bird Class for more insight into the description and elaboration of a Method Class . All the birds in nature have only 2 wings (as we mostly see , but there are abberations ofcourse ). Here , one can take an instance of a Bird Class . All the Birds in Nature have 2 wings , therefore one can take 'wings' as a class variable and a copy of this class variable is

available to all the instances of the Bird Class . In this Bird class , we will create a hypothetical method which applies to the functions that a Bird can operate upon and thus will make use of this method that is "fly" method (... to fly above the sky ... fly rhymes good with sky .. please accept from me a satirical High of Hi ... I am poetic too you know :P)

 

* So where was I .. ya I was at the forefront of creation of a class which would take into its ambit a Bird which would have some generic applicable class variables all applicable to the organism class of Birds like all Birds have a pair of wings .. that makes the count to 2 . And birds fly .. which is a method attributed to birds . These two class variables and class methods would be made use of to instantiate a generic sample class of a Bird

 

* So lets create a Bird with two wings and this flies too (I am sorry to know that when God created a Bird like Penguin , God forgot to add the the instance function "fly" to its class genus ... therefore I shall also keep this off the charts for penguins,kiwis and take only those birds which can fly ... up above the sky )

 

* Without further ado .. lets get to this class creation which would take into effect all the common features of all the instances of a Bird Class

  

==================================

==================================

# understanding class methods

class Bird:

     # calling a class variable

     wings = 2

     # creating a class method @classmethod

     def fly(cls,name):

     print('{} flies with {} wings'.format(name,cls.wings))

 

#display information of 2 birds

Bird.fly('Garuda')

Bird.fly('Pigeon')

Bird.fly('Crow')

Bird.fly('HummingBird')

Bird.fly('Eagle')

 

==================================

==================================

Output

Garuda flies with 2 wings

Pigeon flies with 2 wings

Crow flies with 2 wings

HummingBird flies with 2 wings

Eagle flies with 2 wings

==================================

==================================

 

Monday, April 12, 2021

Math behind Machine Learning - An introductory article on the usage of mathematics and statistics as the foundation of Machine Learning

 


        Math behind Machine Learning

 

* If one wants to implement existing machine learning algorithms from scratch or if someone wants to devise newer machine learning algorithms , then one would require a profound knowledge of probability , linear algebra , linear programming and multivariable calculus

 

* Along with that one may also need to translate math into a form of working code which means that one needs to have a good deal of sophisticated computing skills

 

* This article is an introduction which would help someone in understanding of the mechanics of machine learning and thereafter describe how to translate math basics into usable code

 

* If one would like to apply the existing machine learning knowledge for implementation of practical purposes and practical projects , then one can leverage the best of possibilities of machine learning over datasets using R language and Python language's software libraries using some basic knowledge of math , statistics and programming as Machine learning's core foundation is built upon skills in all of these languages

 

* Some of the things that can be accomplished with a clearer understanding and grasp over these languages is the following :

 

1) Performance of Machine Learning experiments using R and Python language

2) Knowledge upon Vectors , Variables and Matrices

3) Usage of Descriptive Statistics techniques

4) Knowledge of statistical methods like Mean , Median , Mode , Standard Deviation and other important parameters for judging or evaluating a model

5) Understanding the capabilities and methods in which Machine Learning could be put to work which would help in making better predictions etc