In [5]:
import numpy as np
In [1]:
ab = [3, 76]
In [2]:
data = [[2, 81], [4, 93], [6, 91], [8, 97]]
In [3]:
x = [i[0] for i in data]
y = [i[1] for i in data]
In [4]:
def predict(x):
return ab[0]*x + ab[1]
In [6]:
def rmse(p, a):
return np.sqrt(((p-a) ** 2).mean())
In [7]:
def rmse_val(predict_result, y):
return rmse(np.array(predict_result), np.array(y))
In [33]:
predict_result = []
for i in range(len(x)):
predict_result.append(predict(x[i]))
print("공부한 시간={:.1f}, 실제 점수={:.1f}, 예측점수={:.1f}".format(x[i], y[i], predict(x[i])))
In [34]:
print("rmse 최종값: " + str(rmse_val(predict_result, y)))
In [ ]: