//Now to find the r2 score
var residual_sum_of_squares = 0, total_sum_of_squares = 0, r2 = 0;
for(i=0; i<y_values.length; i++){
residual_sum_of_squares+= Math.pow((y_hat[i]-y_values[i]),2);
total_sum_of_squares += Math.pow((y_hat[i]-y_mean),2);
}
r2 = 1- residual_sum_of_squares/total_sum_of_squares;
//Add to regressor object
regressor['r2'] = r2;