Beruflich Dokumente
Kultur Dokumente
School of Informatics
Master of Data science
Haftamu Hailu Tefera
al17hafte@student.his.e
Evaluation of Machine Learning algorithms and Bias Variance Trade off analysis
The main goal of this assignment to evaluate machine learning algorithms on a particular data set
called abalone and analyzing the bias variance tradeoff as complexity of the model increases to fit
the data using different polynomial regressions.
The selected dataset consists of different attributes of the plant called abalone. My experiment is
predicting the age of the plant from different physical measurements like height, width, height and
others. Here in my experiment, I used diameter of the data set to predict the age.
For this assignment, I used Python as a programming language and polynomial regression plus the
collection of functions and classes which are defined inside the sklearn machine learning library.
Firstly, I modeled the relationship between the independent and response variable using simple
linear mode but later used polynomial regression to fit the data because the relationship between
independent variable (diameter) and the response variable is not linear.
Firstly, the data is divided into train and test sets, I train the model using the train data set and later
I applied the model on the unseen data (the test set), and finally I plotted the graphs as follows
Even if I used different polynomial regression with various degrees, but there is error between the
actual data points and predicted value of using the model. When I use simple modes, they do not
represent the actual relationship between the response variable (ring) and the feature variable
(diameter). Using complex models are also sensitive to small change in the data. Therefore, to
decide which model is perfect for my data set I performed bias variance analysis by varying
complexities and I obtained the following complexity vs bias variance.
As we can see from the graph the variance changes slightly from complexity to complexity but the
bias is almost remains the same.
According the Occam's razor principle for this experiment bias and variance is low at complexity 1
which balances between the bias and variance errors.
1. Code for plotting predicted values and real data on the test data
n_models = 10
max_degree = 15
var_values=[]
bias_values = []
for degree in range(1, max_degree):
models = []
for m in range(n_models):
#training the model
model = fit_poly(X_train, y_train, degree)
#testing the model on the test data
Pred = apply_poly(model, X_test)
b=bias(Pred,y_test)/n_models
bias_values.append(b)
va=variance(Pred,Pred)
va=va/n_models
var_values.append(va)
pl.plot(bias_values, label=”bias”, range(1, max_degree))
plt.plot(var_values, label="variance”, range(1, max_degree))
plt.xlabel("Complexity")
plt.ylabel("Bias Value")
plt.grid()
plt.legend()
Reference
1. http://scikit-learn.org/stable/
2. Class lecture notes on machine learning