Linear regression grad cost function