finilized code for linear regression