Skip to content

Instantly share code, notes, and snippets.

@Alakhator
Created April 10, 2020 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alakhator/8fd355915cb3d7bf3ad7c0d5c0809dbe to your computer and use it in GitHub Desktop.
Save Alakhator/8fd355915cb3d7bf3ad7c0d5c0809dbe to your computer and use it in GitHub Desktop.
for (int i = 0; i < 20; i ++) { // since there are 5 values and we want 4 epochs so run for loop for 20 times
int idx = i % 5; //for accessing index after every epoch
double p = b0 + b1 * x[idx]; //calculating prediction
err = p - y[idx]; // calculating error
b0 = b0 - alpha * err; // updating b0
b1 = b1 - alpha * err * x[idx];// updating b1
cout<<"B0="<<b0<<" "<<"B1="<<b1<<" "<<"error="<<err<<endl;// printing values after every updation
error.push_back(err);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment