bias and variance calculation for linear regression

0 votes
If we have 4 parameters of X_train, y_train, X_test, and y_test, how can we calculate the bias and variance of a machine learning algorithm like linear regression?

I have searched a lot but I could not find a single code for this.
Mar 2, 2022 in Machine Learning by Dev
• 6,000 points
1,825 views

1 answer to this question.

0 votes
Evaluation of Variance:

variance = np.var(prediction) # Where prediction is a variable obtained after  predict() function of any Classifier or algorithm

sse= np.mean((np.mean(prediction) - y)** 2) # Where y refers to dependent variable. # sse : Sum of squared errors.

bias = sse - variance

Bias and Variance are errors and need to be balanced. Bias leads to an underfit model that means it does not understand the patterns and fails to generalize, whereas

Variance leads to overfitting of the data, the model learns the data so well even the noises that does not generalize well on unseen data. Variance is the spread of the data, how far are the data points from the central points like mean or median
answered Mar 2, 2022 by Nandini
• 5,480 points

Related Questions In Machine Learning

0 votes
1 answer
0 votes
1 answer

Python script for linear regression on panda dataframe

Use the following code: from scipy import stats slope, ...READ MORE

answered May 23, 2019 in Machine Learning by Imran
1,974 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 7, 2018 in Python by Priyaj
• 58,020 points
1,676 views
0 votes
1 answer

Crawling after login in Python

You missed a few login data forms, ...READ MORE

answered Sep 14, 2018 in Python by Priyaj
• 58,020 points
853 views
0 votes
1 answer

“stub” __objclass__ in a Python class how to implement it?

You want to avoid interfering with this ...READ MORE

answered Sep 27, 2018 in Python by Priyaj
• 58,020 points
2,350 views
+1 vote
1 answer

How is raw_input() and input() in python3.x?

raw_input() was renamed to input() so now input() returns the exact string ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,020 points
897 views
0 votes
1 answer

What is the difference between linear regression and logistic regression?

Hi Dev, to answer your question Linear Regression ...READ MORE

answered Feb 2, 2022 in Machine Learning by Nandini
• 5,480 points
1,170 views
0 votes
1 answer

Assumptions of Naïve Bayes and Logistic Regression

There are very few difference between Naive ...READ MORE

answered Feb 7, 2022 in Machine Learning by Nandini
• 5,480 points
482 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP