Gunction to calculate cost for logistic regression