<filename>W3Schools Online Lessons/ML/TrainTest.py
# Start With a Data Set
import numpy
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score
numpy.random.seed(2)

x = numpy.random.normal(3, 1, 100)
y = numpy.random.normal(150, 40, 100) / x

plt.scatter(x, y)
plt.show()

# Split into Tarin/Test
train_x = x[:80]
train_y = y[:80]

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

# Display the Training Set
plt.scatter(train_x, train_y)
plt.show()

# Display the Testing Set
plt.scatter(test_x, test_y)
plt.show()

# Fit the Data Set
mymodel = numpy.poly1d(numpy.polyfit(train_x, train_y, 4))

myline = numpy.linspace(0, 6, 100)

plt.scatter(train_x, train_y)
plt.plot(myline, mymodel(myline))
plt.show()

# R2
r2 = r2_score(train_y, mymodel(train_x))

print(r2)

# Bring in the Testing Set
r2 = r2_score(test_y, mymodel(test_x))

print(r2)

# Predict Values
print(mymodel(5))

<filename>W3Schools Online Lessons/ML/TrainTest.py
# Start With a Data Set
import numpy
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score
numpy.random.seed(2)

x = numpy.random.normal(3, 1, 100)
y = numpy.random.normal(150, 40, 100) / x

plt.scatter(x, y)
plt.show()

# Split into Tarin/Test
train_x = x[:80]
train_y = y[:80]

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

# Display the Training Set
plt.scatter(train_x, train_y)
plt.show()

# Display the Testing Set
plt.scatter(test_x, test_y)
plt.show()

# Fit the Data Set
mymodel = numpy.poly1d(numpy.polyfit(train_x, train_y, 4))

myline = numpy.linspace(0, 6, 100)

plt.scatter(train_x, train_y)
plt.plot(myline, mymodel(myline))
plt.show()

# R2
r2 = r2_score(train_y, mymodel(train_x))

print(r2)

# Bring in the Testing Set
r2 = r2_score(test_y, mymodel(test_x))

print(r2)

# Predict Values
print(mymodel(5))

# Start With a Data Set # Split into Tarin/Test # Display the Training Set # Display the Testing Set # Fit the Data Set # R2 # Bring in the Testing Set # Predict Values