qda py import numpy as np import matplotlib pyplot as plt from scipy stats import multivariate_normal mu np array ([ , ]mu np array ([ , ]sigma np array ([[ , ,[ ]]sigma np array ([[ , ,[ ]]xy np mgrid - : : - : : jmvn multivariate_normal mu sigma mvn multivariate_normal mu sigma xy np hstack (( reshape - , , reshape - , )) mvn pdf(xyreshape ( shape mvn pdf(xyreshape ( shape plt contour ( , ,zz mvn pdf(xyreshape ( shape mvn pdf(xyreshape ( shape )plt contour ( , , levels =[ linestyles ='dashed 'linewidths colors ' 'plt show (of coursein practice the true parameter th { }cj= is not known and must be estimated from the training data -for exampleby minimizing the cross-entropy training loss ( with respect to thn lossf (xi yi ) (xi yi th)ln (xi yi th) = = where ln |sy ( uy ) - ln( py ( uy the corresponding estimates of the model parameters (see exercise areln (xy thln ay ny xi uy ny : = sy (xi uy )(xi uy ny : = ay ( for where ny :ni= {yi yfor the case where sy for all ywe have yb ay sy when classes are involvedthe classification procedure carries through in exactly the same wayleading to quadratic and linear discriminant functions ( and ( for each class the space now is partitioned into regionsdetermined by the linear or quadratic boundaries determined by each pair of gaussians