Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Friday, April 23, 2021

Describing the use of Statistics in Machine Learning - A full detailed article on some of the most important concepts in Statistics

 

Describing the use of Statistics


* Its important to skim through some of the basic statistical concepts related to probability and statistics . Along with that , we will also try to understand how these concepts can help someone to describe the information used by machine learning algorithms


 * Some of the main concepts that I shall also try to cover in my articles leading to a stronger foothold over the various sections of Statistics are the following topics -- sampling, statistical distributions, statistical descriptive measures.. etc which in one way or the other are based on the concepts of algebra and probability in some or the other ways as they are nothing but more elaborate manifestations of the concepts and theorems of mathematics .

 

* The zist of all the learning of these concepts is not only about how to describe an event by counting the number of occurrences , but its about describing an event without counting every time how many times a particular event occurs .

 

* If there are some imprecision in a recording instrument that one uses , or simply because some error in the the recording procedure of a machine occurs , rather an imprecision occurs in the instrument that one uses or simply because of any random nuisance which disturbs the process of recording a given measure during the process of recording the measure occurs ... then a simple measure such as weight , will differ every time one would get a scale which would be slightly oscillating around the true weights and minimal variation scale . Now , if someone wants to perform such a small incident in a city and want to measure the weight of all the people in the city , then it is probably an impossible experiment to be conducted on such a large scale as it would involve taking the weight-wise reading of all the people in the city which is something that is practically not possible , because first of all if someone wants to perform this experiment in one go , then one has to create a big big gigantic weighing scale to mount all the people of the city in its weighing pans , which is completely an impossible task , and probably the scale may break once all the people have been mounted to the pan or otherwise the worst thing that may happen is that once all the people's weights have been measured , the experiment could render itself insignificant as the experiment once conducted would make the use of the weighing machine useless and hence the cost associated with building of such a big machine for carrying out just one task would become meaningless .

* So , the purpose of experiment might get achieved , but the cost of the built-up of the instrument would run so high that a big dent in the overall GDP of the city would get created which might cripple the city's finance and budget . On the other hand , if we take the measurement of the entire city's weight recording each person's weight one by one , then the effort and time taken for the entire activity to be completed might take some weeks or months of time . Because of the high amount of time and effort that would get consumed while managing the entire ruckus won’t suit the idea for adaptability and taking up the idea. And even if all the weights of the people residing in the city is successfully measured, there are a lot of chances that anyhow some amount for error would definitely popup making the idea of the entire process not so fruitful and fault-proof

 

* Having partial information is a quite complex process which is not a completely negative condition because one can use such smaller matrices for the purpose of efficient and less cumbersome calculations. Also on top of that, it is said that one cannot get a sample of what one wants to describe and learn because the event's complexity might be quite high and may probably feature a great variety of features . Another example that some users could consider while taking a case of a sample or a large case of data , is a case of Twitter tweets . All the tweets may be considered as some sample of data over where the same data could be treated as some experimental potions and minerals which are processed using several word processors , sentiment analyzers , business enhancers , spam , abusive data and all depending upon the sample of data associated with each of the text within the short frame of data that one can provide within the text section .

 

* Therefore it is also a good practice in sampling to sample similar data which has associated characteristics and features which will present the sample data in the form of a grouped cohesive data which fit into a proper sampling criteria. And when sampling is done carefully, one can get an idea that one can obtain a better global view of the data from the constituent samples

 

* In Statistics , a population refers to all the events and objects that one wants to measure and is a part of the given criteria which gives in detail the account of metrices of the population . Using the concept of random sampling , which is picking the events or objects one needs to choose one's examples according to the criteria which would determine how the data is collected ,assembled and synthesised. This is then used for feeding into machine learning algorithms which apply their inherent functions for determination of patterns and behaviour.

 

* Along with such determination , a probabilistic model of input data is built which is used for prediction of similar patterns from any newly input data or datasets ,Application of this concept of data generation from population's subsamples and mapping the identified patterns to map new use cases is one of subsamples the chief objectives of machine learning on the back of supported algorithms

 

* "Random Sampling" -- It is not the only approach for any sort of sampling . One can also apply an approach of "stratified sampling" through which one can control some aspects of the random sample in order to avoid picking too many or too few events of a certain kind .After all , it is said that a random sample is a random sample , the manner it gets picked is irrespective of the manner in which all samples would criterion themselves for picking up a sample , and there is no absolute assurance of always replicating an exact distribution of a population .

 

* A distribution is a statistical formulation which describes how to observe any event or a measure by ideating the probability of witnessing a certain value . Distributions are described in Mathematical formula and can be graphically described using charts such as histograms or distribution plots . The  information that one wants to put over the matrix has a distribution , and one may find that the distributions of different features are related to each other . A normal distribution naturally implies variation and when dealing with numeric values , it is very important to figure out a center of variation which is essentially a value which corresponds to the statistical mean which can be calculated by summing all the values and then dividing the sum by the total number of values considered .

 

* Mean - This is specifically a descriptive measure which tells the users the values to expect the most from within dataset . as it is a general fact that most of the times , one can observe that the mean of a dataset is that data which generally hovers around a given data group or the entire dataset . The Mean of a dataset is the best suited data for any symmetrical and bell-shaped distribution . In cases , when the value is above the mean of the entire dataset , the distribution is similarly shaped for the values that lie below the mean . The normal distribution or the Gaussian distribution is shaped around the mean which one can find only when one is dealing with legible data which is not much skewed in any direction from the equally shaped domes of the normal distribution curve . In the real world , in most of the datasets one can find many skewed distributions that have extreme values on one side of the distribution , which influences the value of mean so much

 

* Median - The Median is a measure that takes the value in the middle after one orders all the observations from smallest to the largest values within the dataset . Based on the value order, the median is a less approximate measure of central approximation of data .

 

* Variance - The significance of mean and median data descriptors is that they describe a value within a data description around which there is some form of variation . In general, the significance of the mean and median descriptors is variation. In general , the significance of the mean and median descriptors is that they describe a value within the distribution around which there is a variation and machine learning algorithms generally do not care about such a form of variation . Most people generally refer to the term , variation as "variance" . And since , variance is a squared number there is also a root equivalent which is termed as "Standard Deviation" . Machine Learning takes into account the concept of variance in every single variable (univariate distributions) and in all the features together (multivariate distribution) to determine how such a variation impacts the response obtained .

 

* Statistics is an important matter in machine learning because it conveys the idea that features have a distribution pattern . Distribution of data implies variation and variation means quantification of information ... which means that more amount of variance is present in the features , then the more amount of Information can be matched to the response .

 

* One can use statistics to assess the quality of the feature matrix and then leverage statistical measures in order to draw a rule from the types of information to their purposes that they cater to .

 

Wednesday, April 21, 2021

An article on - Conditioning Chance and Probability by Bayes Theorem

Conditioning Chance & Probability by Bayes Theorem


* Probability is one of the most key important factors that takes into effect the condition of time and space but there are other measures which go hand in hand with the measures that go into calculation of probability values and that is Conditional Probability which takes into effect the chance of occurrence of one particular event with effect to occurrence of some other events that may also affect the possibility and probability of the other event .

 

* When one would like to estimate the probability of any given event , one may believe the probability of some value to be applicable to some values which one may calculate upon a set of possible events or situations . This term is used to express a belief of "apriori probability" which means general probability of any given event .

 

* For example , in the condition of a throw of a coin ... if the coin thrown is a fair coin , then it could be said that the apriori probability of occurrence of a head is around 50 percent . This means that when someone would go for tossing a coin , he already knows what is the probability of occurrence of a positive ( in other words .. desired outcome ) otherwise occurrence of a negative outcome ( in other words .. undesired outcome ) .

 

* Therefore , no matter how many times one would toss a coin .. whenever faced with a new toss the probability of occurrence of a heads is still 50 percent and the probability of occurrence of a tail is still 50 percent .

 

* But consider a situation where if someone wishes to change the context , then the subject of apriori probability is not valid anymore .. because something subtle has happened and changed the outcome as we all know there are some prerequisites and conditions that must satisfy so that the general experiment could be carried out and come to fruitition. In such a case , one can express the belief as a form of posteriori probability which is the priori probability after something has happened that would tend to modify the count or outcome of the event .

 

* For instance , gender estimation for a person being either a male or a female is the same which is about 50 percent in almost all of the cases . But this general assumption that any population taken into account would be having the same demography is wrong as I happened to come across my referenced article that what generally happens in a demographic population is that generally the women are the ones who tend to live longer and exceed their counterpart males in most of the cases in all of human existence .. as they are mostly the ones who tend to live longer and exceed their counterpart males in most of the factors that contribute to the general well being , and as a result of which the population demographic tilt is more towards the female gender .

 

 Hence , putting all these factors into account that contribute to the general estimate of any population , one should not ideally take gender as a main parameter for determination of population data because this factor is tilted in age-brackets and hence an overall idea for generalisation of this factor should not be considered .

 

* Again , taking this factor of gender into account , the posteriori probability is different from the expected apriori one which in this example can consider gender to be the parameter for estimation of population data and thus estimate somebody's probability of gender on the belief that there are 50 percent males and 50 percent females in a given population data .

 

* One can view cases of conditional probability in the given manner P(y(x)) which in mathematical sense can be read as probability of the event y given the probability of occurrence of event x takes place . For the great relevance Conditional Probability plays in the concepts and studies of machine learning , learning and understanding the syntax of representation , expression and comprehension of the given equation is of great paramount importance to any newbie or virtuoso in the field of maths , statistics and machine learning . Hence , again if someone comes across a notation for conditional probability in the form P(y(x)) which can be read as the probability of event Y happening given X has already happened .

 

* As mentioned earlier in the above paragraph , because of its dependence on possibility of occurrence on single or multiple prior conditions , the role of conditional probability is of paramount importance for machine learning which takes into effect statistical conditions of occurrence of any event . If the apriori probability can change because of circumstances, knowing the possible circumstances can give a big push in one's chances of correctly predicting any event by observing the underlying examples - exactly what machine learning generally intends to do .

 

* Generally , the possibility of finding a random person's gender as a male or female is around 50 percent . But , in case one would like to take into consideration the mortal aspects and age factor of any population , we have seen that the demographic tilt is more in favour of females . If under all such conditions , one would take into consideration the female population , and then dictate a machine learning algorithm to find out the gender of the considered person on the basis of their apriori conditions like length of hair , mortality rate etc , the ML algorithm would be able to very well determine the solicited answer

An article on - Bayes Theorem application and usage

 

Bayes Theorem application and usage

 

Instance and example of usage of Bayes Theorem in Maths and Statistics :

 

P(B|E) = P(E|B)*P(B) / P(E)

 

If one reads the formula , then one will come across the following terms within the instance which can be elaborated with the help of an instance in the following manner :

 

* P( B | E ) - The probability of a belief(B) given a set of evidence(E) is called over here as Posterior Probability . Here , this statement tries to convey the underlying first condition that would be evaluated for going forth over to the next condition for sequential execution . In the given case , the hypothesis that is presented to the reader is whether a person is a female and given the length of her hair is sufficiently long , the subject in concern must be a girl

 

* P( E | B ) - In this conditional form of probability expression , it is expressed that one could be a female given the condition that the subject has sufficiently long hair . In this case , the equation translates to a form of conditional probability .

 

* P ( B ) - Here , the case B stands for the general probaility of being a female with a priori probability of the belief . In the given case , the probability is around 50 percent which could be also translated to a likelihood of occurrence of around 0.5 likelihood

 

 

* P(E) - This is the case of calculating the general probability of having long hair . As per general belief , in a conditional probability equation this term should be also treated as a case of priori probability which means the value for its probability estimate is available well in advance and therefore , the value is pivotal for formulation of the posterior probability

If one would be able to solve the previous problem using the Bayes Formula , then all the constituent values would be put in the given equation which would fill in the given values of the equation .

The same type of analogy is also required for estimation of a certain disease among a certain set of population where one would very likely take to calculate the presence of any particular disease within a given population . For this one needs to undergo a certain type of test which would result in producing a viable or a positive result .

 

Generally , it is perceived that most of the medical tests are not completely accurate and the laboratory would tell for the presence of a certain malignancy within a test which would convey a condensed result about the condition of within a test which would convey a condensed result about the condition of illness of the concerned case .

 

For the case , when one would like to see the number of people showing a positive response from a test is as follows :

1) Case -1 : Who is ill and who gets the correct answer from the test .

This is normally used for the case of estimation of true positives which amounts to 99 percent of the 1 percent of the population who get the illness

2) Case-2 : Who is not ill and who gets the wrong diagnosis result from the test . This group consists of 1 percent of the 99 percent of the population who would get a positive response , even though the illness hasn't been completely discovered or ascertained in the given cases . Again , this is a multiplication of 99 percent and 1 percent ; this group would correspond to the discovery of false positive cases among the given sample . In simple words , this category of grouping takes into its ambit , those patients who are actually not ill (may be fit and fine ) , but due to some aberrations or mistakes in the report which might be under the case of mis-diagnosis of a patient that , the patient is discovered

as a ill person . Under such circumstances, untoward cases of administration of wrong medicines might happen , which rather than curing the person of the given illness might inflict aggravations over the person rendering him more vulnerable to hazards , catastrophies and probably untimely death

 

* So going through the given cases of estimation of correct cases of Classification for a certain disease or illness could help in proper medicine administration which could help in recovery of the patient owing to right Classification of the case ; and if not then the patient would be wrongly classified in a wrong category and probably wrong medicines could get administered to the patient seeking medical assistance for his illness .

 

( I hope , there is some understanding clarity in the cases where the role of Bayesian Probability estimations could be put to use . As mentioned , the usage of this algorithm takes place in a wide-manner for the case of proper treatment and classification of illnesses and patients ; classification of fraudulent cases or credit card / debt card utilisation , productivity of employees at a given organisation by the management after evaluation of certain metrices :P ...... I shall try to extend the use case and applications of this theorem in later blogs and articles )

 

Tuesday, April 20, 2021

Some Operating cases on Probabilities

                   Some Operating cases on Probabilities


 * It is suggested that operations on probabilities are a bit different from numeric operations because the range of occurrence of such probability values generally lies between the range of 0 & 1

 

* One must rely on some set or rules in order for the operation to make sense to the user who is conducting the experiment on probabilities. For example , if someone is conducting an experiment of tossing a coin then he/she must strictly define the rules according to which the game of tossing a coin would be played out . The instructor would declare which outcomes should be taken as valid outcomes and which should not be taken in as valid outcomes , rather must be negated the moment the norms of the game are violated .


 * For example , suppose say a case happens over where a coin does not fall over any of the sides rather falls over the floor standing erect , then the outcome is neither a heads and nor a tails , and neither a 50-50 heads-tails can be taken as consideration for the throw of the dice . Rather what would happen in such a circumstance is that the throw of the dice for this case would be nullified , the entire event of throw of such a dice would be struck off from the probable set of outputs that should happen as a result of the throw of the dice . Thats why one should also keep adhering to the rules of the experiment before conducting such an experiment which would require to know what set of events should be taken in as considerable outcomes and which should not be considered .

 

* Again another property of Probabilities that one needs to be aware is summations between probabilities which states that summations of probabilities is possible only when all the constituting events of the sample space are mutually exclusive to each other . For example lets consider an experiment of rolling a dice over a game of ludo , in this all the possible events that could turn up as a result of throw of the dice are 1 , 2 , 3 , 4 , 5 , 6 . The probability of occurrence of each of the events is 1/6 or 1 by 6 . And here , each of the events within the given sample space are disjoint and mutually exclusive to each other which makes the individual events probability of occurrence as equal to each of the given event divided by the total number of events over the entire sample space . And in case one would like to know the probability of occurrence of all the events together in unison , then one may have to add up the probabilities of each of the individual events as a summation of each of the individual events .. which would yield an output of 1 . So in retrospect, all individual elements of an experiment of probability are disjoint and mutually exclusive and in unison lead to a summed up value of 1 .

 

* We can take another simple example to demonstrate to demonstrate the case of understanding of probability calculation ; in this case one can consider for example the case of picking a spade or a diamond from a set of cards can be calculated in the following manner . Total number of cards in the entire deck = 52 . Number of cards in the house of clubs = 13 , number of cards in the house of clubs = 13 , number of cards in the house of hearts = 13 , number of cards in the house of diamonds = 13 . If a person takes out a card from the house of diamond then the probability if picking up one of the cards is 13/52 ; the same goes for the case of picking up a random card from a house of clubs is 13/52 . So , total probability of finding a card from both the houses is 26/52 which is equals to 0.5

 

* One can take the help of subtraction operation to determine the probability of some events where probability of an event is different from the probability of an event that one would want to compare . For instance , if someone wants to determine the probability of drawing a card that does not belong to some house of card for example , say I want to draw a card which is not a diamond from the overall deck of cards , then one will approach the problem in the given manner . He will first find out the overall probability of finding any card and then he will subtract the chance of occurrence of a particular card from the total , 1 - 0.25 which happens to be as 0.75. One could get a complement of the occurrence of the card in this manner , which could be used for finding the probability of not occurrence of a particular event .

 

* Multiplication of a set of events can be helpful for finding the intersection of a set of independent events . Independent Events are those which do not influence each other . For instance , if one is playing a game of dice and one would like to throw two dices together , then the probability of getting two sixes is 1/ 36 . This can be obtained by multiplication of dices over both the cards , where first the probability of obtaining a 6 is found out to be as 1/6 and then the subsequent independent event would also produce an probability of obtaining another 6 is found out to be as 1/6 , here both the values are multiplied with each other and found that product of both the probabilities of independent events would yield a value output as 1/36 or 0.28 .

 

* Using the concepts of summation , difference and multiplication , one can obtain the probability of most of the calculations which deal with events . For instance , if one would want to compare the probability of getting atleast a six from two throws of dice which is a summation of mutually exclusive events . Probability of obtaining two sixes of dice , p = 1/6* 1/6 = 1/36

 

* In a similar manner if one would like to calculate the probability of having a six on the first dice and then something other than a six on the second throw of the dice is p = (1/6)*(1- 1/6) = 5/36 ,

 

* Probability of getting a six from two thrown dice is p = 1/6* 1/6 +2*1/6*(1- 1/6) = 11/36

 

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 .

Using Vectorisation Effectively in Python and R – a revision example

 


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

     Using Vectorisation Effectively in Python and R – instance example

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


·        While performing Matrix Operations, such as Vector Multiplication , its very hard to consider that the computer does all the forms of hard work .  What does one need to do while working on numbers in a Vectorised form?

 ·        So , while one is working upon numbers , one needs to put the numbers in the form of matrices , vectors and constants and then one can sum , subtract , divide and then multiply the numbers .

 ·        These operations can be performed upon any number which is in the form of Vectors .

 ·        So , when one deals with these vectorised form of numbers in Machine Learning , then one should also have a good ( good is a relative value that lies in between novice and expert ) understanding and know how on how to feed the vectorised data to the algorithm over which the encoded function is going to work upon , which would help the programmer to know and understand the results obtained after the processing of the data is done .

 ·        In order to obtain a correct result , one may need to feed the right data to the right algorihtm .

 ·        In Python, Numpy package offers all the functionality needed to create and manipulate the matrices . The "ndarray" objects allow fast creation of an array , such as a multidimensional matrix by starting with data which are queued into the lists

 ·        The term "ndarray" means "n-dimensional array" which implies that one can create arrays of multiple dimensions like one-dimensional array , 2 dimensional array , 3 dimensional array and so on .

 

 

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

Using a simple Vector for creation of a Numpy List

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

 

import numpy as np

y = np.array([43, 45,47,49,51])

print(y)

print(y.shape)

 

Output

[43,45,47,49,51]

(5,)

 

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

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

 

* The method "shape" can promptly inform someone about the shape of a matrix . In the above given example , one can see that the shape of the matrix is just a one-dimensional entity which reports only three rows and no columns which means that the object is a vector

 * In order to create matrices made of rows and columns , one can make use of lists of list items .

 * The contents of the list inside the main list are the rows of one's matrix

 

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

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

import numpy as np

X = np.array([1.1,1,545,1],[4.6,0,345,2],[7.2,1,754,3])

print(X)

 

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

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

 * The output of the following operation would yield a vector which one can reshape into any desired form of rows and columns .

 * Here , the numbers are filled into the new matrix stacked into it in the form of row data which is occupied from the top most to the lowermost elements of the array which are stored in the output object "X" which would store in it all the elements in an iterative manner containing all the elements in i,j manner . Elements in an iterative manner containing all the elements in i,j manner .

 * Operations with addition and subtractions with scalars using the numpy "ndarray" is the best method of performing any operation .

 

* One can do the following operation - sum , subtract , multiply or divide using the severall standard operators applicable over Python language in the given manner . Lets take two data-array objects .. a and b

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

a = np.array([[1,1],[1,0]])

b = np.array([[1,0],[0,1]])

print(a - b)

[[ 0 1] [1 -1]]

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

a = np.array([[0,1],[1,-1]])

print(a * -2)

[[ 0 -2 ]

[ 2 -2 ]]

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

 * In order to perform multiplication on vectors and matrices , one needs to use the "np.dot" function . The input for this function is two arrays which are of compatible sizes to multiply according to the given order

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

X = np.array([[4,5],[2,4],[3,3]])

b = np.array([3,-2])

print(np.dot(X,b))

[ 2 -2  3 ]

B = np.array([3,-2],[-2,5])

print(np.dot(X,B))

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


 * The same form of multi-dimensional array output can be also produced by an array which one can find in the below set of code . One does not need any additional set of libraries while using R , R performs the tasks using standard functions as given in the below set of code .

 

* One can define the dimensions of one's vector using the "length()" function . But one can use the dis() function instead for the matrices , because applying the length() function to a matrix shows the output to carry only some number of elements in it .

 


Ref : Machine Learning in R and Python -