Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability CMPE 302 Machine Learning Multivariate Linear Regression recalled Polynomial regression Over…tting and under…tting Generalization Expected Value, Variance, Covariance 1/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Multivariate Linear Regression Recall that the multivariable linear regression is a generalization of the linear regression approach to higher dimensions. Each input xi 2 R1xd is a vector with d attributes. In the previous setup we had d = 1. The outputs will be assumed to be univariate, yi 2 R for now, but that can be also generalized in the same way. Then given a training set f(xi 1 , ..., xid , , yi )gN i =1 , we want to learn a linear model for how the inputs a¤ect the outputs: d ŷi = ∑ xij ω j = ω 0 + ω 1 xi 1 + + ω d xid for every 1 i N. j =0 where we assume xi 0 = 1 and ω 0 is the bias term like before. In a matrix form, the expression for the linear model is again Ŷ = XW where Ŷ 2 R N , X 2 R N (d +1 ) , W 2 R d +1 . If we write this explicitly, we have 2 6 6 6 Ŷ = 6 6 4 ŷ1 .. . ŷN 3 2 1 7 6 7 6 7 6 . 7 = 6 .. 7 6 5 4 1 x11 x1d .. . .. . xN 1 xNd 32 76 76 76 76 76 54 ω0 .. . ωd 3 7 7 7 7 = XW . 7 5 Just like the simplest case, the solution is obtained in a closed form by W = XTX 1 XTY. 2/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Multivariate Linear Regression Multivariate linear regression is linear regression for multivariate data. In the case when d = 2, this is as follows: ŷ = ω 0 + x1 ω 1 + x2 ω 2 Φ xi 2 3 1 4 xi 1 5 = xi 2 1 6 . 6 . 6 . 6 Φ=6 1 6 6 .. 4 . 1 2 x11 . .. xi 1 .. . xN 1 ) W = ΦT Φ 1 x1d . .. xi 1 .. . xNd 3 7 7 7 7 7 ) ŷ = ΦW 7 7 5 ΦT ŷ Here Φ is called the feature matrix. 3/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Multivariable linear regression example Consider the electricity usage problem of a building. We have two input features: the outside temperature and the people inside the building. Outside Temperature (T ) 10 8 5 2 Number of People Inside a building (P ) Electricity Used (E ) 4 25 40 38 9 32 61 70 If we vectorize the training data, we have 2 3 2 3 1 10 4 9 6 1 6 32 7 8 25 7 7, 7 Φ=6 Y =6 4 1 4 61 5 5 40 5 1 2 38 70 Ŷ = ΦW ) W = ΦT Φ 1 ΦT Y 4/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Multivariable linear regression example ΦT Φ 1 = = ΦT Y = W = = 31 1 2 3 1 10 4 1 C 6 1 8 25 7 7C 2 56 4 1 5 40 5A 38 1 2 38 02 31 1 2 4 25 107 16.113 1.3367 @4 25 1.3367 0.11918 193 516 5A = 4 107 516 3685 0.28069 0.022126 2 3 2 2 3 3 9 1 1 1 1 172 6 32 7 7 4 791 5 4 10 8 5 2 56 4 61 5 = 5936 4 25 40 38 70 0 2 1 B B4 10 @ 4 1 8 25 1 5 40 3 0.28069 0.022126 5 0.0053234 1 ΦT Φ ΦT Y 2 16.113 1.3367 4 1.3367 0.11918 0.28069 0.022126 32 3 2 3 0.28069 172 47.93 5 4 5 4 0.022126 791 4.3011 5 = 0.0053234 5936 0.82269 Thus we have Ŷ = ΦW or in practical terms E = 47.93 4.3011T + 0.82269P . 5/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression Consider we want to model the following data If we want to model the data with a polynomial of low degree, then this is called the polynomial regression. ŷ = ω 0 + ω 1 x + ω 2 x 2 + ω 3 x 3 + + ωn x n Source: Pattern Recognition and Machine Learning, Christopher Bishop. 6/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression The algorithm just comes from revising the multivariable linear regression. For a given a training set f(xi 1 , ..., xid , , yi )gN i =1 If we de…ne the feature map Φ (x i ) = 1 xi xi2 xi3 then the polynomial regression of degree 3 is given by ŷi = Φ (xi ) W where 2 3 ω0 6 ω1 7 7 W =6 4 ω2 5 ω3 The rest of the computations are remain exactly the same. 7/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression If we model with a degree 0 constant polynomial, then ŷi = ω 0 Source: Pattern Recognition and Machine Learning, Christopher Bishop. 8/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression If we model with a degree 1 polynomial (linear regression as before), then ŷi = ω 0 + ω 1 xi Source: Pattern Recognition and Machine Learning, Christopher Bishop. 9/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression If we model with a degree 3 polynomial, then ŷ = ω 0 + ω 1 x + ω 2 x 2 + ω 3 x 3 Source: Pattern Recognition and Machine Learning, Christopher Bishop. 10/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression If we model with a degree 9 polynomial, then ŷ = ω 0 + ω 1 x + ω 2 x 2 + + ω9 x 9 Source: Pattern Recognition and Machine Learning, Christopher Bishop. 11/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression: an example Given a training set f(0, 6 ) , (1, 4 ) , (2, 20 ) , (3, 0 )g , (these points are chosen nearby the degree 3 polynomial P (x ) = x 3 4x 2 + 5x 7, so that we could compare our result) …nd a polynomial regression with degree 3. Since the feature map is given by Φ (xi ) = 1 xi xi2 xi3 for this training set we have 2 1 then ΦT Φ 02 1 B6 0 6 =B @4 0 0 1 6 1 6 Φ (x i ) = 4 1 1 1 1 1 1 1 2 4 8 32 1 1 6 1 3 7 76 9 54 1 27 1 0 1 2 3 3 2 0 7 6 1 7 ,Y = 6 4 8 5 27 3 6 4 7 7 20 5 0 0 1 2 3 0 1 4 9 0 1 4 9 31 1 02 0 4 C B6 6 1 7 7C = B6 @4 14 8 5A 27 36 6 14 36 98 14 36 98 276 31 1 36 C 98 7 7C 276 5A 794 12/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression: an example ΦT Φ 1 ΦT Y W = = = = 2 3 1.833 1.0 0.166 14.722 12.5 2.611 7 7 12.5 11.5 2.5 5 2.611 2.5 0.555 2 32 3 2 3 1 1 1 1 6 30 6 0 1 2 6 6 3 7 4 7 44 7 6 76 7=6 7 4 0 1 4 9 5 4 20 5 4 84 5 0 1 8 27 0 164 2 1.0 1.833 1.0 1 6 1.833 14.722 12.5 T T Φ Φ Φ Y =6 4 1.0 12.5 11.5 0.166 2.611 2.5 2 3 6.124 6 29.018 7 6 7 4 36.0 5 9.076 6 6 4 1.0 1.833 1.0 0.166 32 0.166 6 2.611 7 76 2.5 5 4 0.555 3 30 44 7 7 84 5 164 13/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression Python Code Example Here is a polynomial regression python code from https://www.w3schools.com/python/python_ml_polynomial_regression.asp import numpy import matplotlib.pyplot as plt x = [1,2,3,5,6,7,8,9,10,12,13,14,15,16,18,19,21,22] y = [100,90,80,60,60,55,60,65,70,70,75,76,78,79,90,99,99,100] mymodel = numpy.poly1d(numpy.poly…t(x, y, 3)) myline = numpy.linspace(1, 22, 100) plt.scatter(x, y) plt.plot(myline, mymodel(myline)) plt.show() print (numpy.poly…t(x, y, 3)) 14/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression Python Code Example When you run the code, we get [-3.03208795e-02 1.34333191e+00 -1.55383039e+01 We get the following degree 3 polynomial P (x ) = 0.0303208795x 3 + 1.34333191x 2 1.13768037e+02] 15.5383039x + 113.768037 15/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression Python Code Example If we try to obtain a degree 2 polynomial, then just update the line for the degree mymodel = numpy.poly1d(numpy.poly…t(x, y, 2)) when we run the code, we obtain [ 0.300185 -5.85858457 94.01812448] We get the following degree 2 polynomial P (x ) = 0.300185x 2 5.85858457x + 94.01812448 Degree 2 and 3 polynomials we have found kind of under…t... 16/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression Python Code Example Let’s try to obtain a degree 6 polynomial, update the line for the degree and run mymodel = numpy.poly1d(numpy.poly…t(x, y, 6)) [-7.54054041e-05 5.02158675e-03 -1.25419509e-01 1.41667305e+00 -6.28955578e+00 1.07030761e-01 1.05366951e+02] We get the following degree 6 polynomial P (x ) = 0.0000754054041x 6 + 0.00502158675x 5 +1.41667305x 3 0.125419509x 4 2 6.28955578x + 0.107030761x + 105.366951 17/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Polynomial Regression Python Code Example Now let’s try to obtain a degree 15 polynomial, update the line for the degree and run mymodel = numpy.poly1d(numpy.poly…t(x, y, 15)) The coe¢ cients of x 15 , x 14 , ..., x 2 , x , 1 are [-2.93978144e-11 5.22666373e-09 -4.23279705e-07 2.06666143e-05 -6.78573042e-04 1.58231835e-02 -2.69736428e-01 3.40862254e+00 -3.20335191e+01 2.22547872e+02 -1.12549185e+03 4.03331108e+03 -9.80649732e+03 1.50661512e+04 -1.28708923e+04 4.60975088e+03] The polynomial passes through each of the points... We (over)…t all the datapoints!... 18/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Over…tting versus Under…tting Under…tting occurs when the model is too simple, so it doesn’t explain well: Over…tting occurs when the model is too complex, so even though it perfectly explains the data at hand, it won’t generalize to the other data we want to predict: 19/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Generalization We would naturally want our models to generalize to new data which our models haven’t seen before The degree of the polynomial is another example of a hyperparameter, just like the learning rate hyperparameter in the gradient descent algorithm; something we can’t include in the training procedure itself We can tune hyperparameters using validation: partition the data into three subsets 1 2 Training set: used to train the model Validation set: used to evaluate generalization error of a trained model and optimize the model parameters Use a training set and a validation set to evaluate model performance and select the best model parameters. 20/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Generalization We would naturally want our models to generalize to new data which our models haven’t seen before The degree of the polynomial is another example of a hyperparameter, just like the learning rate hyperparameter in the gradient descent algorithm; something we can’t include in the training procedure itself We can tune hyperparameters using validation: partition the data into three subsets 1 2 3 Training set: used to train the model Validation set: used to evaluate generalization error of a trained model and optimize the model parameters Test set: used to evaluate …nal model performance once&after hyperparameters are chosen Use a training set and a validation set to evaluate model performance and select the best model parameters. 20/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Generalization We would naturally want our models to generalize to new data which our models haven’t seen before The degree of the polynomial is another example of a hyperparameter, just like the learning rate hyperparameter in the gradient descent algorithm; something we can’t include in the training procedure itself We can tune hyperparameters using validation: partition the data into three subsets 1 2 3 Training set: used to train the model Validation set: used to evaluate generalization error of a trained model and optimize the model parameters Test set: used to evaluate …nal model performance once&after hyperparameters are chosen Use a training set and a validation set to evaluate model performance and select the best model parameters. 20/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability 1. Training set A training set, or a training dataset, is the largest portion of our data that we use to train our machine learning model. They are given to ML algorithms to learn to make better predictions and …nd insights within the dataset. We feed our model with the input features and the target labels from the training set and adjust the model parameters to minimize the error or loss function. The training set helps your model learn the patterns and relationships in the data, but it does not tell you how well your model can generalize to new data. 21/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability 2. Validation set A validation set is a smaller portion of our data that we use to evaluate our model performance during the training process. We do not use the validation set to train our model, but only to test it on di¤erent values of the model parameters, also known as hyperparameters. The validation set helps us compare di¤erent models or di¤erent settings of the same model, and select the one that has the lowest validation error or loss. It also helps us avoid over…tting, which is when our model performs well on the training set but performs poorly on new data. 22/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability 3. Test set A test set is another portion of our data that we use to evaluate our model performance after the training process. We do not use the test set to train or validate our model, but only to test it on unseen data. The test set helps us estimate how well our model will perform on real-world data and measure its generalization ability. The test set also helps us avoid data leakage, which is when our model learns information from the validation or test set that it should not have access to. How do we determine when an algorithm achieves “good” performance? Performance on test set called generalization performance 23/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Solution to avoid over…ting Increase training data or features: When you increase training data or the number of features, your model can’t remember all training data, but it will try to …nd some general setting that applies to majority of training data for reducing loss during training. But same general settings can also be applicable to predict on test data. So by increasing training data, training loss is increased but test loss decreases and that is what expected for Prediction. Reduce model complexity: Same applies here when you reduce model complexity, your model can’t remember all training data. So training loss increases and test loss decreases. 24/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Cross validation: How to split the data There is no de…nitive rule on how to split our data into training, validation, and test sets, but a common practice is to use a 60-20-20 ratio. This means that we use 60% of our data for training, 20% for validation, and 20% for testing. However, this ratio may vary depending on the size and characteristics of our data, and the type and complexity of our model. We can also use other methods to split our data, such as cross-validation, which is when we divide our data into k folds and use one fold as the validation set and the rest as the training set, and repeat this process k times. 25/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Generalization: some other notes Feature maps aren’t magic wands: Not always easy to pick good features. In high dimensions, polynomial expansions can get very large! Until the last few years, a large fraction of the e¤ort of building a good machine learning system was feature engineering. We’ll see that neural networks are able to learn nonlinear functions directly, avoiding hand-engineering of features 26/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Expectation (or expected value) Expectation The expectation (or expected value) of a data value (random variable) X with a probability value function p (x ) is de…ned by E [X ] E [X ] = Z xp (x ) dx in the continuous case N = ∑ x k p (x k ) k =1 µ= 1 N xk in the discrete case N k∑ =1 where µ is the sample mean. The expectation (or expected value) gives some kind of a weighted average where weights are the probabilities of the values. This formula might look a bit confusing, but it will make more sense when you see it used in the context of actual examples. The following examples show how expected value is calculated in …ve di¤erent real-world situations. 27/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Expectation (or expected value) Expectation Example 1: Investments Expected value is often used by trading …rms to determine the expected pro…t or loss from some investment. For example, suppose a particular investment is could deliver a 5% annual return with a probability of 0.95, but it could also deliver a -20% annual return with a probability of 0.05. We would calculate the expected value of this investment to be: Expected value = 5%*.95 + (-20%)*.05 = 3.75% This particular investment has a positive expected value. This means that if we invested in this particular investment an in…nite number of times, we would expected a long-term average annual return of 3.75%. 28/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Expectation (or expected value) Expectation Example 2: Weather Expected value is often used by agricultural companies to determine the expected amount of rain that will fall during a given season. For example, suppose a there is a 20% chance of 1 inch of rain, a 70% chance of 2 inches of rain, and a 10% chance of 3 inches of rain. We would calculate the expected value for the amount of rain to be: Expected value = 0.2*1 + 0.7*2 + 0.1*3 = 1.9 inches 29/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Expectation (or expected value) Expectation Example 3: Gambling Expected value is often used by gamblers to determine how much they could potentially win at a certain game. For example, suppose in a certain game there is a 5% chance of winning $100, a 50% chance of winning $0, and a 45% chance of losing $20. We would calculate the expected value for winnings to be: Expected value = 0.05*$100 + 0.5*$0 + 0.45*(-$20) = -$4 This means that if we played this game an in…nite number of times we would expect to lose $4 each time we play, on average. 30/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Expectation (or expected value) Expectation Example 4: Business Expected value is often used by businesses to calculate the expected return on advertising spending. For example, suppose for a particular advertisement there is a 10% chance of receiving a $5 return, a 30% chance of receiving a $2 return, and a %60 chance of receiving a -$8 return. We would calculate the expected value for the advertisement to be: Expected value = 0.1*$5 + 0.3*$2 + 0.6*(-$8) = -$3.70 This particular advertisement has a negative expected value. This means that if the company used this particular advertisement an in…nite number of times, it would expect to lose $3.70 each time, on average. 31/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Expectation (or expected value) Expectation Example 5: Entrepreneurship Expected value is often used by individuals when deciding whether or not they should pursue entrepreneurship. For example, suppose an individuals thinks that if they quit their job and work for themselves that there is a 60% chance they could earn $20,000 in their …rst year, a 30% chance they could earn $60,000, and a 10% chance they would earn $0. We would calculate the expected value for their income in the …rst year of entrepreneurship to be: Expected value = 0.6*$20,000 + 0.3*$60,000 + 0.1*$0 = $30,000 Depending on whether or not this amount of money is su¢ cient, the individual could then choose to remain in their current job or quit. 32/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Variance Variance Variance of a data value (random variable) X with a probability value function p (x ) is de…ned by Z h i Var [X ] = (x µ)2 p (x ) dx = E (X E [X ])2 in the continuous case N Var [X ] = ∑ (x k µ)2 p (x ) in the discrete case k =1 Variance gives the dispersion of the data value from its expected value. There are also two other commonly used variance terms: If there are N data values, the sample variance S 2 is de…ned by S 2 [X ] = (dividing by N Var [X ] N 1 1 eliminates bias) and the population variance σ2 is de…ned by σ 2 [X ] = Var [X ] N 33/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Variance Expectation Example 1 revisited: Investments We had the example as a particular investment is could deliver a 5% annual return with a probability of 0.95, but it could also deliver a -20% annual return with a probability of 0.05. We have calculated the expected value of this investment to be: Expected value = 5%*(0.95) + (-20%)*(0.05) = 3.75% The variance will be (3.75% - 5%)2 *(0.95) + (3.75% - (20)%)2 *(0.05) = 0.3% Here the number of data points N = 2 and N 1 = 1 so the sample variance is 0.3% / 1 = 0.3% and the population variance is 0.3% / 2 = 0.15%. Try to …nd the variances of the other examples just for exercise. 34/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Covariance Covariance In probability, the covariance of a pair two random variables (X , Y ) = f(xi , yi )gN i =1 is de…ned by cov (X , Y ) = E [(X µX ) (Y µY )] in the continuous case where µX = E [X ] and µY = E [Y ] are the expected values of X and Y respectively. In the discrete case, the covariance of a pair of random variable (X , Y ) = f(xi , yi )gN i =1 is de…ned by 1 N cov (X , Y ) = (x i µX ) (y i µY ) N i∑ =1 It gives information about the dependence (relation) of the values of X on the values of Y. 35/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Covariance Covariance If greater values of X correspond with greater values of Y , and the same holds for smaller values (that is, the variables X and Y tend to show similar behavior), the covariance is positive, i.e. cov [X , Y ] > 0. Similarly if greater values of X correspond with smaller values of Y , and the same holds for smaller values (that is, the variables X and Y tend to show opposite behavior), the covariance is negative, i.e. cov [X , Y ] < 0. If there seems to be none of the above, then cov [X , Y ] = 0. Source: researchgate.com 36/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Covariance Covariance If X = [X 1 , X 2 , ..., X n ]T is a d dimensional random vector, its covariance matrix is de…ned by the following symmetric, positive de…nite matrix i h Ω : = cov [X ] = E (X µX ) (X µX )T 2 = Var [X 1 ] 6 6 6 cov [X 2 , X 1 ] 6 6 6 6 .. 6 . 6 4 cov [X d , X 1 ] cov [X 1 , X 2 ] cov [X 1 , X d ] Var [X 2 ] .. . cov [X d , X 2 ] .. . 3 7 7 cov [X 2 , X d ] 7 7 7 7 7 .. 7 . 7 5 Var [X d ] 37/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Covariance Covariance: A visual example with eigenvalues/eigenvectors A visual example of covariance matrix of two random variables with eigenvalues/eigenvectors: 38/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Covariance Covariance: A numerical example The table below shows the values of two new company stock values, X versus Y , between 2015 and 2020 : Year X Stock Value ($) Y Stock Value ($) 2015 1, 245 100 2016 1, 415 123 2017 1, 312 129 2018 1, 427 143 2019 1, 510 150 2020 1, 590 197 Then the mean (average) values are µX = 1, 245 + 1, 415 + 1, 312 + 1, 427 + 1, 510 + 1, 590/6 = 1, 416.5 µY = 100 + 123 + 129 + 143 + 150 + 197/6 = 140.3 39/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Covariance Covariance: A numerical example Find the di¤erence of each variable value with their mean value Year X µX Y µY (X µX ) (Y µY ) 2015 1, 245 1, 416.5 = 171.5 100 140.3 = 40.3 6, 911.45 2016 1, 415 1, 416.5 = 1.5 123 140.3 = 17.3 25.95 2017 1, 312 1, 416.5 = 104.5 129 140.2 = 11.2 1, 180.85 2018 1, 427 1, 416.5 = 10.5 143 140.3 = 2.7 28.35 2019 1, 510 1, 416.5 = 93.5 150 140.3 = 9.7 906.95 2020 1, 590 1, 416.5 = 173.5 197 140.3 = 56.7 9, 837.45 Finally we can obtain the covariance of company X ’s stock and company Y ’s stock as cov (X , Y ) = = 1 (6, 911.45 + 25.95 + 1, 180.85 + 28.35 + 906.95 + 9, 837.45 ) 6 18, 891 = 3, 148.5 6 We conclude from the positive nature of the covariance value that the two companies’ stocks move in the same direction. A major application of covariance is in …nance and investing. Covariance is often used to evaluate the risk of particular stocks by comparing whether they move with or against each other. For example, if the value of two stocks increases and decreases opposite one another, then they would be complementary and carry minimal risk because they minimize …nancial loss by having one growing while the other shrinks. 40/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Gaussian distribution Gaussian Distribution The probability density function of a Gaussian distribution (also called as Normal distribution) x N µ, σ2 is given by p (x ) = p 1 2πσ2 e 1 (x 2σ2 µ )2 where µ is the mean (the expected value of x ) and σ2 is the variance. 41/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Gaussian distribution Sampling from a (univariate) Gaussian Distribution 42/43 Multivariate Linear Regression Polynomial regression Over…tting and under…tting Generalization Some probability Gaussian distribution Covariance and Multivariate Gaussians Let X = [X 1 , X 2 , ..., X n ]T is a d dimensional random vector given by a multivariate Gaussian distribution, N (X jµ, Ω) , then we have N (X jµ, Ω) := where Ωij = cov [X i , X j ] for 1 1 (2π )d /2 jΩj i, j e 1/2 1 2 h (X µ )T Ω 1 (X µ ) i d. 43/43
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )