In the context of data science, bias and variance are the two key concepts in the context of machine learning that can affect the performance of models:-
Bias
It refers to the error which is introduced by approximating a real-world problem with a simplified model. If a model has a high bias score then it means that there is a robust assumptions about the underlying data.
Variance
It refers to the sensitivity of a model to small fluctuations and even smaller noise in the training data. If a model has a high rate of variance then it means that it is overly complex and captured noises in the training data.
Here is a Python script given which demonstrates how you can train a model and even evaluate its bias or variance by using the method of cross-validation:-
From sklearn.model_selection import cross_val_score
From sklearn.linear_model import LinearRegression
# Sample training data (replace with actual data)
X_train = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Y_train = [10, 20, 30]
# Initialize linear regression model
Model = LinearRegression()
# Evaluate model performance using cross-validation
Cv_scores = cross_val_score(model, X_train, y_train, cv=5)
# Calculate bias and variance
Bias = 1 – cv_scores.mean()
Variance = cv_scores.std()
Print(“Bias:”, bias)
Print(“Variance:”, variance)