optimization for Linear regression and Logistic regression