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 1,250 views

## 1 answer to this question.

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
• 5,480 points

## Alternatives to linear regression for dataset with many points with small value and some extreme values

The above situation is the case where ...READ MORE

## Python code for basic linear regression

Hi @Dipti, you could try something like ...READ MORE

## Ignore the NaN and do the linear regression on remaining values

Yes, you can do this using statsmodels: import ...READ MORE

## Python script for linear regression on panda dataframe

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

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

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

+1 vote

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

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