3
$\begingroup$

Iam pretty new to the whole topic so please dont be harsh. I know these may be simple questions but everybody has to start somewhere ^^

So I created (or more copied) my first little Model which predicts sons heights based on their fathers.

#Father Data
X=data['Father'].values[:,None]
X.shape

#According sons data
y=data.iloc[:,1].values
y.shape

#Spliting the data into test and train data
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)

#Doing a linear regression
lm=LinearRegression()
lm.fit(X_train,y_train)

# save the model to disk
filename = 'Father_Son_Height_Model.pckl'
pickle.dump(lm, open(filename, 'wb'))

#Predicting the height of Sons
y_test=lm.predict(X_test)
print(y_test)

Now I wanted to create a plot that displays the accuracy of my model or how "good" it is. Something like it is done here: https://machinelearningmastery.com/how-to-calculate-precision-recall-f1-and-more-for-deep-learning-models/

But i cant quiet get it to work. This here Sems like I would work but what should I store in "model_history"?

plt.subplot(212)
plt.title('Accuracy')
plt.plot(model_history.history['acc'], label='train')
plt.plot(model_history.history['val_acc'], label='test')
plt.legend()
plt.show()

A easy to adapt tutorial-Link would be a geat help already. Keras seems to be a thing but I would want to avoid yet another library if possible and sensible.

$\endgroup$
3
$\begingroup$

Your context is different than the one provided in the link. There, the author has made a neural network in Keras and has plotted the accuracy against the number of epochs. One epoch is when an entire dataset is passed both forward and backward through the neural network once. So, he is calculating accuracy after every epoch while the weights vary to fit data based on the loss function. (Thus, the accuracy increases as the number of epochs increases.)

In your case, you are performing a linear regression which fits the data and generates an equation. There is no feedback system. Accuracy here can be defined based on your need. In this case (Predicting sons height based on their father's), you can define accuracy as how accurate your predictions were. Take an error function like MAE (Mean absolute error). Lesser the error rate is more accurate is your model. MAE is an accuracy measure here. enter image description here

For general classification tasks, accuracy is the number of instances you predicted correctly divided by the total number of instances. (In the link, author used default keras accuracy metric defined somewhat like this)

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.