Python Machine Learning

Train/Test

Train test split

Train/Test

Train/Test is a method to measure the accuracy of your model. It is called Train/Test because you split the data set into two sets: a training set and a testing set.

Train Test Split

import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score

train_x = x[:80]
train_y = y[:80]

test_x = x[80:]
test_y = y[80:]

mymodel = np.poly1d(np.polyfit(train_x, train_y, 4))

r2 = r2_score(test_y, mymodel(test_x))
print(r2)