00001: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 476, 'const': 433, 'code+const': 909}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return (((float(a))*(x**2)) + ((float(b))*x) + (float(c)))
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (((float(Y[0]) - (Y_hat[0])))**2) + (((float(Y[1]) - (Y_hat[1])))**2) + (((float(Y[2]) - (Y_hat[2])))**2) + (((float(Y[3]) - (Y_hat[3])))**2) + (((float(Y[4]) - (Y_hat[4])))**2)
#======================================

00002: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 352, 'const': 393, 'code+const': 745}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]#ในนี้เป็น int
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5):
      Y[i]=float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[]
    for i in range(5):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=a*(x**2)+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE=0
    for i in range(5):
      SSE+=(Y[i]-Y_hat[i])**2
    return SSE
#======================================

00003: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 518, 'const': 433, 'code+const': 951}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    X = [float(e) for e in X]
    Y = input('Y = ').split()
    Y = [float(e) for e in Y]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    yhat1 = f(X[0],a,b,c)
    yhat2 = f(X[1],a,b,c)
    yhat3 = f(X[2],a,b,c)
    yhat4 = f(X[3],a,b,c)
    yhat5 = f(X[4],a,b,c)
    Y_hat = [yhat1,yhat2,yhat3,yhat4,yhat5]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    yhat = a*x**2+b*x+c
    return yhat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    a = (Y[0]-Y_hat[0])**2
    b = (Y[1]-Y_hat[1])**2
    c = (Y[2]-Y_hat[2])**2
    d = (Y[3]-Y_hat[3])**2
    e = (Y[4]-Y_hat[4])**2
    x = a+b+c+d+e
    return x
#======================================

00004: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 45.0, 45.0, 67.8125]
test_main0.0NameError("name 'x' is not defined")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 456, 'const': 419, 'code+const': 875}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = (f(x[0],a,b,c),f(x[1],a,b,c),f(x[2],a,b,c),f(x[3],a,b,c),f(x[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = (a*(x**2))+(b*x)+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans1 = (Y[0]-Y_hat[0])**2
    ans2 = (Y[1]-Y_hat[1])**2
    ans3 = (Y[2]-Y_hat[2])**2
    ans4 = (Y[3]-Y_hat[3])**2
    return ans1 + ans2 + ans3 + ans4
#======================================

00005: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 448, 'const': 433, 'code+const': 881}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(d) for d in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c)] +[ f(X[1],a,b,c)]+[ f(X[2],a,b,c)]+ [f(X[3],a,b,c)]+[f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2)+ b*x +c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 +(Y[2]-Y_hat[2])**2 +(Y[3]-Y_hat[3])**2 +(Y[4]-Y_hat[4])**2
#======================================

00006: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0 Y_hat=[]
^
IndentationError: unexpected indent
[10.0, 21.25, 87.0625]
test_SSE0.0 Y_hat=[]
^
IndentationError: unexpected indent
[0.0, 5.0, 5.0, 7.8125]
test_main0.0 Y_hat=[]
^
IndentationError: unexpected indent
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    YY=Y
    Y=[]
    for i in  YY:
       Y+=[float(i)]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a=float(a)
    b=float(b)
    c=float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
     Y_hat=[]
     for i in X:
        Y_hat+=[f(i,a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=a*x**2+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE=0
    for i in range(len(Y)):
        SSE+=(Y[i]-Y_hat[i])**2
    return str(SSE)
#======================================

00007: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 532, 'const': 433, 'code+const': 965}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y0 = float(Y[0]); Y1= float(Y[1]); Y2=float(Y[2]); Y3=float(Y[3]); Y4=float(Y[4])
    Y = [Y0,Y1,Y2,Y3,Y4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = ((float(a))*(float(x))**2)+((float(b))*(float(x)))+float(c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    a = (Y[0]-float(Y_hat[0]))**2
    b = (Y[1]-float(Y_hat[1]))**2
    c = (Y[2]-float(Y_hat[2]))**2
    d = (Y[3]-float(Y_hat[3]))**2
    e = (Y[4]-float(Y_hat[4]))**2
    ans = a+b+c+d+e
    return ans
#======================================

00008: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 454, 'const': 433, 'code+const': 887}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(e) for e in Y ]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2) + b*x +c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return sum([(float(Y_hat[0])-Y[0])**2, (float(Y_hat[1])-Y[1])**2, 
                (float(Y_hat[2])-Y[2])**2, (float(Y_hat[3])-Y[3])**2, 
                (float(Y_hat[4])-Y[4])**2])
#======================================

00009: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 396, 'const': 431, 'code+const': 827}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y=input('Y = ').split(" ")
    for i in range(len(Y)):
      Y[i]=float(Y[i])
     # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    r=a*(x**2)+(b*x)+c
    return r
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    c=0
    for i in range(5):
      c+=(Y[i]-Y_hat[i])**2
    return c 
#======================================

00010: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]  
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
   Y_hatt = a*(x**2)+b*x+c
   return Y_hatt
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  SSE = (Y_hat[0]-Y[0])**2+(Y_hat[1]-Y[1])**2+(Y_hat[2]-Y[2])**2+(Y_hat[3]-Y[3])**2+(Y_hat[4]-Y[4])**2
  return SSE
    # Y and Y_hat are lists of five floats
#======================================

00011: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 456, 'const': 433, 'code+const': 889}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return (a*(x**2))+(b*x)+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
#======================================

00012: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 368, 'const': 391, 'code+const': 759}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2)+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum = 0
    for i in range(len(Y)):
        sum += (float(Y[i])-float(Y_hat[i]))**2
    return sum
#======================================

00013: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 520, 'const': 433, 'code+const': 953}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    Y = [Y[0], Y[1], Y[2], Y[3], Y[4]]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return (a*(x**2))+(b*x)+c   # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y[0]-Y_hat[0])**2) + ((Y[1]-Y_hat[1])**2) +((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00014: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 354, 'const': 419, 'code+const': 773}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split(' ')  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5):
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))# ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5):
      Y_hat += [f(X[i],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Yhat = (a*(x)**2) + (b*(x)) + c
    return Yhat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    m = 0
    for i in range(5):
      m += (Y[i] - Y_hat[i])**2
    return m
#======================================

00015: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (a*(x**2))+(b*x)+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((float(Y[0])-float(Y_hat[0]))**2)+((float(Y[1])-float(Y_hat[1]))**2)+((float(Y[2])-float(Y_hat[2]))**2)+((float(Y[3])-float(Y_hat[3]))**2)+((float(Y[4])-float(Y_hat[4]))**2)
    return SSE
#======================================

00016: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c) , f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
   yh=float(a)*x**2+float(b)*x+float(c)
   return yh
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse=(Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return sse
#======================================

00017: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 366, 'const': 379, 'code+const': 745}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[i],a,b,c) for i in range(len(X))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    # 𝑦̂ =𝑎𝑥2+𝑏𝑥+𝑐
    a, b, c, x = float(a), float(b), float(c), float(x) 
    return a*(x**2) + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum = 0
    for y_i, y_hat_i in zip(Y, Y_hat):
      y_i_minus_y_hat_i = float(y_i) - float(y_hat_i)
      sum += (y_i_minus_y_hat_i)**2
    return sum
#======================================

00018: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 494, 'const': 433, 'code+const': 927}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')
    a = float(a)# ลอง 12.8
    b = input('b = ')
    b = float(b)# ลอง -40.2
    c = input('c = ')
    c = float(c)# ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return ((a*(x**2))+(b*x)+c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return ((Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2)
#======================================

00019: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'float' object is not iterable")
[10.0, 21.25, 87.0625]
test_SSE0.0TypeError("'list' object cannot be interpreted as an integer")
[0.0, 5.0, 5.0, 7.8125]
test_main1.0TypeError("'list' object cannot be interpreted as an integer")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 360, 'const': 399, 'code+const': 759}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = list(map(float, input('Y = ').split()))  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in f(X,a,b,c):
        Y_hat.append(i)
    # # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    y = []
    temp = 0.0
    for i in x:
        temp = 0.0
        temp = (a*pow(i, 2)) + (b*i) + c
        y.append(temp)
    return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    sse = 0.0
    for i in range(Y):
        # print(Y(i), Y_hat(i))
        sse += pow((Y(i) - Y_hat(i)), 2)
    # Y and Y_hat are lists of five floats
    return sse
#======================================

00020: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
[9.5, 14.0, 25.0, 42.0, 65.0] [9.75, 15.5, 27.75, 46.5, 71.75] [1, 2, 3, 4, 5] 75.6875
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 552, 'const': 433, 'code+const': 985}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(str(Y[0])),float(str(Y[1])),float(str(Y[2])),float(str(Y[3])),float(str(Y[4]))]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)] 
    print(Y,Y_hat,X,SSE(Y,Y_hat))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  y = (float(a))*((float(x))**2)+(float(b))*float(x)+float(c)
  return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  sse = (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
  return sse
    # Y and Y_hat are lists of five floats
#======================================

00021: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 352, 'const': 393, 'code+const': 745}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(len(X)):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    result = a*(x**2) + b*(x) + c
    return result
#======================================
def SSE(Y, Y_hat):
  import math
  SSE = 0
  for i in range(len(Y)):
    SSE += math.pow(float(Y[i])-float(Y_hat[i]),2)
  return round(SSE,4)
    # Y and Y_hat are lists of five floats
#======================================

00022: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 496, 'const': 433, 'code+const': 929}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    y0 = float(y[0])
    y1 = float(y[1])
    y2 = float(y[2])
    y3 = float(y[3])
    y4 = float(y[4])
    Y = [y0, y1, y2, y3, y4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    a = float(a)
    b = input('b = ')  # ลอง -40.2
    b = float(b)
    c = input('c = ')  # ลอง 400.5
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = a*x**2 + b*x + c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse
#======================================

00023: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 394, 'const': 391, 'code+const': 785}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2) + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    for i in range(len(Y)):
        temp = (Y[i] - Y_hat[i])**2
        sse += temp
    return sse
#======================================

00024: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 524, 'const': 433, 'code+const': 957}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),
         float(Y[1]),
         float(Y[2]),
         float(Y[3]),
         float(Y[4]),]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat_1 = f(X[0],a,b,c)
    Y_hat_2 = f(X[1],a,b,c)
    Y_hat_3 = f(X[2],a,b,c)
    Y_hat_4 = f(X[3],a,b,c)
    Y_hat_5 = f(X[4],a,b,c)
    Y_hat = [Y_hat_1, Y_hat_2, Y_hat_3, Y_hat_4, Y_hat_5]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = (a*(x**2))+(b*x)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE_0 = (Y[0]-Y_hat[0])**2
    SSE_1 = (Y[1]-Y_hat[1])**2
    SSE_2 = (Y[2]-Y_hat[2])**2
    SSE_3 = (Y[3]-Y_hat[3])**2
    SSE_4 = (Y[4]-Y_hat[4])**2
    SSE = SSE_0 + SSE_1 + SSE_2 + SSE_3 + SSE_4
    return SSE
#======================================

00025: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 368, 'const': 338, 'code+const': 706}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(y) for y in input().split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(len(X)):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = float(a)*(float(x)**2)+(float(b)*x)+float(c)
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = float()
    for i in range(len(Y)):
      sse_n = ((Y[i]) - float(Y_hat[i]))**2
      sse += sse_n
    return sse
#======================================

00026: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 510, 'const': 433, 'code+const': 943}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0]*5
    Y_hat[::1] = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y1 = (a*(x**2))+(b*x)+c
    return Y1
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00027: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0,0,0,0,0]
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    f = a*(x**2) + b*x + c
    return f 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00028: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 419, 'code+const': 949}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0,0,0,0,0]
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    f = a*(x*x) + (b*x) + c
    return f
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00029: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  Y_hat = a*(x**2) + b*x + c
  return Y_hat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
  return SSE
    # Y and Y_hat are lists of five floats
#======================================

00030: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 538, 'const': 433, 'code+const': 971}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 4
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    #ติดนานมากว่าทำไมกราฟออกมาแปลกๆอ้อลืมไปว่าsplitแล้วมันเป็นstr
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=(a*(float(x)**2))+(b*float(x))+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE=((float(Y_hat[0])-float(Y[0]))**2)+((float(Y_hat[1])-float(Y[1]))**2)+((float(Y_hat[2])-float(Y[2]))**2)+((float(Y_hat[3])-float(Y[3]))**2)+((float(Y_hat[4])-float(Y[4]))**2)
    return SSE
    #listลบกันไม่ได้ ยกกำลังก็ไม่ได้
#======================================

00031: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 432, 'const': 433, 'code+const': 865}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float (e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  return (a*(x**2)) + (b*x) + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  return ((Y[0]-Y_hat[0])**2) + ((Y[1]-Y_hat[1])**2) + ((Y[2]-Y_hat[2])**2) + ((Y[3]-Y_hat[3])**2) + ((Y[4]-Y_hat[4])**2)
#======================================

00032: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 448, 'const': 433, 'code+const': 881}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()] # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(float(x)**2)+(b*float(x))+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 +(Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2 
    return sse
#======================================

00033: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 520, 'const': 433, 'code+const': 953}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0])]+[float(Y[1])]+[float(Y[2])]+[float(Y[3])]+[float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = ') ) # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),
             f(X[1],a,b,c),
             f(X[2],a,b,c),
             f(X[3],a,b,c),
             f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (a*(x**2))+(b*x)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (((float(Y[0])-float(Y_hat[0]))**2)+
          ((float(Y[1])-float(Y_hat[1]))**2)+
          ((float(Y[2])-float(Y_hat[2]))**2)+
          ((float(Y[3])-float(Y_hat[3]))**2)+
          ((float(Y[4])-float(Y_hat[4]))**2))
    return SSE
#======================================

00034: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = ') ) # ลอง 400.5
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    y_hat=(a*(x**2))+(b*x)+c
    return y_hat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    sum=((float(Y_hat[0])-float(Y[0]))**2)+((float(Y_hat[1])-float(Y[1]))**2)+((float(Y_hat[2])-float(Y[2]))**2)+((float(Y_hat[3])-float(Y[3]))**2)+((float(Y_hat[4])-float(Y[4]))**2)
    return sum
    # Y and Y_hat are lists of five floats
#======================================

00035: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 468, 'const': 433, 'code+const': 901}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
    # print(type(Y[0]))
#======================================
def f(x,a,b,c):
    y_hat = float((a*x**2)+(b*x)+c)
    return y_hat
#======================================
def SSE(y,y_hat):
    e = (y[0]-y_hat[0])**2 + (y[1]-y_hat[1])**2 + (y[2]-y_hat[2])**2 + (y[3]-y_hat[3])**2 + (y[4]-y_hat[4])**2
    return e
#======================================

00036: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 476, 'const': 433, 'code+const': 909}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
#======================================

00037: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split() # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    f = a*(x**2) + b*x + c
    return f
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((Y[0] - Y_hat[0]))**2 + ((Y[1] - Y_hat[1]))**2 + ((Y[2] - Y_hat[2]))**2 + ((Y[3] - Y_hat[3]))**2 + ((Y[4] - Y_hat[4]))**2
    return sse
#======================================

00038: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 419, 'code+const': 883}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]   
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = a*x*x + b*x + c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse
#======================================

00039: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 536, 'const': 433, 'code+const': 969}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = (input('Y = ')).split()  # ลอง 378.66 372.16 391.94 438.0 510.34
    Y = list()
    for i in y:
      Y.append(float(i))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))# ลอง 12.8 
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.05
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y = (a*(x**2))+(b*x)+(c)
    return(Y)
#======================================
def SSE(Y, Y_hat): #input ไม่จำเป็นต้องออกเป็นค่าเดียวกัน
    # Y and Y_hat are lists of five floats
    Y0 = float(Y[0])
    Y1 = float(Y[1])
    Y2 = float(Y[2])
    Y3 = float(Y[3])
    Y4 = float(Y[4])
    Y_hat0 = Y_hat[0]
    Y_hat1 = Y_hat[1]
    Y_hat2 = Y_hat[2]
    Y_hat3 = Y_hat[3]
    Y_hat4 = Y_hat[4]
    SSE = ((Y0-Y_hat0)**2)+((Y1-Y_hat1)**2)+((Y2-Y_hat2)**2)+((Y3-Y_hat3)**2)+((Y4-Y_hat4)**2)
    return(SSE)
#======================================

00040: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 500, 'const': 433, 'code+const': 933}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(x) for x in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),
        f(X[1],a,b,c),
        f(X[2],a,b,c),
        f(X[3],a,b,c),
        f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2)+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    x1 = (float(Y[0])-float(Y_hat[0]))**2
    x2 = (float(Y[1])-float(Y_hat[1]))**2
    x3 = (float(Y[2])-float(Y_hat[2]))**2
    x4 = (float(Y[3])-float(Y_hat[3]))**2
    x5 = (float(Y[4])-float(Y_hat[4]))**2
    return x1+x2+x3+x4+x5
#======================================

00041: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
[1, 2, 3, 4, 5]
[9.5, 14.0, 25.0, 42.0, 65.0]
[9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.69875
[]
bytecount: {'code': 450, 'const': 405, 'code+const': 855}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y1 = []
    for p in Y:
      u = float(p)
      Y1.append(u)
    Y = Y1
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c) ,f(X[2],a,b,c),f(X[3],a,b,c) ,f(X[4],a,b,c)]
    print(X)
    print(Y)
    print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = a*x**2 + b*x + c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Sse = 0
    for i in range(5):
      R = float(Y[i])
      Dif = abs(R - Y_hat[i])
      Sq = Dif **2
      Sse += Sq
    Sse = round(Sse,2)
    return Sse
#======================================

00042: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 354, 'const': 367, 'code+const': 721}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(float(X[i]),float(a),float(b),float(c)) for i in range(len(X))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  return a*(x**2)+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  return sum([(float(Y[i])-Y_hat[i])**2 for i in range(len(Y))])
#======================================

00043: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 482, 'const': 433, 'code+const': 915}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ') ) # ลอง 12.8
    b = float(input('b = ') )  # ลอง -40.2
    c = float(input('c = ') ) # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
#======================================

00044: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 344, 'const': 391, 'code+const': 735}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0]*5
    for i in range(5):
        Y_hat[i] = f(X[i],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return (a*(x**2)) + (b*x) + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE_list = [0]*len(Y)
    for i in range(len(Y)):
        SSE_list[i] = (float(Y[i]) - float(Y_hat[i]))**2
    return sum(SSE_list)
#======================================

00045: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'float' object is not subscriptable")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 634, 'const': 487, 'code+const': 1121}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a=float(a)
    b=float(b)
    c=float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    Y_hat = f(X,a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y0 = a*(x[0]**2) + b*x[0] +c
    y1 = a*(x[1]**2) + b*x[1] +c
    y2 = a*(x[2]**2) + b*x[2] +c
    y3 = a*(x[3]**2) + b*x[3] +c
    y4 = a*(x[4]**2) + b*x[4] +c
    return [y0,y1,y2,y3,y4]
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse0 = (float(Y[0]) - float(Y_hat[0]))**2
    sse1 = (float(Y[1])- float(Y_hat[1]))**2
    sse2 = (float(Y[2])- float(Y_hat[2]))**2
    sse3 = (float(Y[3]) - float(Y_hat[3]))**2
    sse4 = (float(Y[4]) - float(Y_hat[4]))**2
    return sse0+sse1+sse2+sse3+sse4
#======================================

00046: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return float((a*(x**2))+(b*x)+c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    es = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return es
#======================================

00047: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 520, 'const': 433, 'code+const': 953}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    a = float(Y[0])
    b = float(Y[1])
    c = float(Y[2])
    d = float(Y[3])
    e = float(Y[4])
    Y[0] = a
    Y[1] = b
    Y[2] = c
    Y[3] = d
    Y[4] = e
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')# ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = list()
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
     return float(a)*(float(x)**2) + float(b)*float(x) + float(c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y_hat[0]-Y[0])**2) + ((Y_hat[1]-Y[1])**2) + ((Y_hat[2]-Y[2])**2) + ((Y_hat[3]-Y[3])**2) + ((Y_hat[4]-Y[4])**2)
    return SSE
#======================================

00048: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'float' object is not subscriptable")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 568, 'const': 487, 'code+const': 1055}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X, a, b, c)
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    คำตอบ0 = a*(x[0]**2) + b*x[0] + c
    คำตอบ1 = a*(x[1]**2) + b*x[1] + c
    คำตอบ2 = a*(x[2]**2) + b*x[2] + c
    คำตอบ3 = a*(x[3]**2) + b*x[3] + c
    คำตอบ4 = a*(x[4]**2) + b*x[4] + c
    return [คำตอบ0,คำตอบ1,คำตอบ2,คำตอบ3,คำตอบ4]
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    คำตอบ = (Y[0] - Y_hat[0])**2
    คำตอบ += (Y[1] - Y_hat[1])**2
    คำตอบ += (Y[2] - Y_hat[2])**2
    คำตอบ += (Y[3] - Y_hat[3])**2
    คำตอบ += (Y[4] - Y_hat[4])**2
    return คำตอบ
#======================================

00049: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 562, 'const': 433, 'code+const': 995}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    Y[0],Y[1],Y[2],Y[3],Y[4] = float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  yhat=float(a)*pow(x,2)+float(b)*x+float(c)
  return yhat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse0=pow(float(Y[0])-float(Y_hat[0]),2)
    sse1=pow(float(Y[1])-float(Y_hat[1]),2)
    sse2=pow(float(Y[2])-float(Y_hat[2]),2)
    sse3=pow(float(Y[3])-float(Y_hat[3]),2)
    sse4=pow(float(Y[4])-float(Y_hat[4]),2)
    return sse0+sse1+sse2+sse3+sse4
#======================================

00050: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
[10.0, 21.25, 23587.140625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 756399.76171875
[]
bytecount: {'code': 448, 'const': 433, 'code+const': 881}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(x) for x in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    a=float(a)
    b = input('b = ')  # ลอง -40.2
    b=float(b)
    c = input('c = ')  # ลอง 400.5
    c=float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat= [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c): 
  return (((a*x)**2)+(b*x)+c)
     # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat): 
  # Y and Y_hat are lists of five floats
  return ((Y[0]-Y_hat[0]))**2 + ((Y[1]-Y_hat[1]))**2 + ((Y[2]-Y_hat[2]))**2 + ((Y[3]-Y_hat[3]))**2 + ((Y[4]-Y_hat[4]))**2
#======================================

00051: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Yhat = a*(x**2)+b*x+c
    return Yhat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00052: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 594, 'const': 433, 'code+const': 1027}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0,0,0,0,0]
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    x = float(x)
    y = a*(x**2) + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    y = (float(Y[0]) - Y_hat[0])**2 + (float(Y[1]) - Y_hat[1])**2 + (float(Y[2]) - Y_hat[2])**2 +(float(Y[3]) - Y_hat[3])**2+ (float(Y[4]) - Y_hat[4])**2
    return y
#======================================

00053: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 502, 'const': 390, 'code+const': 892}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input().split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats-
    y = (float(a)*x*x)+(float(b)*x)+float(c)
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((float(Y[0]) - float(Y_hat[0]))**2)+((float(Y[1]) - float(Y_hat[1]))**2)+((float(Y[2]) - float(Y_hat[2]))**2)+((float(Y[3]) - float(Y_hat[3]))**2)+((float(Y[4]) - float(Y_hat[4]))**2)
    return sse
#======================================

00054: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 480, 'const': 433, 'code+const': 913}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[ f(X[0],a,b,c) , f(X[1],a,b,c) , f(X[2],a,b,c),f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2 + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans=(Y[0]-Y_hat[0])**2
    ans+=(Y[1]-Y_hat[1])**2
    ans+=(Y[2]-Y_hat[2])**2
    ans+=(Y[3]-Y_hat[3])**2
    ans+=(Y[4]-Y_hat[4])**2
    return ans
#======================================

00055: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 506, 'const': 433, 'code+const': 939}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0]*5
    Y_hat[0] = f(1, a, b, c)
    Y_hat[1] = f(2, a, b, c)
    Y_hat[2] = f(3, a, b, c)
    Y_hat[3] = f(4, a, b, c)
    Y_hat[4] = f(5, a, b, c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = a*(x**2)+b*x+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    k = ((Y_hat[0]-Y[0])**2)+((Y_hat[1]-Y[1])**2)+((Y_hat[2]-Y[2])**2)+((Y_hat[3]-Y[3])**2)+((Y_hat[4]-Y[4])**2)
    return k
#======================================

00056: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 514, 'const': 433, 'code+const': 947}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a * (x**2) + b * x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0] - Y_hat[0])**2
    sse += (Y[1] - Y_hat[1])**2
    sse += (Y[2] - Y_hat[2])**2
    sse += (Y[3] - Y_hat[3])**2
    sse += (Y[4] - Y_hat[4])**2
    return sse
#======================================

00057: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = ((a*(x**2))+(b*x)+c)
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return sse
#======================================

00058: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
[10.0, 21.25, 23587.140625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 756399.76171875
[]
bytecount: {'code': 468, 'const': 433, 'code+const': 901}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = list()
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  x=float(x)
  a=float(a)
  b=float(b)
  c=float(c)
  return (((a*x)**2+(b*x)+c))
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  return ((float(Y[0])-float(Y_hat[0])))**2 + ((float(Y[1])-float(Y_hat[1])))**2 + ((float(Y[2])-float(Y_hat[2])))**2 + ((float(Y[3])-float(Y_hat[3])))**2 + ((float(Y[4])-float(Y_hat[4])))**2
    # Y and Y_hat are lists of five floats
#======================================

00059: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 532, 'const': 433, 'code+const': 965}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y =[float(Y[0]), float(Y[1]),  float(Y[2]),  float(Y[3]),  float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat = float(a)*(float(x)**2)+float(b)*float(x) + float(c)
    return Y_hat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    A = ((float(Y[0])-float(Y_hat[0]))**2)
    B = ((float(Y[1])-float(Y_hat[1]))**2)
    C = ((float(Y[2])-float(Y_hat[2]))**2)
    D = ((float(Y[3])-float(Y_hat[3]))**2)
    E = ((float(Y[4])-float(Y_hat[4]))**2)
    F = A + B + C + D + E
    return F
#======================================

00060: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'float' object is not subscriptable")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 564, 'const': 433, 'code+const': 997}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    w0 = float(Y[0])
    w1 = float(Y[1])
    w2 = float(Y[2])
    w3 = float(Y[3])
    w4 = float(Y[4])
    Y = [w0, w1, w2, w3, w4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X, a, b, c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    z0 = x[0]
    z1 = x[1]
    z2 = x[2]
    z3 = x[3]
    z4 = x[4]
    y0 = a*z0**2 + b*z0 + c
    y1 = a*z1**2 + b*z1 + c
    y2 = a*z2**2 + b*z2 + c
    y3 = a*z3**2 + b*z3 + c
    y4 = a*z4**2 + b*z4 + c
    return [y0,y1,y2,y3,y4]
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    m0, m1, m2, m3, m4 = Y
    n0, n1, n2, n3, n4 = Y_hat
    SSE = (m0 - n0)**2
    SSE += (m1 - n1)**2
    SSE += (m2 - n2)**2
    SSE += (m3 - n3)**2
    SSE += (m4 - n4)**2
    return SSE
#======================================

00061: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 508, 'const': 419, 'code+const': 927}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    l0 = float(Y[0])
    l1 = float(Y[1])
    l2 = float(Y[2])
    l3 = float(Y[3])
    l4 = float(Y[4])
    Y = [l0, l1, l2, l3, l4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    x = float(x)
    Y = (a*x*x)+(b*x)+c
    return float(Y)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00062: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 520, 'const': 433, 'code+const': 953}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    #for i in range(5):
        #Y[i] = float(Y[i])
    # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat=[f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    f=a*(x**2)+b*x+c
    return f
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    SSE = ((float(Y_hat[0])-float(Y[0]))**2)
    SSE += ((float(Y_hat[1])-float(Y[1]))**2)
    SSE += ((float(Y_hat[2])-float(Y[2]))**2)
    SSE += ((float(Y_hat[3])-float(Y[3]))**2)
    SSE += ((float(Y_hat[4])-float(Y[4]))**2)
    return SSE
    # Y and Y_hat are lists of five floats
#======================================

00063: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    x = float(x)
    y = a*(x**2)+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0])-Y_hat[0])**2 + (float(Y[1])-Y_hat[1])**2 + (float(Y[2])-Y_hat[2])**2 + (float(Y[3])-Y_hat[3])**2 + (float(Y[4])-Y_hat[4])**2
    return SSE
#======================================

00064: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 494, 'const': 433, 'code+const': 927}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],float(a),float(b),float(c)), f(X[1],float(a),float(b),float(c)),f(X[2],float(a),float(b),float(c)),f(X[3],float(a),float(b),float(c)),f(X[4],float(a),float(b),float(c))] 
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2)+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (float(Y[0]) - float(Y_hat[0]))**2 + (float(Y[1]) - float(Y_hat[1]))**2 + (float(Y[2]) - float(Y_hat[2]))**2 + (float(Y[3]) - float(Y_hat[3]))**2 + (float(Y[4]) - float(Y_hat[4]))**2
    return sse
#======================================

00065: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 468, 'const': 433, 'code+const': 901}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = list(Y[::1])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = (a*(x**2))+(b*x)+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    answer = ((float(Y[0])-float(Y_hat[0]))**2) + ((float(Y[1])-float(Y_hat[1]))**2) + ((float(Y[2])-float(Y_hat[2]))**2) + ((float(Y[3])-float(Y_hat[3]))**2) + ((float(Y[4])-float(Y_hat[4]))**2)
    return answer
#======================================

00066: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 586, 'const': 433, 'code+const': 1019}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=list([f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)])
    Y_hat[0]=float(Y_hat[0])
    Y_hat[1]=float(Y_hat[1])
    Y_hat[2]=float(Y_hat[2])
    Y_hat[3]=float(Y_hat[3])
    Y_hat[4]=float(Y_hat[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2)+(b*x)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE=(((Y[0])-(Y_hat[0]))**2)+(((Y[1])-(Y_hat[1]))**2)+(((Y[2])-(Y_hat[2]))**2)+(((Y[3])-(Y_hat[3]))**2)+(((Y[4])-(Y_hat[4]))**2)
    return SSE
#======================================

00067: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'float' object is not subscriptable")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 592, 'const': 487, 'code+const': 1079}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    a0 = float(Y[0])
    a1 = float(Y[1])
    a2 = float(Y[2])
    a3 = float(Y[3])
    a4 = float(Y[4])
    Y = [a0, a1, a2, a3, a4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X,a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y0 = a*(x[0]**2) + b*x[0] + c
    y1 = a*(x[1]**2) + b*x[1] + c
    y2 = a*(x[2]**2) + b*x[2] + c
    y3 = a*(x[3]**2) + b*x[3] + c
    y4 = a*(x[4]**2) + b*x[4] + c
    y_hat = [y0,y1,y2,y3,y4]
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])**2
    sse += (Y[1]-Y_hat[1])**2
    sse += (Y[2]-Y_hat[2])**2
    sse += (Y[3]-Y_hat[3])**2
    sse += (Y[4]-Y_hat[4])**2
    return sse
#======================================

00068: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 562, 'const': 433, 'code+const': 995}
import matplotlib.pyplot as plt
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    result = float(a*x**2)+float(b*x)+float(c)
    return result
#=====================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Sum = ((float(Y[0])-float(Y_hat[0]))**2)+          ((float(Y[1])-float(Y_hat[1]))**2)+            ((float(Y[2])-float(Y_hat[2]))**2)+            ((float(Y[3])-float(Y_hat[3]))**2)+            ((float(Y[4])-float(Y_hat[4]))**2)
    return Sum
#======================================
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================

00069: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 372, 'const': 379, 'code+const': 751}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split()  # ลอง 378.66 372.16 391.94 438.0 510.34
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c =float( input('c = '))  # ลอง 400.05
    Y_hat=[]
    Y2=[float(x) for x in Y]
    Y=Y2
    for i in range(len(X)):
        Y_hat.append(f(X[i],a,b,c))
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x,a,b,c):
    y_hat=a*(x**2)+b*x+c
    return y_hat
def SSE(Y, Y_hat):
    all=0
    for i in range(len(Y)):
        all += (float(Y[i])-float(Y_hat[i]))**2
    return all

00070: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 352, 'const': 393, 'code+const': 745}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for e in range(5):
        Y[e] = float(Y[e])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5):
        Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2)+ b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    for i in range(5):
        sse += (Y_hat[i]-Y[i])**2
    return sse
#======================================

00071: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 460, 'const': 433, 'code+const': 893}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#=====================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    for e in range(len(Y)):
      Y[e] = float(Y[e])
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return(y)
#======================================
def SSE(Y, Y_hat):
  SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    # Y and Y_hat are lists of five floats
  return(SSE)
#======================================

00072: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
[[10.0], [21.25], [87.0625]]
test_SSE0.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> [3789.665, 37214.160, 39125.940, 4382.0, 6510.340]
Sum of squared errors = 175.64875
[]
bytecount: {'code': 498, 'const': 445, 'code+const': 943}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [378.66, 372.16, 391.94, 438.0, 510.34]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = 12.8  # ลอง 12.8
    b = -40.2  # ลอง -40.2
    c = 400.5  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X[0],a,b,c)
    Y_hat += f(X[1],a,b,c)
    Y_hat += f(X[2],a,b,c)
    Y_hat += f(X[3],a,b,c)
    Y_hat += f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = [a*(x**2) + (b*x) + c]
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = [(Y[0]-Y_hat[0])**2] 
    SSE +=[(Y[1]-Y_hat[1])**2]
    SSE +=[(Y[2]-Y_hat[2])**2]
    SSE +=[(Y[3]-Y_hat[3])**2]
    SSE +=[(Y[4]-Y_hat[4])**2]
    SSE = int(SSE[0]) + int(SSE[1]) + int(SSE[2]) + int(SSE[3]) + int(SSE[4])
    return SSE
#======================================

00073: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 422, 'const': 421, 'code+const': 843}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5) :
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2) + b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return sse
#======================================

00074: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 390, 'const': 391, 'code+const': 781}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [ float(i) for i in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),
             f(X[3], a, b, c),f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = a*x**2 + b*x + c
    return a
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    for i in range(len(Y)) :
        sse += (Y[i]-Y_hat[i])**2
    return sse
#======================================

00075: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.69875
[]
bytecount: {'code': 394, 'const': 431, 'code+const': 825}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split(" ")]  # ลอง 378.66 379.16 391.94 438.0 510.34
    #print(Y)
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    #print(a, b, c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c),
             f(X[3],a,b,c), f(X[4],a,b,c)]
    #print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    yy = (a*(x**2))+(b*x)+c
    #print(yy)
    return yy
#======================================
def SSE(Y, Y_hat):
  # Y and Y_hat are lists of five floats
  sose = 0
  for i in range(5):
      sose += (Y[i]-Y_hat[i])**2
  #print(sose)
  return round(sose, 2)
#======================================

00076: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 522, 'const': 419, 'code+const': 941}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y1 = f(X[0],a,b,c)
    Y2 = f(X[1],a,b,c)
    Y3 = f(X[2],a,b,c)
    Y4 = f(X[3],a,b,c)
    Y5 = f(X[4],a,b,c)
    Y_hat = [Y1,Y2,Y3,Y4,Y5]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
      y = a*(x*x) + b*x + c
      return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
      sse = ((Y[0]-Y_hat[0])**2) + ((Y[1]-Y_hat[1])**2) + ((Y[2]-Y_hat[2])**2) + ((Y[3]-Y_hat[3])**2) + ((Y[4]-Y_hat[4])**2)
      return sse
    # Y and Y_hat are lists of five floats
#======================================

00077: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 476, 'const': 419, 'code+const': 895}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x*x+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    a1=(Y[0]-Y_hat[0])**2
    a2=(Y[1]-Y_hat[1])**2
    a3=(Y[2]-Y_hat[2])**2
    a4=(Y[3]-Y_hat[3])**2
    a5=(Y[4]-Y_hat[4])**2
    return a1+a2+a3+a4+a5
#======================================

00078: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 522, 'const': 433, 'code+const': 955}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] =float(Y[1]) 
    Y[2] =float(Y[2])
    Y[3] =float(Y[3])
    Y[4] =float(Y[4])   
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [(f(X[0],a,b,c)),(f(X[1],a,b,c)),              (f(X[2],a,b,c)),(f(X[3],a,b,c)),              (f(X[4],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  y1 = (float(a)*(float(x)**2))+(float(b)*float(x))+float(c)
  return float(y1)
  # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  sse = (float(Y[0])-Y_hat[0])**2+(float(Y[1])-Y_hat[1])**2+         (float(Y[2])-Y_hat[2])**2+(float(Y[3])-Y_hat[3])**2+         (float(Y[4])-Y_hat[4])**2
  return sse
  # Y and Y_hat are lists of five floats
#======================================

00079: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 436, 'const': 391, 'code+const': 827}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  ret = 0
  for i in range(len(Y)):
    ret += (Y_hat[i]-Y[i])**2
  return ret
#======================================

00080: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 494, 'const': 433, 'code+const': 927}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    YY = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = []
    for i in range(len(X)) :
      Y.append(float(YY[i]))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    Y_hat.append(f(X[0],a,b,c))
    Y_hat.append(f(X[1],a,b,c))
    Y_hat.append(f(X[2],a,b,c))
    Y_hat.append(f(X[3],a,b,c))
    Y_hat.append(f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2 + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00081: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 380, 'const': 379, 'code+const': 759}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)) :
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(len(X)) :
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    return a*(x**2)+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = 0
    for i in range(len(Y)) :
      SSE += (Y[i] - Y_hat[i])**2
    return SSE
#======================================

00082: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 412, 'const': 391, 'code+const': 803}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)) :
      Y[i]=float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =  [0]*5
    for i in range(len(Y_hat)) :
      Y_hat[i]=f(X[i],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  #y=[0]*len(x)
 # for i in range(len(x)) :
   # y[i]=a*x[i]**2+b*x[i]+c
  y=a*float(x)**2+b*float(x)+c
  return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  a=[0]*len(Y)
  b=0
  for i in range(len(Y)) :
    a[i]= (Y[i]-Y_hat[i])**2
  for n in a :
    b+=n
  return b
    # Y and Y_hat are lists of five floats
#======================================

00083: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 440, 'const': 432, 'code+const': 872}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    y =  [float(e) for e in input('Y =').split() ] # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    Y = list(y) # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return a*(x**2) + b*x + c 
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    return (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    # Y and Y_hat are lists of five floats
#======================================

00084: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 402, 'const': 409, 'code+const': 811}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(x) for x in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (a * x ** 2) + (b * x) + c
    return round(y_hat, 2)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = [0.0] * 5
    for i in range(5) :
        sse[i] = (Y[i] - Y_hat[i]) ** 2
    return sum(sse)
#======================================

00085: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 576, 'const': 447, 'code+const': 1023}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
    return a*x**2 + b*x + c
def SSE(Y, Y_hat):
    sum = [0]*5
    sum[0] = (Y[0] - float(Y_hat[0]))**2
    sum[1] = (Y[1] - float(Y_hat[1]))**2
    sum[2] = (Y[2] - float(Y_hat[2]))**2
    sum[3] = (Y[3] - float(Y_hat[3]))**2
    sum[4] = (Y[4] - float(Y_hat[4]))**2
    sum = sum[0]+sum[1]+sum[2]+sum[3]+sum[4]
    return sum

00086: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 433, 'code+const': 917}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()# ลอง 378.66 372.16 391.94 438.0 510.34
    Y = (float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4]))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.05
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = (f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    polynomial = a*x**2 + b*x + c
    return polynomial
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00087: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0 Y = [float(Y[0]),float(Y[1]),-4float(Y[2]),float(Y[3]),float(Y[4])]
^
SyntaxError: invalid syntax
[10.0, 21.25, 87.0625]
test_SSE0.0 Y = [float(Y[0]),float(Y[1]),-4float(Y[2]),float(Y[3]),float(Y[4])]
^
SyntaxError: invalid syntax
[0.0, 5.0, 5.0, 7.8125]
test_main0.0 Y = [float(Y[0]),float(Y[1]),-4float(Y[2]),float(Y[3]),float(Y[4])]
^
SyntaxError: invalid syntax
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0]*5
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    Y = [float(Y[0]),float(Y[1]),-4float(Y[2]),float(Y[3]),float(Y[4])]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return float(a)*float(x**2)+float(b)*float(x)+float(c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum0 = (float(Y[0])-float(Y_hat[0]))**2
    sum1 = (float(Y[1])-float(Y_hat[1]))**2
    sum2 = (float(Y[2])-float(Y_hat[2]))**2
    sum3 = (float(Y[3])-float(Y_hat[3]))**2
    sum4 = (float(Y[4])-float(Y_hat[4]))**2
    return sum0 + sum1 + sum2 + sum3 + sum4
#======================================

00088: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0ValueError("could not convert string to float: '9.5 14 25 42 65'")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 476, 'const': 433, 'code+const': 909}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    a = float(input('a = '))  
    b = float(input('b = ')) 
    c = float(input('c = '))  
    Y = input('Y = ').split() 
    Y = [float(x) for x in Y]
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c) , f(X[4],a,b,c) ]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x,a,b,c):
  x = float(x)
  a = float(a)
  b = float(b)
  c = float(c)
  y1 = a*x**2 + b*x + c
  return y1
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  sse = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
  return sse

00089: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 444, 'const': 433, 'code+const': 877}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2 + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2 
    return SSE
#======================================

00090: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 506, 'const': 433, 'code+const': 939}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a * (x ** 2) + b * x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats 
    SSE = (Y[0]-Y_hat[0])**2
    SSE += (Y[1]-Y_hat[1])**2
    SSE += (Y[2]-Y_hat[2])**2
    SSE += (Y[3]-Y_hat[3])**2
    SSE += (Y[4]-Y_hat[4])**2
    return SSE
#======================================

00091: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = (a*(x)**2) + (b*x) + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0] )**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00092: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 470, 'const': 433, 'code+const': 903}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    fx=a*(x**2)+b*x+c
    return fx
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    s1=(float(Y[0])-float(Y_hat[0]))**2
    s2=(float(Y[1])-float(Y_hat[1]))**2
    s3=(float(Y[2])-float(Y_hat[2]))**2
    s4=(float(Y[3])-float(Y_hat[3]))**2
    s5=(float(Y[4])-float(Y_hat[4]))**2
    sse=s1+s2+s3+s4+s5
    return sse
    # Y and Y_hat are lists of five floats
#======================================

00093: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats 
    Y_hat = (a*(x**2))+(b*x)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (((float(Y[0]))-(float(Y_hat[0])))**2)+(((float(Y[1]))-(float(Y_hat[1])))**2)+(((float(Y[2]))-(float(Y_hat[2])))**2)+(((float(Y[3]))-(float(Y_hat[3])))**2)+(((float(Y[4]))-(float(Y_hat[4])))**2)
    return SSE
#======================================

00094: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 498, 'const': 433, 'code+const': 931}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split() # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    #Y = [378.66,379.16,391.94,438.0,510.34]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = ')) # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    f = a*(x**2)+b*(x)+c
    return float(f)
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    s = ((Y[0] - Y_hat[0])**2+ (Y[1] - Y_hat[1])**2+ (Y[2] - Y_hat[2])**2+ (Y[3] - Y_hat[3])**2+ (Y[4] - Y_hat[4])**2)
    return float(s)
    # Y and Y_hat are lists of five floats
#======================================

00095: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 524, 'const': 433, 'code+const': 957}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    Xpro = [1,2,3,4,5]
    X = [float(i) for i in Xpro]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Ypro = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Ypro]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hatpro = [f(float(X[0]), a, b, c), f(float(X[1]), a, b, c), f(float(X[2]), a, b, c), f(float(X[3]), a, b, c), f(float(X[4]), a, b, c)] #[f(X[::],a,b,c)] 
    #[f(X[::],a,b,c)] 
    Y_hat = [float(i) for i in Y_hatpro]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  return (a)*(x**2)+(b)*(x)+c  
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  return ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
#======================================

00096: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y =  [9.5, 14.0, 25.0, 42.0, 65.0]
Y_hat =  [9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 396, 'const': 412, 'code+const': 808}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[]
    for i in range(5):
      Y_hat.append(f(X[i],a,b,c))
    for i in range(5):
      Y[i]= float(Y[i])
    print("Y = ",Y)
    print("Y_hat = ",Y_hat)  
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (float(a)*float(x)*float(x))+(float(b)*float(x))+float(c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse=0
    for i in range(5):
      Ans2 = (float(Y[i])-float(Y_hat[i]))**2
      sse += Ans2
    return sse
#======================================

00097: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 400, 'const': 405, 'code+const': 805}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(item) for item in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    res = a*(x**2) + b*x + c
    return res
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum = 0 
    for i in range (0,5):
      sum = sum + (float(Y[i]) - float(Y_hat[i]))**2 
    return sum
#======================================

00098: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 380, 'const': 391, 'code+const': 771}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y_float = []
    for i in range(0,len(Y)):
      Y_float.append(float(Y[i]))
    Y = Y_float
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(0,len(X)):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2) + b*x + c 
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    for i in range(0,len(Y)):
      sse += (Y[i] - Y_hat[i])**2
    return sse
#======================================

00099: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 460, 'const': 432, 'code+const': 892}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    #Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(e) for e in input('Y =').split()]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Z = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return Z
#======================================

00100: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 378, 'const': 445, 'code+const': 823}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    q = ['*'] * 5
    for i in range(len(Y)):
      q[i] = float(Y[i])
    Y = q
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = ["#"]*5
    for i in range(5):
      Y_hat[i] = f(X[i],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return float(a)*(float(x)**2) + float(b)*float(x) + float(c)
#======================================
def SSE(Y, Y_hat):
  sse = 0
    # Y and Y_hat are lists of five floats
  for i in range(5):
    sse += (Y[i]-Y_hat[i])**2
  return sse

00101: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 626, 'const': 433, 'code+const': 1059}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    Y_hat = 5*[0]
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c) # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    a = float(a)
    b = float(b)
    c = float(c)
    x = float(x)
    yhat = a*x**2+b*x+c
    return yhat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    Y_hat[0] = float(Y_hat[0])
    Y_hat[1] = float(Y_hat[1])
    Y_hat[2] = float(Y_hat[2])
    Y_hat[3] = float(Y_hat[3])
    Y_hat[4] = float(Y_hat[4])
    sse = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2 
    return sse # Y and Y_hat are lists of five floats
#======================================

00102: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 518, 'const': 433, 'code+const': 951}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 4dd
    v,w,x,y,z = Y
    v = float(v)
    w = float(w)
    x = float(x)
    y = float(y)
    z = float(z) 
    Y = [v,w,x,y,z]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    y = a*x**2 + b*x + c
    return y 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    S = (Y[0] - Y_hat[0])**2
    S = S + (Y[1] - Y_hat[1])**2
    S = S + (Y[2] - Y_hat[2])**2
    S = S + (Y[3] - Y_hat[3])**2
    S = S + (Y[4] - Y_hat[4])**2
    return S
#======================================

00103: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 546, 'const': 464, 'code+const': 1010}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = ['aomsin']*5
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    y = a*x**2 + b*x + c
    return y 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    poonpunn = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return poonpunn
#======================================

00104: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y = (float(a)*(x**2)) + (float(b)*x) + float(c)
    return Y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    error = (float(Y[0])-float(Y_hat[0]))**2 + (float(Y[1])-float(Y_hat[1]))**2 + (float(Y[2])-float(Y_hat[2]))**2 + (float(Y[3])-float(Y_hat[3]))**2 + (float(Y[4])-float(Y_hat[4]))**2
    return error
#======================================

00105: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=a*(x**2)+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE=((Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00106: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 402, 'const': 405, 'code+const': 807}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 372.16 391.94 438.0 510.34 
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = float(a*x**2+b*x+c)
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = 0
    for i in range(5):
      SSE = SSE + (float(Y[i])-float(Y_hat[i]))**2
    return SSE
#======================================

00107: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 396, 'const': 381, 'code+const': 777}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = list()
    for i in range(5):
      Y_hat.append(f(X[i], a, b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    x = float(x)
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans = list()
    for i in range(len(Y)) :
      ans.append((float(Y[i])-float(Y_hat[i]))**2)
    return round(sum(ans), 4)
#======================================

00108: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
['910.55'0, '201.80'25, '867.061'25]
test_SSE0.0
['0.0000', '5.0000', '5.0000', '7.8125']
test_main0.0
9.30
15.05
27.30
46.05
71.30
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 62.752.68750
[]
bytecount: {'code': 406, 'const': 381, 'code+const': 787}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input().split()  # ลอง 
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input())  # ลอง 12.8
    b = float(input())  # ลอง -40.2
    c = float(input())  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    for i in Y_hat:
      print(i)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (a*x**2)+(b*x)+c-0.45
    k = "{:.2f}".format(y_hat)
    return(k)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    n=0
    SSE = 0
    while n < 5 :
      SSE  =  SSE + (float(Y[n])-float(Y_hat[n]))**2
      n += 1
    return "{:.4f}".format(SSE)
#======================================

00109: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 516, 'const': 317, 'code+const': 833}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input().split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    y0 = float(Y[0])
    y1 = float(Y[1])
    y2 = float(Y[2])
    y3 = float(Y[3])
    y4 = float(Y[4])
    Y = [y0, y1, y2, y3, y4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input())  # ลอง 12.8
    b = float(input())  # ลอง -40.2
    c = float(input())  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c), ]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2 + b*x + c
    return(Y_hat)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (float(Y[0]) - float(Y_hat[0]))**2 + (float(Y[1]) - float(Y_hat[1]))**2 + (float(Y[2]) - float(Y_hat[2]))**2 + (float(Y[3]) - float(Y_hat[3]))**2 + (float(Y[4]) - float(Y_hat[4]))**2
    return(sse)
#======================================

00110: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.69875
[]
bytecount: {'code': 404, 'const': 405, 'code+const': 809}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5):
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c) , f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2) + (b*x) + c 
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    s = 0
    for i in range(5):
        s += (float(Y[i])-float(Y_hat[i]))**2
    return round(s, 2)
#======================================

00111: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 496, 'const': 433, 'code+const': 929}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = a*x**2+b*x+c
    return(Y_hat)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y_hat[0]-Y[0])**2+(Y_hat[1]-Y[1])**2+(Y_hat[2]-Y[2])**2+(Y_hat[3]-Y[3])**2+(Y_hat[4]-Y[4])**2
    return(SSE)
#======================================

00112: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 480, 'const': 433, 'code+const': 913}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = float(a)*float(x)**2 + float(b)*float(x) + c
    return(Y_hat)
#======================================
def SSE(Y, Y_hat):
    SSE = ((Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 +
           (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 +
           (Y[4] - Y_hat[4])**2 )
    return(SSE)
    # Y and Y_hat are lists of five floats
#======================================

00113: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = ')) # ลอง 400.5
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    y_hat = a*X**2+b*X+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    S = ((float(Y[0])-float(Y_hat[0]))**2)+((float(Y[1])-float(Y_hat[1]))**2)+((float(Y[2])-float(Y_hat[2]))**2)+((float(Y[3])-float(Y_hat[3]))**2)+((float(Y[4])-float(Y_hat[4]))**2)
    return S
#======================================

00114: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 522, 'const': 433, 'code+const': 955}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0]) ; Y[1]=float(Y[1]) ; Y[2]=float(Y[2]) ; Y[3]=float(Y[3]) ; Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a=float(a) ; b=float(b) ; c=float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c): # x, a, b and c are floats
    Y_hat=(a*(x**2))+(b*x)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat): # Y and Y_hat are lists of five floats
    y0 = (Y[0]-Y_hat[0])**2
    y1 = (Y[1]-Y_hat[1])**2
    y2 = (Y[2]-Y_hat[2])**2
    y3 = (Y[3]-Y_hat[3])**2
    y4 = (Y[4]-Y_hat[4])**2
    sse_sum = y0+y1+y2+y3+y4
    return sse_sum
#======================================

00115: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 510, 'const': 433, 'code+const': 943}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = float(a*x**2+b*x+c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE001 = (Y[0]-Y_hat[0])**2
    SSE002 = (Y[1]-Y_hat[1])**2
    SSE003 = (Y[2]-Y_hat[2])**2
    SSE004 = (Y[3]-Y_hat[3])**2
    SSE005 = (Y[4]-Y_hat[4])**2
    return SSE001+SSE002+SSE003+SSE004+SSE005
#======================================

00116: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 514, 'const': 433, 'code+const': 947}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat0 = f(X[0],a,b,c)
    Y_hat1 = f(X[1],a,b,c)
    Y_hat2 = f(X[2],a,b,c)
    Y_hat3 = f(X[3],a,b,c)
    Y_hat4 = f(X[4],a,b,c)
    Y_hat = [Y_hat0, Y_hat1, Y_hat2, Y_hat3, Y_hat4]
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
#======================================

00117: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 444, 'const': 433, 'code+const': 877}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง 
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(X) for X in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are float   
    f = (a*x**2)+(b*x)+c
    return(f)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat that are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2 
    return(SSE)
#======================================

00118: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
['9.5', '14', '25', '42', '65'] [9.75, 15.5, 27.75, 46.5, 71.75]
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 472, 'const': 420, 'code+const': 892}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y =  ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    print(Y,Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (float(a)*float(x)*float(x)) + (float(b)*float(x)) + float(c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans = (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
    return ans
#======================================

00119: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
['10.0', '21.25', '87.0625']
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 386, 'const': 391, 'code+const': 777}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [ float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[i],a,b,c)) for i in range(0,len(X))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2)+b*x+c
    return str(y) 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    a = 0
    for i in range(0,len(Y)):
        a += (Y[i]-Y_hat[i])**2
    return a 
#======================================

00120: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 514, 'const': 433, 'code+const': 947}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = (f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = a*x**2 + b*x + c
    return float(Y_hat)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2)
    return sse
#======================================

00121: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(X**2) + (b*X) + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00122: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'int' object is not callable")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0TypeError("'float' object is not callable")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 260, 'const': 346, 'code+const': 606}
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0,0,0,0,0]
    for i in range(5): Y_hat[i] = f(X[i],float(a),float(b),float(c))
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
    # x, a, b and c are floats
    temp = a(x**2) + bx + c
    return(temp)
def SSE(Y, Y_hat):
    tem = 0
    i=0
    while i<=4:
        tem += (float(Y[i])-float(Y_hat[i]))**2
        i+=1
    return(tem)

00123: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 356, 'const': 397, 'code+const': 753}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5) :
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [None]*5
    for i in range(5) :
      Y_hat[i] = f(X[i], a, b, c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  qe = a*x**2+b*x+c
  return qe
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  sse = 0.0
  for i in range(5) :
    sse += (Y[i]-Y_hat[i])**2
  return sse
    # Y and Y_hat are lists of five floats
#======================================

00124: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 532, 'const': 433, 'code+const': 965}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = (f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    X = float(x)
    A = float(a)
    B = float(b)
    C = float(c)
    y_hat = A*(X**2) + B*X + C
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y = [float(i) for i in Y]
    Y_hat = [float(j) for j in Y_hat]
    ss = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return ss 
#======================================

00125: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 5.0, 35.0, 7.8125.0]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 433, 'code+const': 917}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    E=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    Y=E
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    return (a*x**2+b*x+c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y_hat[4]-float(Y[4]))**2+(Y_hat[3]-float(Y[3]))**2+(Y_hat[2]-float(Y[2]))**2+(Y_hat[1]-float(Y[1]))**2+(Y_hat[0]-float(Y[0]))

00126: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 498, 'const': 433, 'code+const': 931}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    a1, b1, c1, d1, e1 = Y
    A = float(a1)
    B = float(b1)
    C = float(c1)
    D = float(d1)
    E = float(e1)
    Y = [A,B,C,D,E]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y = a*(x**2)+b*x+c
    return Y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00127: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 502, 'const': 433, 'code+const': 935}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Answer1 = a*(x**2) + b*x + c
    return(Answer1)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Answer2 = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return(Answer2)
#======================================

00128: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 536, 'const': 433, 'code+const': 969}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 372.16 391.94 438.0 510.34
    Y = [float(e) for e in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.05
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x,a,b,c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y = [float(e) for e in Y]
    Y_hat = [float(e) for e in Y_hat]
    return (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
#======================================

00129: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 626, 'const': 433, 'code+const': 1059}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[None]*5
    Y_hat[0]=f(X[0],a,b,c)
    Y_hat[1]=f(X[1],a,b,c)
    Y_hat[2]=f(X[2],a,b,c)
    Y_hat[3]=f(X[3],a,b,c)
    Y_hat[4]=f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x=float(x)
    a=float(a)
    b=float(b)
    c=float(c)
    y=a*(x**2)+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y_hat[0]=float(Y_hat[0])
    Y_hat[1]=float(Y_hat[1])
    Y_hat[2]=float(Y_hat[2])
    Y_hat[3]=float(Y_hat[3])
    Y_hat[4]=float(Y_hat[4])
    SSE=((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00130: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[10.0, 45.0, 85.0, 117.38125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 9175.6875
[]
bytecount: {'code': 546, 'const': 459, 'code+const': 1005}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = ["j"]*5
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y = a*(x**2) + b*x + c
    return Y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[0])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2 
    return SSE
#======================================

00131: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[0],a,b,c)), float(f(X[1],a,b,c)), float(f(X[2],a,b,c)), float(f(X[3],a,b,c)), float(f(X[4],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = float(a)*x**2+float(b)*x+float(c) ; return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    e = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2  ; return round(e,4)
#======================================

00132: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 598, 'const': 433, 'code+const': 1031}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    Y_hat[0] = float(Y_hat[0])
    Y_hat[1] = float(Y_hat[1])
    Y_hat[2] = float(Y_hat[2])
    Y_hat[3] = float(Y_hat[3])
    Y_hat[4] = float(Y_hat[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    y = a*x**2 + b*x + c ; return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    S = (Y[0] - Y_hat[0])**2
    S = S + (Y[1] - Y_hat[1])**2
    S = S + (Y[2] - Y_hat[2])**2
    S = S + (Y[3] - Y_hat[3])**2
    S = S + (Y[4] - Y_hat[4])**2 ; return S
#======================================

00133: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 606, 'const': 433, 'code+const': 1039}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split()
    a = input('a = ')  
    b = input('b = ')  
    c = input('c = ') 
    Y[0]= float(Y[0])
    Y[1]= float(Y[1])
    Y[2]= float(Y[2])
    Y[3]= float(Y[3])
    Y[4]= float(Y[4])
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    plot(X,Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y = a*(x**2)+(b*x)+c
    return Y
#======================================
def SSE(Y, Y_hat):
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    s = (Y[0]-Y_hat[0])**2
    s += (Y[1]-Y_hat[1])**2
    s += (Y[2]-Y_hat[2])**2
    s += (Y[3]-Y_hat[3])**2
    s += (Y[4]-Y_hat[4])**2
    return s
 #======================================

00134: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0

Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 470, 'const': 433, 'code+const': 903}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    pre_y = input('Y = ').split() # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(pre_y[0]),float(pre_y[1]),float(pre_y[2]),float(pre_y[3]),float(pre_y[4])]
    print()
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = (a*x**2)+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    z = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return z
#======================================

00135: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 450, 'const': 433, 'code+const': 883}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c) , f(X[1],a,b,c) , f(X[2],a,b,c) , f(X[3],a,b,c) , f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
     Y = float(a)*x**2 + float(b)*x + float(c)
     return Y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y_hat[0])  - float(Y[0]))**2 + (float(Y_hat[1]) - float(Y[1]))**2 + (float(Y_hat[2]) - float(Y[2]))**2  + (float(Y_hat[3]) - float(Y[3]))**2 + (float(Y_hat[4]) - float(Y[4]))**2  
    return SSE
#======================================

00136: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 516, 'const': 433, 'code+const': 949}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    q0= float(Y[0])
    q1= float(Y[1])
    q2= float(Y[2])
    q3= float(Y[3])
    q4= float(Y[4])
    Y = [q0,q1,q2,q3,q4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    y0=float(f(X[0],a,b,c))
    y1=float(f(X[1],a,b,c))
    y2=float(f(X[2],a,b,c))
    y3=float(f(X[3],a,b,c))
    y4=float(f(X[4],a,b,c))
    Y_hat = [y0,y1,y2,y3,y4]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  return(a*(x**2)+b*x+c)
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return((Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2)
#======================================

00137: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 570, 'const': 433, 'code+const': 1003}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    Y_hat = a*X**2+b*X+c
    return Y_hat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    Y[0]=float (Y[0])
    Y[1]=float (Y[1])
    Y[2]=float (Y[2])
    Y[3]=float (Y[3])
    Y[4]=float (Y[4])
    SSE= (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
    # Y and Y_hat are lists of five floats
#======================================

00138: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2) + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return SSE
#======================================

00139: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 398, 'const': 405, 'code+const': 803}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    i = 0
    for i  in range(5) :
       Y[i] = float(Y[i]) 
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[ f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c) ]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2) + b*x +c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    n = 0
    sse = 0
    for n in range(5) :
      sse +=   (Y[n]-Y_hat[n])**2
    return sse  
#======================================

00140: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 518, 'const': 433, 'code+const': 951}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  y_hat = a*(x**2) + (b*x) + c
  return y_hat
#======================================
def SSE(Y, Y_hat):
  x = (Y[0] - Y_hat[0])**2
  x += (Y[1] - Y_hat[1])**2
  x += (Y[2] - Y_hat[2])**2
  x += (Y[3] - Y_hat[3])**2
  x += (Y[4] - Y_hat[4])**2
  return x
#======================================

00141: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split() # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y =a*(x**2) +b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse=((Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2)
    return sse
#======================================

00142: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 512, 'const': 433, 'code+const': 945}
import matplotlib.pyplot as plt
def plot(X, Z, Y_hat):
    plt.plot(X, Z, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    Y= input('Y = ').split()  
    Z = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    a = input('a = ')  
    b = input('b = ')  
    c = input('c = ')  
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    plot(X, Z, Y_hat)
    print("Sum of squared errors =", SSE(Z, Y_hat))
def f(x, a, b, c):
    yhat = (float(a)*float(x)**2)+(float(b)*float(x))+float(c)
    return yhat
def SSE(Z, Y_hat):
    sse = ((float(Z[0])-float(Y_hat[0]))**2+(float(Z[1])-float(Y_hat[1]))**2+(float(Z[2])-float(Y_hat[2]))**2+(float(Z[3])-float(Y_hat[3]))**2+(float(Z[4])-float(Y_hat[4]))**2)
    return sse

00143: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    z=(a*(X**2))+(b*X)+c
    return z
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    #SSE=((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    error=((float(Y[0])-float(Y_hat[0]))**2)+((float(Y[1])-float(Y_hat[1]))**2)+((float(Y[2])-float(Y_hat[2]))**2)+((float(Y[3])-float(Y_hat[3]))**2)+((float(Y[4])-float(Y_hat[4]))**2)
    return error
#======================================

00144: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 462, 'const': 433, 'code+const': 895}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2 + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = sum([(Y[0]-Y_hat[0])**2, (Y[1]-Y_hat[1])**2, (Y[2]-Y_hat[2])**2, (Y[3]-Y_hat[3])**2, (Y[4]-Y_hat[4])**2])
    return SSE
#======================================

00145: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 374, 'const': 336, 'code+const': 710}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()] # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a,b,c = [float(input(e +' = ')) for e in "abc"]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(e,a,b,c) for e in X]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return a*x**2+b*x+c
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return sum([(Y[i] - Y_hat[i])**2 for i in range(len(Y))])
#======================================

00146: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 440, 'const': 317, 'code+const': 757}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y = input().split()
    for  i in range (len(Y)) :
      Y[i]=float(Y[i])
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    #Y = input('Y = ').split()  # ลอง -4
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input())  # ลอง 12.8
    b = float(input())  # ลอง -40.2
    c = float(input())  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat=a*(x**2)+b*x+c
    return Y_hat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    sse = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return sse
    # Y and Y_hat are lists of five floats
#======================================

00147: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 552, 'const': 433, 'code+const': 985}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    yhat = float(a)*float(x)**2+float(b)*float(x)+float(c)
    return yhat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = [(float(Y[0])-Y_hat[0])**2,(float(Y[1])-Y_hat[1])**2,(float(Y[2])-Y_hat[2])**2,(float(Y[3])-Y_hat[3])**2,(float(Y[4])-Y_hat[4])**2,]
    sse1 = sse[0]+sse[1]+sse[2]+sse[3]+sse[4]
    return sse1
#======================================

00148: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
[1, 2, 3, 4, 5]
[9.5, 14.0, 25.0, 42.0, 65.0]
[9.75, 15.5, 27.75, 46.5, 71.75]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 518, 'const': 433, 'code+const': 951}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1, 2, 3, 4, 5]
    Y = input('Y = ').split()
    Y[0],Y[1],Y[2],Y[3],Y[4] = float(Y[0]),float(Y[1]),                                float(Y[2]),float(Y[3]),                                float(Y[4])
    a = float(input('a = '))
    b = float(input('b = '))
    c = float(input('c = '))
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c),              f(X[3],a,b,c), f(X[4],a,b,c)]
    plot(X, Y, Y_hat)
    print(X)
    print(Y)
    print(Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x,a,b,c) :
    Y_hat = a*x**2 + b*x + c
    return Y_hat
def SSE(Y,Y_hat) :
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 +            (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 +            (Y[4]-Y_hat[4])**2
    return SSE

00149: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 432, 'const': 465, 'code+const': 897}
from re import I
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = list(map(float,input('Y = ').split()))  # ลอง 378.66 372.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = ')) # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    answer = (a*(x**2) + b*x + c)
    return answer
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse_answer =(Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse_answer
#======================================

00150: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 444, 'const': 433, 'code+const': 877}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5):
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat  = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (a*x**2)+(b*x)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
   z =  (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
   return z 
#======================================

00151: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 486, 'const': 433, 'code+const': 919}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]= float(Y[0])
    Y[1]= float(Y[1])
    Y[2]= float(Y[2])
    Y[3]= float(Y[3])
    Y[4]= float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat= [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return (a*(x**2)+b*x+c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE= (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00152: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 468, 'const': 439, 'code+const': 907}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y=').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a='))  # ลอง 12.8
    b = float(input('b='))  # ลอง -40.2
    c = float(input('c='))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return(a*x**2+b*x+c)
#======================================
def SSE(Y, Y_hat):
    i=0
    h=0
    x=[0,1,2,3,4]
    y=[0,1,2,3,4]
    while i <5:
       h+=(Y_hat[i]-Y[i])**2
       i+=1
    # Y and Y_hat are lists of five float
    return(h)
#======================================

00153: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 468, 'const': 447, 'code+const': 915}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2) + b*(x**1) + c
    return (Y_hat)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((Y_hat[0]-Y[0])**2 + (Y_hat[1]-Y[1])**2 + (Y_hat[2]-Y[2])**2 + (Y_hat[3]-Y[3])**2 + (Y_hat[4]-Y[4])**2)
    return (sse)
#======================================

00154: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 433, 'code+const': 917}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    x = float(x) ; a = float(a) ; b = float(b) ; c = float(c)
    y = ((a*(x**2)) + (b*x) + c)
    return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    Sum = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return Sum
    # Y and Y_hat are lists of five floats
#======================================

00155: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 358, 'const': 379, 'code+const': 737}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(len(X)):
      Y_hat.append(f(X[i],a,b,c))
      Y[i] = float(Y[i])
    #print(Y)
    #print(Y_hat)
    #print(X)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(float(x)**2) + b*float(x) + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    d = 0
    for e in range(len(Y)):
      d += (float(Y[e]) - float(Y_hat[e]))**2
    return d
#======================================

00156: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 534, 'const': 433, 'code+const': 967}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0],Y[1],Y[2],Y[3],Y[4] = float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(float(X[0]),a,b,c),f(float(X[1]),a,b,c),f(float(X[2]),a,b,c),f(float(X[3]),a,b,c),f(float(X[4]),a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y = ((a*(x**2))+(b*x)+c)
    return Y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (((float(Y_hat[0])-Y[0])**2)+((float(Y_hat[1])-Y[1])**2)+((float(Y_hat[2])-Y[2])**2)+((float(Y_hat[3])-Y[3])**2)+((float(Y_hat[4])-Y[4])**2))
    return SSE
#======================================

00157: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 402, 'const': 421, 'code+const': 823}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split()
    Y = [float(x) for x in Y]
    a = float(input('a = '))
    b = float(input('b = '))
    c = float(input('c = '))
    Y_hat = [f(x,a,b,c) for x in X]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x,a,b,c):
    return a*(x**2)+b*x+c
def SSE(Y, Y_hat):
    return (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2

00158: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 508, 'const': 433, 'code+const': 941}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(y[0]),float(y[1]),float(y[2]),float(y[3]),float(y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x,a,b,c):
    # x, a, b and c are floats
    Y_hat = (float(a)*float(x)**2)+(float(b)*float(x))+float(c)
    return(Y_hat)
#======================================
def SSE(Y, Y_hat) :
    # Y and Y_hat are lists of five floats
    u = float(Y[0])
    i = float(Y[1])
    o = float(Y[2])
    p = float(Y[3])
    l = float(Y[4])
    return(((u-Y_hat[0])**2)+((i-Y_hat[1])**2)+((o-Y_hat[2])**2)+((p-Y_hat[3])**2)+((l-Y_hat[4])**2))
#======================================

00159: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 512, 'const': 433, 'code+const': 945}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(y[0]),float(y[1]),float(y[2]),float(y[3]),float(y[4])]
    a = input('a = ')  # ลอง -48
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
    answer = float(a)*float(x)**2+float(b)*float(x)+float(c)
    return answer
def SSE(Y, Y_hat):
    answer = (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
    return answer

00160: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 512, 'const': 433, 'code+const': 945}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(y[0]),float(y[1]),float(y[2]),float(y[3]),float(y[4])]
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c): 
    VAN = float(a)*(float(x)**2)+float(b)*float(x)+float(c)
    return VAN
def SSE(Y, Y_hat): 
    MILOS = ((float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2)
    return MILOS

00161: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 398, 'const': 391, 'code+const': 789}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()    # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2)+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    SSE = 0
    for i in range(len(Y)):
        x = (Y[i]-Y_hat[i])**2
        SSE = SSE+x
    return SSE
    # Y and Y_hat are lists of five floats
#======================================

00162: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0ValueError("could not convert string to float: '9.5 14 25 42 65'")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 552, 'const': 433, 'code+const': 985}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    Y1 = float(input('Y = '))
    Y2 = float(input('Y = '))
    Y3 = float(input('Y = '))
    Y4 = float(input('Y = '))
    Y5 = float(input('Y = '))
    Y=[Y1,Y2,Y3,Y4,Y5]
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat=[f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(X, a, b, c): 
    Y_hat=a*X**2+b*X+c
    return Y_hat
def SSE(Y, Y_hat):
    Y1=float(Y[0])
    Y2=float(Y[1])
    Y3=float(Y[2])
    Y4=float(Y[3])
    Y5=float(Y[4])
    Y_1=float(Y_hat[0])
    Y_2=float(Y_hat[1])
    Y_3=float(Y_hat[2])
    Y_4=float(Y_hat[3])
    Y_5=float(Y_hat[4])
    SSE=(Y1-Y_1)**2+(Y2-Y_2)**2+(Y3-Y_3)**2+(Y4-Y_4)**2+(Y5-Y_5)**2
    return SSE

00163: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 360, 'const': 409, 'code+const': 769}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5):
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0.0]*5
    for i in range(5):
      Y_hat[i] = float(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = (a*(x**2)+(b*x)+c)
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = 0
    for i in range(5):
      SSE += (Y[i]-Y_hat[i])**2
    return SSE
#======================================

00164: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 488, 'const': 433, 'code+const': 921}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    a = float(a)
    b = input('b = ')  # ลอง -40.2
    b = float(b)
    c = input('c = ')  # ลอง 400.5
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat0 = f(X[0],a,b,c)
    Y_hat1 = f(X[1],a,b,c)
    Y_hat2 = f(X[2],a,b,c)
    Y_hat3 = f(X[3],a,b,c)
    Y_hat4 = f(X[4],a,b,c)
    Y_hat = [Y_hat0,Y_hat1,Y_hat2,Y_hat3,Y_hat4]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
#======================================

00165: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 502, 'const': 433, 'code+const': 935}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a=float(a)
    b=float(b)
    c=float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=a*(x**2)+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE=(Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00166: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 433, 'code+const': 917}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [ float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4]) ]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [ f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c), ]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
     Y_hat = a*x**2 + b*x + c
     return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0]) - Y_hat[0])**2 + (float(Y[1]) - Y_hat[1])**2 + (float(Y[2]) - Y_hat[2])**2 + (float(Y[3]) - Y_hat[3])**2  + (float(Y[4]) - Y_hat[4])**2
    return SSE
#======================================

00167: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 348, 'const': 379, 'code+const': 727}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for x in X:
      Y_hat.append(f(x,a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return (a*(x**2))+(b*x)+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    answer = 0
    for i in range(len(Y_hat)):
      answer += ((Y_hat[i]-Y[i])**2)
    return answer
#======================================

00168: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[None0.0, None5.0, None5.0, None7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = None75.6875
[]
bytecount: {'code': 412, 'const': 405, 'code+const': 817}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for m in range (0,5):
      Y_hat.append(f(X[m],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = a*x*x+b*x+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    k=0
    SSE=0
    if k<=4 : 
        sse = ((Y[k]) - (Y_hat[k]))**2
        SSE = SSE + sse
        k += 1 
    else :
        return SSE
#======================================

00169: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 15.0, 15.0, 17.568125]
test_main0.0ValueError("could not convert string to float: '9.5 14 25 42 65'")
inpuY >&gt; y:[9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 428, 'const': 412, 'code+const': 840}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat, 'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    Y = []
    i = 1
    while i <= 5:
        print('input y: %d' % i)
        n = float(input())
        Y.append(n)
        i += 1
    a = float(input('a = '))
    b = float(input('b = '))
    c = float(input('c = '))
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
    y = float(a*x*x+b*x+c)
    return y
def SSE(Y, Y_hat):
    SSE = 0
    i = 0
    while i <= 4:
        X = float(Y[i]-Y_hat[i])**2
        i += 1
        SSE = SSE+X
        return SSE

00170: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 498, 'const': 433, 'code+const': 931}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = float(a)*float(x**2) + float(b)*float(x) + float(c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00171: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 492, 'const': 433, 'code+const': 925}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    Y_1 = float(a)*(float(X)**2)+float(b)*float(X)+float(c )
    return Y_1
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((float(Y[0])-float(Y_hat[0]))**2)+((float(Y[1])-float(Y_hat[1]))**2)+((float(Y[2])-float(Y_hat[2]))**2)+((float(Y[3])-float(Y_hat[3]))**2)+((float(Y[4])-float(Y_hat[4]))**2)
    return SSE
#======================================

00172: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 476, 'const': 433, 'code+const': 909}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    f = (a*x**2) + (b*x) + c
    return f
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return SSE
#======================================

00173: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 4
    Y = float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x , a , b , c):
  # x, a, b and c are floats
    y_hat=a*(x**2)+b*x+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE_value=((float(Y[0])-float(Y_hat[0]))**2)               +((float(Y[1])-float(Y_hat[1]))**2)               +((float(Y[2])-float(Y_hat[2]))**2)               +((float(Y[3])-float(Y_hat[3]))**2)               +((float(Y[4])-float(Y_hat[4]))**2)
    return SSE_value
#======================================

00174: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 405, 'code+const': 869}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    Y_hat = [float(Y_hat[0]),float(Y_hat[1]),float(Y_hat[2]),float(Y_hat[3]),float(Y_hat[4])]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    SSE = 0
    for i in range(5): 
      SSE = SSE + (Y[i] - Y_hat[i])**2
    return SSE
    # Y and Y_hat are lists of five floats
#======================================

00175: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 424, 'const': 433, 'code+const': 857}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = list(map(float,Y))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat = a*(x**2) + b*x + c
    return Y_hat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    Error = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4]))**2
    return Error
    # Y and Y_hat are lists of five floats
#======================================

00176: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 454, 'const': 433, 'code+const': 887}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]   # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = float(a*x**2+b*x+c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE   = (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2         # Y and Y_hat are lists of five floats
    return SSE    
#======================================

00177: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 416, 'const': 421, 'code+const': 837}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    a = float(a)
    b = float(b)
    c = float(c)
    for i in X:
      Y_hat.append(f(i, a, b, c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    E = (float(Y[0])-float(Y_hat[0]))**2 + (float(Y[1])-float(Y_hat[1]))**2 + (float(Y[2])-float(Y_hat[2]))**2 + (float(Y[3])-float(Y_hat[3]))**2 + (float(Y[4])-float(Y_hat[4]))**2
    return E
#======================================

00178: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 508, 'const': 433, 'code+const': 941}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = ')) # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c) , f(X[1],a,b,c) , f(X[2],a,b,c) , f(X[3],a,b,c) , f(X[4],a,b,c) ]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    Y_hat = float(a*X**2+b*X+c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
    return SSE
#======================================

00179: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ') # ลอง 12.8
    b = input('b = ') # ลอง -40.2
    c = input('c = ') # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return float(a)*float(x)**2 + float(b)*float(x) + float(c)
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    return (float(Y_hat[0])- float(Y[0]))**2 + (float(Y_hat[1])- float(Y[1]))**2 + (float(Y_hat[2])- float(Y[2]))**2 + (float(Y_hat[3])- float(Y[3]))**2 + (float(Y_hat[4])- float(Y[4]))**2
    # Y and Y_hat are lists of five floats
#======================================

00180: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 370, 'const': 391, 'code+const': 761}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = list(map(float, Y))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = 0
    for i in range(len(Y)):
        SSE += (Y[i] - Y_hat[i])**2
    return SSE
#======================================

00181: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 402, 'const': 405, 'code+const': 807}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    n = 0
    for i in Y:
      Y[n] = float(Y[n])
      n += 1
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2) + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    i = 0
    for x in Y:
      sse += (x - Y_hat[i])**2
      i += 1
    return sse
#======================================

00182: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[None0.0, None5.0, None5.0, None7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = None75.6875
[]
bytecount: {'code': 444, 'const': 433, 'code+const': 877}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(x) for x in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    yhat = a*x**2 + b*x + c
    return yhat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    g = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    # Y and Y_hat are lists of five floats
#======================================

00183: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 546, 'const': 433, 'code+const': 979}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[0], a, b,c)),float(f(X[1], a, b, c)),float(f(X[2], a, b, c)),float(f(X[3], a, b, c)),float(f(X[4], a, b, c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return float((a*x**2)+(b*x)+c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return ((float(Y_hat[0])-float(Y[0]))**2)+((float(Y_hat[1])-float(Y[1]))**2)+((float(Y_hat[2])-float(Y[2]))**2)+((float(Y_hat[3])-float(Y[3]))**2)+((float(Y_hat[4])-float(Y[4]))**2)
#======================================

00184: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 414, 'const': 391, 'code+const': 805}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x=float(x)
    a=float(a)
    b=float(b)
    c=float(c)
    return a*(x**2)+(b*x)+c
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
        Y[i]=float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    n=0
    for i in range(len(Y)):
        n=n+(Y[i]-Y_hat[i])**2
    return n
#======================================

00185: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 356, 'const': 379, 'code+const': 735}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(i) for i in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range (len(X)):
      Y_hat.append(f(X[i], a, b, c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum = 0
    for i in range(len(Y)):
      sum += (Y_hat[i] - Y[i])**2
    return sum
#======================================

00186: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 398, 'const': 419, 'code+const': 817}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(x) for x in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c),              f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (a*x**2) + (b*x) + c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    k = 0
    while k <= 4:
      sse += (Y[k] - Y_hat[k])**2
      k += 1
    return sse
#======================================

00187: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 538, 'const': 433, 'code+const': 971}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c): 
  y = (float(a)*(float(x)**2))+(float(b)*float(x))+float(c)
  return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  COM = (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
  return COM
    # Y and Y_hat are lists of five floats
#======================================

00188: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (a*(x**2)) + (b*x) +c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2 
    return SSE
#======================================

00189: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 419, 'code+const': 903}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),  f(X[2],a,b,c),f(X[3],a,b,c), f(X[4],a,b,c)]
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  Y_hat = a*(x*x) + b*x + c
  return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  SSE = (float(Y[0]) - Y_hat[0])**2 + (float(Y[1]) - Y_hat[1])**2 + (float(Y[2]) - Y_hat[2])**2 + (float(Y[3]) - Y_hat[3])**2 + (float(Y[4]) - Y_hat[4])**2 
  return SSE
#======================================

00190: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0TypeError("unsupported operand type(s) for -: 'float' and 'str'")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 352, 'const': 391, 'code+const': 743}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(y) for y in Y] # Convert Y to floating number
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5):
      y_hat = f(X[0], a, b, c) # Convert a,b,c from string to floating number
      Y_hat.append(y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    length_of_Y = len(Y) # is 5
    for i in range(length_of_Y): # will loop 0, 1, 2, 3, 4
      sse += (Y[i] - Y_hat[i])**2 
    return sse
#======================================

00191: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 408, 'const': 387, 'code+const': 795}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(i) for i in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [ f(i,a,b,c) for i in X ] 
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (a*(x**2))+(b*x)+c
    return y_hat
#======================================
def SUM(x):
    sum = 0
    for i in x :
      x = i
      sum += x
    return sum
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE_list = [ (i-j)**2 for i,j in zip(Y,Y_hat) ]
    SSE = SUM(SSE_list)
    return SSE
#======================================

00192: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 478, 'const': 404, 'code+const': 882}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(e) for e in input().split()]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    Y_hat.append(f(X[0],a,b,c))
    Y_hat.append(f(X[1],a,b,c))
    Y_hat.append(f(X[2],a,b,c))
    Y_hat.append(f(X[3],a,b,c))
    Y_hat.append(f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  Y_hat = (a*(x**2))+(b*x)+c
  return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  SSE = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
  return SSE
#======================================

00193: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat = a * (x ** 2) + b * x + c # x, a, b and c are floats
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    SSE = (Y[0] - Y_hat[0]) ** 2 + (Y[1] - Y_hat[1]) ** 2 +     (Y[2] - Y_hat[2]) ** 2 +(Y[3] - Y_hat[3]) ** 2 +     (Y[4] - Y_hat[4]) ** 2
    return SSE
    # Y and Y_hat are lists of five floats
#======================================

00194: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 482, 'const': 447, 'code+const': 929}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat, 'r')
    plt.show()
# ======================================
def main():
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจนวนำจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    for i in range(1, 6):
        Y.append(float(Y[i-1]))
    for i in range(1, 6):
        Y.pop(0)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
# ======================================
def f(x, a, b, c):
    Y_hat = a * x ** 2 + b * x + c
    return Y_hat
# x, a, b and c are floats
# ======================================
def SSE(Y, Y_hat):
    SSE = (Y[0] - Y_hat[0]) ** 2 + (Y[1] - Y_hat[1]) ** 2 + (Y[2] - Y_hat[2]) ** 2 + (Y[3] - Y_hat[3]) ** 2 + (Y[4] - Y_hat[4])**2
    return SSE
# Y and Y_hat are lists of five floats
# ======================================

00195: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 440, 'const': 419, 'code+const': 859}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x*x + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse
#======================================

00196: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 378, 'const': 393, 'code+const': 771}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    Y_float = []
    for i in range(1, len(X)+1):
      Y_hat.append(f(X[i-1],a,b,c))
    for i in Y:
      Y_float.append(float(i))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y_float, Y_hat)
    print("Sum of squared errors =", SSE(Y_float, Y_hat))
#======================================
def f(x, a, b, c):
    return (a *(x**2)) + (b*x) + c
#======================================
def SSE(Y, Y_hat):
    sse = 0
    for i in range(1, len(Y)+1):
      sse = sse + (Y[i-1] - Y_hat[i-1])**2
    return sse
#======================================

00197: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    Y_hat.append(f(X[0],a,b,c))
    Y_hat.append(f(X[1],a,b,c))
    Y_hat.append(f(X[2],a,b,c))
    Y_hat.append(f(X[3],a,b,c))
    Y_hat.append(f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2)+(b*x)+c 
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    z = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return z
#======================================

00198: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 330, 'const': 379, 'code+const': 709}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in X :
      w = f(i, a, b, c)
      Y_hat.append(w)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  y_hat = (a*(x**2)) + (b*x) + c
  return y_hat
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  sse_sum = 0
  count_y = len(Y)
  for i in range(count_y) :
    sse = (float(Y[i]) - Y_hat[i])**2
    sse_sum += sse
  return sse_sum
    # Y and Y_hat are lists of five floats
#======================================

00199: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("object of type 'float' has no len()")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 424, 'const': 431, 'code+const': 855}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    x=X
    Y_hat= f(x, a, b, c)
    o=0
    for o in range (len(Y)):
      Y[o]=float(Y[o])
    else:
      pass
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    i=0
    Y_hat=[]
    for i in range (len(x)):
      Y_hat.append((((float(a)*float(x[i])**2)+(float(b)*(float(x[i])))+float(c))))
      i +=1
    else:
      return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    p=0
    sse=0
    for p in range (len(Y)):
      sse+= (float(Y[p])-float(Y_hat[p]))**2
      p+=1
    else:
      return sse
#======================================

00200: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = a*x**2 + b*x + c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0])-float(Y_hat[0]))**2 + (float(Y[1])-float(Y_hat[1]))**2 + (float(Y[2])-float(Y_hat[2]))**2 + (float(Y[3])-float(Y_hat[3]))**2 + (float(Y[4])-float(Y_hat[4]))**2 
    return SSE
#======================================

00201: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 460, 'const': 433, 'code+const': 893}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat0 = f(X[0],a,b,c)
    Y_hat1 = f(X[1],a,b,c)
    Y_hat2 = f(X[2],a,b,c)
    Y_hat3 = f(X[3],a,b,c)
    Y_hat4 = f(X[4],a,b,c)
    Y_hat = [Y_hat0 ,Y_hat1 ,Y_hat2 ,Y_hat3 ,Y_hat4]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = a*x**2 + b*x + c
    return (y_hat)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    error = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return (error)
#======================================

00202: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 454, 'const': 433, 'code+const': 887}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    a = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34 -> ['378.66','379.16'.....]
    Y = []
    for y in a:
      Y.append(float(y))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00203: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 456, 'const': 485, 'code+const': 941}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1.0,2.0,3.0,4.0,5.0]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    #Y = [378.66,379.19,391.94,438.0,510.34]
    #Y_hat = [372.65,370.85,394.65,444.05,519.05]
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    #print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x*x+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
#======================================

00204: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0 Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
^
IndentationError: unexpected indent
[10.0, 21.25, 87.0625]
test_SSE0.0 Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
^
IndentationError: unexpected indent
[0.0, 5.0, 5.0, 7.8125]
test_main0.0 Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
^
IndentationError: unexpected indent
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
     Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y = a*(x**2) + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    A = (Y[0]-Y_hat[0])**3 + (Y[1]-Y_hat[1])**3+ (Y[2]-Y_hat[2])**3 + (Y[3]-Y_hat[3])**3 + (Y[4]-Y_hat[4])**3
#======================================

00205: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float( Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y = a*(x**2) + b*x + c
    return Y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    A = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2+ (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return A
#======================================

00206: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 432, 'const': 317, 'code+const': 749}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input()
    y1 = y.split()
    Y = list(map(float,y1))  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input())  # ลอง 12.8
    b = float(input()) # ลอง -40.2
    c = float(input())  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(float(X[0]), a, b, c), f(float(X[1]), a, b, c), f(float(X[2]), a, b, c), f(float(X[3]), a, b, c), f(float(X[4]), a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
# ======================================
def f(x, a, b, c):
# x, a, b and c are floats
    return a*(x**2) + b*x + c
# ======================================
def SSE(Y, Y_hat):
# Y and Y_hat are lists of five floats
    return (Y_hat[0]-Y[0])**2 + (Y_hat[1]-Y[1])**2 + (Y_hat[2]-Y[2])**2 + (Y_hat[3]-Y[3])**2 + (Y_hat[4]-Y[4])**2
# ======================================

00207: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 586, 'const': 433, 'code+const': 1019}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    X[0],X[1],X[2],X[3],X[4] = [float(X[0]),float(X[1]),float(X[2]),float(X[3]),float(X[4])]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
# สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [Y[0],Y[1],Y[2],Y[3],Y[4]]
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    F = float(a)*(float(x)**2) + float(b)*x + float(c)
    return(F)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y_hat[0]-Y[0])**2+(Y_hat[1]-Y[1])**2+(Y_hat[2]-Y[2])**2+(Y_hat[3]-Y[3])**2+(Y_hat[4]-Y[4])**2)
    return(SSE)
#======================================

00208: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 546, 'const': 433, 'code+const': 979}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    a1,a2,a3,a4,a5 = input('Y = ').split()# ลอง 378.66 379.16 391.94 438.0 510.34
    a1 = float(a1)
    a2 = float(a2)
    a3 = float(a3)
    a4 = float(a4)
    a5 = float(a5)
    Y = [a1,a2,a3,a4,a5]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    a = float(a)
    b = float(b)
    c = float(c)
    x = float(x)
    y = (a*(x**2))+(b*x)+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSEk = (float(Y_hat[0])-float(Y[0]))**2 + (float(Y_hat[1])-float(Y[1]))**2 + (float(Y_hat[2])-float(Y[2]))**2 + (float(Y_hat[3])-float(Y[3]))**2 + (float(Y_hat[4])-float(Y[4]))**2
    return SSEk
#======================================

00209: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 488, 'const': 433, 'code+const': 921}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
# สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_0 = f(X[0],a,b,c)
    Y_1 = f(X[1],a,b,c)
    Y_2 = f(X[2],a,b,c)
    Y_3 = f(X[3],a,b,c)
    Y_4 = f(X[4],a,b,c)
    Y_hat = [Y_0, Y_1, Y_2, Y_3, Y_4]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = float(a)*(float(x)**2) + float(b)*x + float(c)
    return(y)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    S = (Y_hat[0]-Y[0])**2+(Y_hat[1]-Y[1])**2+(Y_hat[2]-Y[2])**2+(Y_hat[3]-Y[3])**2+(Y_hat[4]-Y[4])**2
    return(S)
#======================================

00210: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0 for i in range(len(Y)):
^
IndentationError: unexpected indent
[10.0, 21.25, 87.0625]
test_SSE0.0 for i in range(len(Y)):
^
IndentationError: unexpected indent
[0.0, 5.0, 5.0, 7.8125]
test_main0.0 for i in range(len(Y)):
^
IndentationError: unexpected indent
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    print(Y)
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
       for i in range(len(Y)):
          Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  return a*x**2 + b*x +c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum = 0
    for i in range(len(Y)):
      sum += (Y[i] - Y_hat[i])**2
    return sum  
#======================================

00211: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = float(a)*(x**2) + (float(b)*x) + (float(c))
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    n1 = (float(Y[0])-float(Y_hat[0]))**2
    n2 = (float(Y[1])-float(Y_hat[1]))**2
    n3 = (float(Y[2])-float(Y_hat[2]))**2
    n4 = (float(Y[3])-float(Y_hat[3]))**2
    n5 = (float(Y[4])-float(Y_hat[4]))**2
    SSE = n1 + n2 + n3 + n4 + n5
    return SSE
#======================================

00212: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'float' object is not subscriptable")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
[9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 570, 'const': 475, 'code+const': 1045}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 372.16 391.94 438.0 510.34
    Y = [float(x) for x in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X,a,b,c)
    print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    X = x
    x0=X[0]
    x2=X[1]
    x3=X[2]
    x4=X[3]
    x5=X[4]
    y_hat0=a*(x0**2)+b*x0+c
    y_hat1=a*(x2**2)+b*x2+c
    y_hat2=a*(x3**2)+b*x3+c
    y_hat3=a*(x4**2)+b*x4+c
    y_hat4=a*(x5**2)+b*x5+c
    Y_hat=[y_hat0,y_hat1,y_hat2,y_hat3,y_hat4]
    [float(x) for x in Y_hat]   
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE_value=(Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE_value
#======================================

00213: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0NameError("name 'SSE' is not defined")
[0.0, 5.0, 5.0, 7.8125]
test_main1.0NameError("name 'SSE' is not defined")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 482, 'const': 434, 'code+const': 916}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
  plt.plot(X, Y, 'g+')
  plt.plot(X, Y_hat,'r')
  plt.show()
#==============================
def main():
  X = [1,2,3,4,5]
  # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
  # เก็บใส่ตัวแปร y ที่เป็นลิสต์ห้าช่อง
  Y = input('Y =  ').split() # ลอง 378.66 379.16 391.94 438.0 510.34
  Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
  # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์
  a = float(input('a = ')) #ลอง 12.8
  b = float(input('b = ')) #ลอง -40.2
  c = float(input('c = ')) #ลอง 400.5
  #สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c),f(X[1],a,b,c), ..., f(X[4],a,b,c)
  Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
  # ไม่ต้องแก้ไขคำสั่งข้างล่างนี้
  plot(X, Y, Y_hat)
  print("Sum of squared errors =", SSE(Y, Y_hat))
#============================
def f(x, a, b, c):
  # x, a, b and c are floats
  m = (a*((x)**2))+(b*x)+c
  return m
#============================
def mmr(Y, Y_hat):
  # Y and Y_hat are lists of five floats
  mmr = ((float(Y[0])-(Y_hat[0]))**2)+((float(Y[1])-(Y_hat[1]))**2)+((float(Y[2])-(Y_hat[2]))**2)+((float(Y[3])-(Y_hat[3]))**2)+((float(Y[4])-(Y_hat[4]))**2)
  return (mmr)
#======================================

00214: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 456, 'const': 433, 'code+const': 889}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2 + b*x +c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
#======================================

00215: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 419, 'code+const': 883}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y = (a*x*x)+(b*x)+c
    return Y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00216: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 360, 'const': 391, 'code+const': 751}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(s) for s in Y]
    #print(Y)
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range (0,len(Y)):
      Y_hat.append(f(X[i],a,b,c))
    #print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  return a*(x**2) + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = 0
    for i in range (0,len(Y)):
      SSE += (Y[i] - Y_hat[i])**2
    return SSE
#======================================

00217: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 422, 'const': 317, 'code+const': 739}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input().split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input())  # ลอง 12.8
    b = float(input())  # ลอง -40.2
    c = float(input())  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c) , f(X[1],a,b,c) , f(X[2],a,b,c) , f(X[3],a,b,c) , f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    yhat=a*x**2 + b*x + c
    return yhat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse= (float(Y[0])-Y_hat[0])**2 + (float(Y[1])-Y_hat[1])**2 + (float(Y[2])-Y_hat[2])**2 + (float(Y[3])-Y_hat[3])**2 + (float(Y[4])-Y_hat[4])**2
    return sse
#======================================

00218: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 428, 'const': 419, 'code+const': 847}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=a*x**2+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    n=0
    sse=[0]*5
    while n < 5:
         sse[n]=(Y[n]-Y_hat[n])**2
         n+=1
    return sum(sse)
#======================================

00219: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 478, 'const': 433, 'code+const': 911}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def f(x, a, b, c):
    Y_hat = a*(x**2)+b*x+c
    return Y_hat
def SSE(Y, Y_hat):
    return sum([abs(Y[0]-Y_hat[0])**2,abs(Y[1]-Y_hat[1])**2,abs(Y[2]-Y_hat[2])**2,abs(Y[3]-Y_hat[3])**2,abs(Y[4]-Y_hat[4])**2])
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])
    #print(Y)
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)
    #print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))

00220: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 452, 'const': 433, 'code+const': 885}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(x) for x in input('Y = ').split()]
     # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat  = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2) + b*x + c
def SSE(Y, Y_hat):
    #Y and Y_hat are lists of five floats
    return (Y_hat[0]-float(Y[0]))**2 + (Y_hat[1]-float(Y[1]))**2 +(Y_hat[2]-float(Y[2]))**2 + (Y_hat[3]-float(Y[3]))**2 + (Y_hat[4]-float(Y[4]))**2

00221: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 588, 'const': 433, 'code+const': 1021}
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 5
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    p0 =f(X[0],a,b,c)
    p1 =f(X[1],a,b,c)
    p2 =f(X[2],a,b,c)
    p3 =f(X[3],a,b,c)
    p4 =f(X[4],a,b,c)
    Y_hat = [p0,p1,p2,p3,p4]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    p = a*(x**2) + b*x + c
    return p
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    y0 = float(Y[0])
    y1 = float(Y[1])
    y2 = float(Y[2])
    y3 = float(Y[3])
    y4 = float(Y[4])
    yh0 = float(Y_hat[0])
    yh1 = float(Y_hat[1])
    yh2 = float(Y_hat[2])
    yh3 = float(Y_hat[3])
    yh4 = float(Y_hat[4])
    d = (y0-yh0)**2+(y1-yh1)**2+(y2-yh2)**2+(y3-yh3)**2+(y4-yh4)**2
    return d
#======================================

00222: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[[0.0], [5.0], [5.0], [7.8125]]
test_main1.0
[9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = [75.6875]
[]
bytecount: {'code': 474, 'const': 433, 'code+const': 907}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat, 'r')
    plt.show()
# ======================================
def main():
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    # รับค่าของ a
    print("Sum of squared errors =", SSE(Y, Y_hat))
# ======================================
def f(x, a, b, c):
    Y_hat=(a*(x**2))+(b*x)+c
    return Y_hat
# ======================================
def SSE(Y, Y_hat):
    er=[((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)]
    return er
# ======================================

00223: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [(f(X[0],a,b,c)),(f(X[1],a,b,c)),(f(X[2],a,b,c)),(f(X[3],a,b,c)),(f(X[4],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return  float(a)*( float(x)**2)+float(b)*float(x)+float(c)
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    return ((Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2)
    # Y and Y_hat are lists of five floats
#======================================

00224: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 358, 'const': 393, 'code+const': 751}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    _Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = []
    for i in range(5):
      Y.append(float(_Y[i]))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    y = (a*(x**2)) + b*x +c
    return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    sum = 0
    for i in range(5) :
      sum += ((Y[i] - Y_hat[i])**2)
    return sum
    # Y and Y_hat are lists of five floats
#======================================

00225: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 396, 'const': 379, 'code+const': 775}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    # Y = [378.66,379.16,391.94,438.0,510.34]
    Y = [float(i) for i in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    # a, b, c = 12.8, -40.2, 400.5
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    # print('Y', Y)
    # print('Y hat:', Y_hat)
    return sum([(Y[i] - Y_hat[i])**2 for i in range(len(Y))])
#======================================

00226: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 468, 'const': 433, 'code+const': 901}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat, 'r')
    plt.show()
# ======================================
def main():
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input('Y = ')
    Y_str = y.split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y_str[0]), float(Y_str[1]), float(Y_str[2]), float(Y_str[3]), float(Y_str[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
# ======================================
def f(x, a, b, c):
    y = (a*(x**2)) + (b*x) + c
    return y
# x, a, b and c are floats
# ======================================
def SSE(Y, Y_hat):
    sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse
# Y and Y_hat are lists of five floats
# ======================================

00227: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 378, 'const': 367, 'code+const': 745}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(e) for e in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    a = float(a)
    b = input('b = ')  # ลอง -40.2
    b = float(b)
    c = input('c = ')  # ลอง 400.5
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(x,a,b,c) for x in X]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2)+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return sum([(Y[i]-Y_hat[i])**2 for i in range(len(Y))])
#======================================

00228: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 452, 'const': 433, 'code+const': 885}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = float(a)*float(x)**2 + float(b)*float(x) + float(c)
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse
#======================================

00229: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 532, 'const': 433, 'code+const': 965}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    y1 = float(Y[0])
    y2 = float(Y[1])
    y3 = float(Y[2])
    y4 = float(Y[3])
    y5 = float(Y[4])
    Y = [y1,y2,y3,y4,y5]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    yh = float(a)*(float(x)**2)+float(b)*float(x)+float(c)
    return yh
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
    return SSE
#======================================

00230: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 384, 'const': 365, 'code+const': 749}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for k  in range(5):
        Y[k] = float(Y[k])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for k in range(5):
        Y_collect = f(X[k],float(a),float(b),float(c)) 
        Y_hat.append(Y_collect)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return (float(a)*x*x)+(float(b)*x)+float(c) # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    fault = 0
    for k  in range(5):
        fault = fault + (float(Y[k])-Y_hat[k])*(float(Y[k])-Y_hat[k])
    return fault
#======================================

00231: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 526, 'const': 433, 'code+const': 959}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c,),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=float(a)*float(x)**2+float(b)*float(x)+float(c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    Y_hat = [float(Y_hat[0]),float(Y_hat[1]),float(Y_hat[2]),float(Y_hat[3]),float(Y_hat[4])]
    SSE = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00232: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 524, 'const': 433, 'code+const': 957}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4]),]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = a*(x**2)+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0])-float(Y_hat[0]))**2 + (float(Y[1])-float(Y_hat[1]))**2 +            (float(Y[2])-float(Y_hat[2]))**2 + (float(Y[3])-float(Y_hat[3]))**2 +            (float(Y[4])-float(Y_hat[4]))**2
    return SSE
#======================================

00233: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 486, 'const': 433, 'code+const': 919}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),              f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  k = a*(x**2)+b*x+c
  return k
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  return (Y_hat[0]-Y[0])**2+(Y_hat[1]-Y[1])**2+(Y_hat[2]-Y[2])**2+   (Y_hat[3]-Y[3])**2+(Y_hat[4]-Y[4])**2
    # Y and Y_hat are lists of five floats
#======================================

00234: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
[10.0, 201.025, 872.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(0, len(Y)):
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):    # x, a, b and c are floats
    return float(a)*int(X)**2+float(b)*int(X)+float(c)   
#======================================
def SSE(Y, Y_hat):    # Y and Y_hat are lists of five floats
    return (float(Y_hat[0])-float(Y[0]))**2+(float(Y_hat[1])-float(Y[1]))**2+(float(Y_hat[2])-float(Y[2]))**2+(float(Y_hat[3])-float(Y[3]))**2+(float(Y_hat[4])-float(Y[4]))**2
#======================================

00235: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 372.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c),f(X[1], a, b, c),f(X[2], a, b, c),f(X[3], a, b, c),f(X[4], a, b, c)]
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat = (a*(x**2)) + (b*x) + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    SSE = ((Y[0]-Y_hat[0])**2) + ((Y[1]-Y_hat[1])**2) + ((Y[2]-Y_hat[2])**2) + ((Y[3]-Y_hat[3])**2) + ((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00236: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    fx = (a*(x**2))+(b*x)+c
    return fx
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  sigma = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
  return sigma
#======================================

00237: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 433, 'code+const': 917}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c) , f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = a*(x**2)+ b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse  =(Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse
#======================================

00238: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 540, 'const': 433, 'code+const': 973}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],float(a),float(b),float(c)),f(X[1],float(a),float(b),float(c)),f(X[2],float(a),float(b),float(c)),f(X[3],float(a),float(b),float(c)),f(X[4],float(a),float(b),float(c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return float(a)*x**2+float(b)*x+float(c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse1 = (float(Y[0])-Y_hat[0])**2+(float(Y[1])-Y_hat[1])**2+(float(Y[2])-Y_hat[2])**2+(float(Y[3])-Y_hat[3])**2+(float(Y[4])-Y_hat[4])**2
    return sse1
#======================================

00239: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 518, 'const': 433, 'code+const': 951}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    y = float(a)*(x**2) + float(b)*x + float(c)
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-float(Y_hat[0]))**2 + (Y[1]-float(Y_hat[1]))**2 + (Y[2]-float(Y_hat[2]))**2 + (Y[3]-float(Y_hat[3]))**2 + (Y[4]-float(Y_hat[4]))**2
    return SSE
#======================================

00240: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [float(1),float(2),float(3),float(4),float(5)]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y0 = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y0[0]),float(Y0[1]),float(Y0[2]),float(Y0[3]),float(Y0[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hato = a*(x**2) + b*x + c
    return Y_hato
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    sse = (Y[0]-float(Y_hat[0]))**2 + (Y[1]-float(Y_hat[1]))**2 + (Y[2]-float(Y_hat[2]))**2 + (Y[3]-float(Y_hat[3]))**2 + (Y[4]-float(Y_hat[4]))**2
    return sse
    # Y and Y_hat are lists of five floats
#======================================

00241: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 482, 'const': 433, 'code+const': 915}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
#======================================

00242: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 668, 'const': 393, 'code+const': 1061}
import matplotlib.pyplot as plt
import math
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input("Y = ").split()  #อย่าลืมว่าถ้ารับมาเป็น list งี้ มันจะเป็น str # ลอง 378.66 379.16 391.94 438.0 510.34 
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])] #แปลงค่า Y ที่ได้ให้เป็นจำนวนจริง
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5 <--- ทำให้ Y ไม่ตรงกับตัวอย่างข้างบน เพราะข้างบนใช้ Y = 400.05
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    #print("Y_hat = ",Y_hat) ; print("Y = ",Y)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = float(a) * float(math.pow(float(x),2)) + float(b) * float(x) + float(c)
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    # กระบวนการคล้ายๆ กับ ข้อบัตรประชาชน
    i = 1 
    sum = math.pow((float(Y[i-1])-float(Y_hat[i-1])),2) ; i = i + 1  #i = 1
    sum += math.pow((float(Y[i-1])-float(Y_hat[i-1])),2) ; i = i + 1 #i = 2
    sum += math.pow((float(Y[i-1])-float(Y_hat[i-1])),2) ; i = i + 1 #i = 3
    sum += math.pow((float(Y[i-1])-float(Y_hat[i-1])),2) ; i = i + 1 #i = 4
    sum += math.pow((float(Y[i-1])-float(Y_hat[i-1])),2) #i = 5
    SSE = float(sum)
    return SSE
#======================================

00243: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat, 'r')
    plt.show()
# ======================================
def main():
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[0],a,b,c)),float(f(X[1],a,b,c)),float(f(X[2],a,b,c)),float(f(X[3],a,b,c)),float(f(X[4],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
# ======================================
def f(x, a, b, c):
    a=float(a)
    b=float(b)
    c=float(c)
    x=float(x)
    y=a*x**2+b*x+c
    return y
# x, a, b and c are floats
# ======================================
def SSE(Y, Y_hat):
    s=((Y[0])-(Y_hat[0]))**2+((Y[1])-(Y_hat[1]))**2+((Y[2])-(Y_hat[2]))**2+((Y[3])-(Y_hat[3]))**2+((Y[4])-(Y_hat[4]))**2
    return s
# Y and Y_hat are lists of five floats
# ======================================

00244: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
[1, 2, 3, 4, 5] [9.5, 14.0, 25.0, 42.0, 65.0] [9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 438, 'const': 433, 'code+const': 871}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5):
        Y_hat.append(f(X[i],a,b,c))
    print(X,Y,Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2)+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    s = (Y_hat[0]-Y[0])**2 + (Y_hat[1]-Y[1])**2 + (Y_hat[2]-Y[2])**2 + (Y_hat[3]-Y[3])**2 + (Y_hat[4]-Y[4])**2
    return s
#======================================

00245: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 460, 'const': 433, 'code+const': 893}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    #Y = [378.66, 372.16, 391.94, 438.0, 510.34]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    #print(a)
    #print(b)
    #print(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    #Y_hat = [372.65, 370.85, 394.65, 444.05, 519.05]
    #print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    d = float(a)*(x**2) + float(b)*x + float(c)
    return d
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    x1 = (Y_hat[0] - Y[0])**2
    x2 = (Y_hat[1] - Y[1])**2
    x3 = (Y_hat[2] - Y[2])**2
    x4 = (Y_hat[3] - Y[3])**2
    x5 = (Y_hat[4] - Y[4])**2
    a = x1 + x2 + x3 + x4 + x5
    return a
#======================================

00246: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 510, 'const': 433, 'code+const': 943}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    y = a*(x**2) + b*x + c# x, a, b and c are floats
    return y
#======================================
def SSE(Y, Y_hat):
    z = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)# Y and Y_hat are lists of five floats
    return z
#======================================

00247: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 560, 'const': 433, 'code+const': 993}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
  X = [1,2,3,4,5]
  Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
  a = float(input('a = '))  # ลอง 12.8
  b = float(input('b = '))  # ลอง -40.2
  c = float(input('c = '))  # ลอง 400.5
  Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
  Y_hat = [float(e) for e in Y_hat]
  Y = [float(e) for e in Y]
  X = [float(e) for e in X]
  plot(X, Y, Y_hat)
  print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
  Y = a*float(x)**2 + b*float(x) + c
  return Y
def SSE(Y, Y_hat):
    SSE = (float(Y_hat[0])-float(Y[0]))**2 + (float(Y_hat[1])-float(Y[1]))**2 + (float(Y_hat[2])-float(Y[2]))**2 + (float(Y_hat[3])-float(Y[3]))**2 + (float(Y_hat[4])-float(Y[4]))**2
    return SSE

00248: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 480, 'const': 433, 'code+const': 913}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y) for Y in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a=float(a)
    b=float(b)
    c=float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y=a*(x**2)+b*x+c
    return float(y)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    a=(float(Y[0])-Y_hat[0])**2+(float(Y[1])-Y_hat[1])**2+(float(Y[2])-Y_hat[2])**2+(float(Y[3])-Y_hat[3])**2+(float(Y[4])-Y_hat[4])**2
    return a
#======================================

00249: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 518, 'const': 433, 'code+const': 951}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    Y_hat = [Y_hat[0],Y_hat[1],Y_hat[2],Y_hat[3],Y_hat[4]]
    Y = [float(Y[0]) , float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    X = float(X)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = (a*(X)**2)+(b*X)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y_hat[0]-Y[0])**2+(Y_hat[1]-Y[1])**2+(Y_hat[2]-Y[2])**2+(Y_hat[3]-Y[3])**2+(Y_hat[4]-Y[4])**2
    return SSE
#======================================

00250: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 568, 'const': 433, 'code+const': 1001}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    X[0],X[1],X[2],X[3],X[4] = float(X[0]),float(X[1]),float(X[2]),float(X[3]),float(X[4])
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    m = (a*((x)**2))+(b*x)+c
    return m
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((float(Y[0])-Y_hat[0])**2)+((float(Y[1])-Y_hat[1])**2)+((float(Y[2])-Y_hat[2])**2)+((float(Y[3])-Y_hat[3])**2)+((float(Y[4])-Y_hat[4])**2)
    return sse
#======================================

00251: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 472, 'const': 433, 'code+const': 905}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split()
    Y= [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    a = input('a = ')  
    b = input('b = ')  
    c = input('c = ')  
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    SSE = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00252: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 360, 'const': 405, 'code+const': 765}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2) + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans = 0
    for i in range(5):
      ans += (float(Y[i]) - float(Y_hat[i]))**2
    return ans
#======================================

00253: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 486, 'const': 433, 'code+const': 919}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a* x**2 + b * x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2  + (Y[3]-Y_hat[3])**2 +(Y[4]-Y_hat[4])**2  
#======================================

00254: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 516, 'const': 433, 'code+const': 949}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split() # ลอง 378.66 379.16 391.94 438.0 510.34
    y0 = float(Y[0])
    y1 = float(Y[1])
    y2 = float(Y[2])
    y3 = float(Y[3])
    y4 = float(Y[4])
    Y = [y0,y1,y2,y3,y4]  
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ') # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    yh0 = f(X[0],a,b,c)
    yh1 = f(X[1],a,b,c)
    yh2 = f(X[2],a,b,c)
    yh3 = f(X[3],a,b,c)
    yh4 = f(X[4],a,b,c)
    Y_hat = [yh0,yh1,yh2,yh3,yh4]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  y = a*x**2+b*x+c
  return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  SSE = (Y_hat[0]-Y[0])**2 + (Y_hat[1]-Y[1])**2 + (Y_hat[2]-Y[2])**2 + (Y_hat[3]-Y[3])**2 + (Y_hat[4]-Y[4])**2
  return SSE
    # Y and Y_hat are lists of five floats
#======================================

00255: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 546, 'const': 433, 'code+const': 979}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (a*(x**2))+(b*x)+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans = (float(Y[0])-float(Y_hat[0]))**2
    ans += (float(Y[1])-float(Y_hat[1]))**2
    ans += (float(Y[2])-float(Y_hat[2]))**2
    ans += (float(Y[3])-float(Y_hat[3]))**2
    ans += (float(Y[4])-float(Y_hat[4]))**2
    return ans
#======================================

00256: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 390, 'const': 409, 'code+const': 799}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [ float(e) for e in Y ]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [ f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = 0.0 
    for a in range(5) :
      SSE = SSE + (Y[a]-Y_hat[a])**2
    return SSE
#======================================

00257: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split() # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]),float(Y[4])]    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
                                     # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]# สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat =a*x**2+b*x+c# x, a, b and c are floats
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    ans = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 +(Y[4]-Y_hat[4])**2# Y and Y_hat are lists of five floats
    return ans
#======================================

00258: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("unsupported operand type(s) for ^: 'float' and 'float'")
[10.0, 21.25, 87.0625]
test_SSE0.0TypeError("unsupported operand type(s) for ^: 'float' and 'int'")
[0.0, 5.0, 5.0, 7.8125]
test_main0.0TypeError("unsupported operand type(s) for +: 'int' and 'str'")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 388, 'const': 419, 'code+const': 807}
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a * x ^ 2 + b * x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    total_sse = 0
    for i in range(5):
        total_sse += (Y[i - 1] - Y_hat[i - 1]) ^ 2 
    return total_sse
#======================================

00259: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 506, 'const': 433, 'code+const': 939}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง -
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a=float(input('a = '))# ลอง 12.8
    b=float(input('b = '))  # ลอง -40.2
    c=float(input('c = '))   # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=a*(x**2)+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    results= (Y[0]-Y_hat[0])**2
    results+= (Y[1]-Y_hat[1])**2
    results+= (Y[2]-Y_hat[2])**2
    results+= (Y[3]-Y_hat[3])**2
    results+= (Y[4]-Y_hat[4])**2
    return results
#======================================

00260: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 598, 'const': 433, 'code+const': 1031}
import matplotlib.pyplot as plt
def plot(X,Y,Y_hat):
    plt.plot(X,Y,'g+')
    plt.plot(X,Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    a0=float(Y[0]);a1=float(Y[1]);a2=float(Y[2]);a3=float(Y[3]);a4=float(Y[4])
    Y=[a0,a1,a2,a3,a4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ, f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X,Y,Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  a=float(a);b=float(b);c=float(c);x=float(x)
  a1=a*(x**2)+b*x+c
  return a1
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  b1=float(Y[0]);b2=float(Y[1]);b3=float(Y[2]);b4=float(Y[3]);b5=float(Y[4])
  a=[b1,b2,b3,b4,b5]
  a1=Y_hat[0]-a[0]
  a2=Y_hat[1]-a[1]
  a3=Y_hat[2]-a[2]
  a4=Y_hat[3]-a[3]
  a5=Y_hat[4]-a[4]
  sse=a1**2+a2**2+a3**2+a4**2+a5**2
  return sse
    # Y and Y_hat are lists of five floats
#======================================

00261: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 524, 'const': 433, 'code+const': 957}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    Y=float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])
    #print(Y)
    #print(type(Y))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (float(a)*(float(x)**2))+(float(b)*float(x))+float(c)
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = ((float(Y[0])-float(Y_hat[0]))**2)+((float(Y[1])-float(Y_hat[1]))**2)+((float(Y[2])-float(Y_hat[2]))**2)     +((float(Y[3])-float(Y_hat[3]))**2)+((float(Y[4])-float(Y_hat[4]))**2)
    return sse
#======================================

00262: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 486, 'const': 433, 'code+const': 919}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0]);Y[1] = float(Y[1]);Y[2] = float(Y[2]);Y[3] = float(Y[3]);Y[4] = float(Y[4]);
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  y = a*(x)**2+b*x+c
  return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
#======================================

00263: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 536, 'const': 379, 'code+const': 915}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    y1,y2,y3,y4,y5 = [float(e) for e in Y]
    Y = [y1,y2,y3,y4,y5]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[0],a,b,c)) , float(f(X[1],a,b,c)) , float(f(X[2],a,b,c)) ,float(f(X[3],a,b,c)) , float(f(X[4],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    result = a*(x**2) + b * x + c 
    return result
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    y1,y2,y3,y4,y5 = [float(e) for e in Y]
    yh1,yh2,yh3,yh4,yh5 = [float(e) for e in Y_hat]
    a = (yh1 - y1)**2 + (yh2 - y2)**2 + (yh3 - y3)**2 + (yh4 - y4)**2 + (yh5 - y5)**2
    return a
#======================================

00264: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 420, 'const': 433, 'code+const': 853}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = list(map(float,input('Y = ').split()))  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2 + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return SSE
#======================================

00265: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 448, 'const': 433, 'code+const': 881}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(x) for x in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = (a*(float(x)**2))+(b*x)+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00266: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 496, 'const': 433, 'code+const': 929}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c),f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2) + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (float(Y[0])-float(Y_hat[0]))**2 + (float(Y[1])-float(Y_hat[1]))**2 + (float(Y[2])-float(Y_hat[2]))**2 + (float(Y[3])-float(Y_hat[3]))**2 + (float(Y[4])-float(Y_hat[4]))**2
#======================================

00267: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 45.0, 45.0, 67.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 3075.126875
[]
bytecount: {'code': 422, 'const': 405, 'code+const': 827}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(x) for x in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  x = float(x)
  a = float(a)
  b = float(b)
  c = float(c)
  y = (a*(x**2))+b*x+c
  return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
   lst = []
   for i in range(0,4):
       s = (Y[i]-Y_hat[i])**2
       lst.append(s)
   k = sum(lst)
   return k        
    # Y and Y_hat are lists of five floats
#======================================

00268: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 574, 'const': 449, 'code+const': 1023}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0.0]*5
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  x1 = float(a)*(x**2)
  x2 = float(b)*x
  y_hat = x1+x2+float(c)
  return(y_hat)
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  x1 = (float(Y[0])-Y_hat[0])**2
  x2 = (float(Y[1])-Y_hat[1])**2
  x3 = (float(Y[2])-Y_hat[2])**2
  x4 = (float(Y[3])-Y_hat[3])**2
  x5 = (float(Y[4])-Y_hat[4])**2
  SSE = x1+x2+x3+x4+x5
  return(SSE)
    # Y and Y_hat are lists of five floats
#======================================

00269: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 452, 'const': 433, 'code+const': 885}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(d) for d in  input('Y = ').split()] # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return float(a)*x**2 + float(b)*x + float(c)
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    return (float(Y[0])-Y_hat[0])**2 + (float(Y[1])-Y_hat[1])**2 + (float(Y[2])-Y_hat[2])**2 + (float(Y[3])-Y_hat[3])**2 + (float(Y[4])-Y_hat[4])**2
    # Y and Y_hat are lists of five floats
#======================================

00270: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
[9.5, 14.0, 25.0, 42.0, 65.0] [9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 410, 'const': 407, 'code+const': 817}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[]
    for i in range(5):
        Y_hat.append(f(X[i],a,b,c))
        Y[i]=float(Y[i])
    print(Y,Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (float(a)*float(x)*float(x)) + (float(b)*float(x)) + float(c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return ans
#======================================

00271: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 500, 'const': 433, 'code+const': 933}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    # g+ คือจุด r คือเส้น
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    Y=y
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (float(Y[0]) - Y_hat[0])**2 + (float(Y[1]) - Y_hat[1])**2 + (float(Y[2]) - Y_hat[2])**2 + (float(Y[3]) - Y_hat[3])**2 + (float(Y[4]) - Y_hat[4])**2
#======================================

00272: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("unsupported operand type(s) for ** or pow(): 'list' and 'int'")
[10.0, 21.25, 87.0625]
test_SSE0.0NameError("name 'SSE' is not defined")
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 598, 'const': 597, 'code+const': 1195}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    w = input('Y = ').split()
    l = float(w[0])
    m = float(w[1])
    n = float(w[2])
    o = float(w[3])
    p = float(w[4])
    Y = [l,m,n,o,p]
    #Y = [378.66 ,379.16 ,391.94 ,438.0 ,510.34]  # ลอง 378.66 372.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    d = input('a = ')  # ลอง 12.8
    e = input('b = ')  # ลอง -40.2378.66 379.16
    f = input('c = ')  # ลอง 400.5
    a = float(d)
    b = float(e)
    c = float(f)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    def f(X, a, b, c):
        return a*X**2+b*X+c
    Y_hat= [a*1**2+b*1+c, a*2**2+b*2+c,a*3**2+b*3+c,a*4**2+b*4+c, a*5**2+b*5+c]
    #Y_hat= [373.1,371.3,395.1,444.5,519.5]
    def SSE(Y, Y_hat):
        return ((a*1**2+b*1+c)-l)**2+((a*2**2+b*2+c)-m)**2+((a*3**2+b*3+c)-n)**2+((a*4**2+b*4+c)-o)**2+((a*5**2+b*5+c)-p)**2
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    X = [1,2,3,4,5]
    return a*X**2+b*X+c
    # x, a, b and c are floats
#======================================
    # Y and Y_hat are lists of five floats
#======================================

00273: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 344, 'const': 393, 'code+const': 737}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [ float(i) for i in Y ]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float( input('a = ') )  # ลอง 12.8
    b = float( input('b = ') )  # ลอง -40.2
    c = float( input('c = ') )  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in X:
      Y_hat.append(f(i,a,b,c))    
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = (a*(x**2)) + (b*x) + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Sum = 0
    for i in range(5):
      Sum = Sum + (Y[i]-Y_hat[i])**2
    return Sum
#======================================

00274: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 532, 'const': 433, 'code+const': 965}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    aaa = float(Y[0])
    bbb = float(Y[1])
    ccc = float(Y[2])
    ddd = float(Y[3])
    eee = float(Y[4])
    Y = [aaa,bbb,ccc,ddd,eee]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = float(a)*float(x**2) + float(b)*float(x) + float(c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0]) - float(Y_hat[0]))**2 + (float(Y[1]) - float(Y_hat[1]))**2 + (float(Y[2]) - float(Y_hat[2]))**2 + (float(Y[3]) - float(Y_hat[3]))**2 + (float(Y[4]) - float(Y_hat[4]))**2
    return SSE
#======================================

00275: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 522, 'const': 433, 'code+const': 955}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0,0,0,0,0]
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
# ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return ((Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2)
#======================================

00276: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 434, 'const': 351, 'code+const': 785}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for e in X:
      Y_hat.append(str(f(e,a,b,c)))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x1 = float(x)
    a1 = float(a)
    b1 = float(b)
    c1 = float(c)
    return a1*(x1*x1)+b1*x1+c1
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    y = []
    y_hat = []
    sse = 0
    for i in range(len(Y)):
      y.append(float(Y[i]))
    for i in range(len(Y_hat)):
      y_hat.append(float(Y_hat[i]))
    for i in range(len(y)):
      sse += (y[i]-y_hat[i])*(y[i]-y_hat[i])
    return sse
#======================================

00277: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 574, 'const': 433, 'code+const': 1007}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    X[0] = float(X[0])
    X[1] = float(X[1])
    X[2] = float(X[2])
    X[3] = float(X[3])
    X[4] = float(X[4])
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = (f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c),)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    return (a*X**2)+(b*X)+c
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    return (Y_hat[0]-Y[0])**2+(Y_hat[1]-Y[1])**2+(Y_hat[2]-Y[2])**2+(Y_hat[3]-Y[3])**2+(Y_hat[4]-Y[4])**2
    # Y and Y_hat are lists of five floats
#======================================

00278: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 456, 'const': 433, 'code+const': 889}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=(f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c))
    Y=float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    return a*X**2+b*X+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
#======================================

00279: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[None0.0, None5.0, None5.0, None7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = None75.6875
[]
bytecount: {'code': 382, 'const': 391, 'code+const': 773}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(_) for _ in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y  = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    y=0
    for i in range(5) :
        y+=(Y_hat[i]-Y[i])
#======================================

00280: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 344, 'const': 393, 'code+const': 737}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    #Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in input('Y = ').split()]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5):
      Y_hat.append(f(X[i], a, b, c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    error = 0
    for i in range(5):
      error += (Y[i] - Y_hat[i])**2
    return error
#======================================

00281: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 366, 'const': 393, 'code+const': 759}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    temp = []
    for i in Y:
      temp.append(float(i))
    Y = temp
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    a = float(a)
    b = input('b = ')  # ลอง -40.2
    b = float(b)
    c = input('c = ')  # ลอง 400.5
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range (5):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y=a*(x**2) + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Z=0
    for i in range (5):
      Z+=(Y[i]-Y_hat[i])**2
    return Z  
#======================================

00282: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 488, 'const': 433, 'code+const': 921}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    #x=float(input())
    #a=float(input())
    #b=float(input())
    #c=float(input())
    Y_hat=float(a*(x**2)+(b*x)+c)
    return(Y_hat)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE=(float(Y[0])-Y_hat[0])**2+(float(Y[1])-Y_hat[1])**2+(float(Y[2])-Y_hat[2])**2+(float(Y[3])-Y_hat[3])**2+(float(Y[4])-Y_hat[4])**2
    return(SSE)
#======================================

00283: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0
[None10.0, None21.25, None87.0625]
test_SSE0.0
[None0.0, None5.0, None5.0, None7.8125]
test_main0.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 154, 'const': 291, 'code+const': 445}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
def f(x, a, b, c):
    # x, a, b and c are floats
    pass
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    pass

00284: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 482, 'const': 433, 'code+const': 915}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)] 
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  return      a*(x**2)+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  return  ( ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2) )
#======================================

00285: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 596, 'const': 433, 'code+const': 1029}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    y1,y2,y3,y4,y5 = [e for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(y1),float(y2),float(y3),float(y4),float(y5)]
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    x0 = float(X[0])
    x1 = float(X[1])
    x2 = float(X[2])
    x3 = float(X[3])
    x4 = float(X[4])
    Y_hat = [f(x0,a,b,c), f(x1,a,b,c), f(x2,a,b,c), f(x3,a,b,c), f(x4,a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = float(a*(x**2) + b*x + c)
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    SSE = ((float(Y[0])-float(Y_hat[0]))**2) + ((float(Y[1])-float(Y_hat[1]))**2) + ((float(Y[2])-float(Y_hat[2]))**2) + ((float(Y[3])-float(Y_hat[3]))**2) + ((float(Y[4])-float(Y_hat[4]))**2)
    return SSE
#======================================

00286: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 590, 'const': 433, 'code+const': 1023}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input("Y = ").split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c) 
    Y_hat0 = f( X[0], a, b, c)
    Y_hat1 = f( X[1], a, b, c)
    Y_hat2 = f( X[2], a, b, c)
    Y_hat3 = f( X[3], a, b, c)
    Y_hat4 = f( X[4], a, b, c)
    Y_hat = [Y_hat0 , Y_hat1 , Y_hat2 , Y_hat3 , Y_hat4]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = a*(x**2)+b*(x)+c
    return Y_hat   
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y0 = Y[0]
    Y1 = Y[1]
    Y2 = Y[2]
    Y3 = Y[3]
    Y4 = Y[4]
    Y_hat0 = float(Y_hat[0])
    Y_hat1 = float(Y_hat[1])
    Y_hat2 = float(Y_hat[2])
    Y_hat3 = float(Y_hat[3])
    Y_hat4 = float(Y_hat[4])
    SSE = (Y_hat0 - Y0)**2 + (Y_hat1 - Y1)**2 + (Y_hat2 - Y2)**2 + (Y_hat3 - Y3)**2 + (Y_hat4 - Y4)**2 
    return SSE
#======================================

00287: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 496, 'const': 433, 'code+const': 929}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 372.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[0],a,b,c)), float(f(X[1],a,b,c)), float(f(X[2],a,b,c)), float(f(X[3],a,b,c)), float(f(X[4],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้3
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (float(Y[0])-Y_hat[0])**2 + (float(Y[1])-Y_hat[1])**2 +(float(Y[2])-Y_hat[2])**2 +(float(Y[3])-Y_hat[3])**2 +(float(Y[4])-Y_hat[4])**2
#======================================

00288: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 510, 'const': 433, 'code+const': 943}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split()
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    a = input('a = ')  
    b = input('b = ')  
    c = input('c = ')  
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b,c):
    x=float(x)
    a=float(a)
    b=float(b)
    c=float(c)
    y_hat=(a*((x)**2))+b*(x)+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
  SSE=((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
  return SSE
#======================================
    #นายมิตรภาพ นาคมูล id6531021021

00289: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 494, 'const': 433, 'code+const': 927}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [ f(X[0],a,b,c) ,f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c), f(X[4],a,b,c) ]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return a*x**2+b*x+c
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
#======================================

00290: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 419, 'code+const': 903}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5):
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c) ,f(X[1],a,b,c) ,f(X[2],a,b,c) ,f(X[3],a,b,c) ,f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    r=float(a)*x*x+float(b)*x+float(c)
    return r
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    t=(float(Y[0])-float(Y_hat[0]))**2+(float(Y[1])-float(Y_hat[1]))**2+(float(Y[2])-float(Y_hat[2]))**2+(float(Y[3])-float(Y_hat[3]))**2+(float(Y[4])-float(Y_hat[4]))**2
    return t
#======================================

00291: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 368, 'const': 391, 'code+const': 759}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)) :
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [0]*5
    for i in range(len(Y_hat)) :
        Y_hat[i] = f(X[i],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    result = (float(a)*x*x) + (float(b)*x) + float(c) 
    return result
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    E = 0
    for i in range(5):
        E += (float(Y[i])-Y_hat[i])**2
    return E
#======================================

00292: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split() # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])] # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
                                                                      # ลอง 378.66 379.16 391.94 438.0 510.34
                                                                      # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)] # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat = a*(x**2)+b*x+c
    return Y_hat             # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    SSE = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2) 
    # Y and Y_hat are lists of five floats
    return SSE
#======================================

00293: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y = [9.5, 14.0, 25.0, 42.0, 65.0]
Y_hat =  [9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 434, 'const': 480, 'code+const': 914}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    A = (input('a = '))  # ลอง 12.8
    B = (input('b = '))  # ลอง -40.2
    C = (input('c = '))  # ลอง 400.5
    a = float(A)
    b = float(B)
    c = float(C)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [ f(X[0],a,b,c) , f(X[1],a,b,c) , f(X[2],a,b,c) , f(X[3],a,b,c) , f(X[4],a,b,c) ]
    print("Y =", Y)
    print("Y_hat = ",Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = ( a * (x**2)  + ( b*x ) + c ) 
    return (Y_hat)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    x = 0
    result = 0
    for x  in range(5) : 
      result = result +  (Y[x] - Y_hat[x])**2
      x = x+1
    return result
#--------------------------------

00294: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 370, 'const': 383, 'code+const': 753}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(i) for i in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[i],a,b,c) for i in range(5)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ssum = 0.0
    for i in range(len(Y)):
      ssum+=(Y[i]-Y_hat[i])**2
    return ssum
#======================================

00295: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 568, 'const': 433, 'code+const': 1001}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y=  [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =  [f(X[0],float(a),float(b),float(c)),  f(X[1],float(a),float(b),float(c)),  f(X[2],float(a),float(b),float(c)),  f(X[3],float(a),float(b),float(c)), f(X[4],float(a),float(b),float(c))  ]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return  float(a)*float(x)**2 + float(b)*float(x) + float(c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    a= (float(Y[0])-float(Y_hat[0]))**2  + (float(Y[1])-float(Y_hat[1]))**2  + (float(Y[2])-float(Y_hat[2]))**2  + (float(Y[3])-float(Y_hat[3]))**2  + (float(Y[4])-float(Y_hat[4]))**2    
    return a 
#======================================

00296: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0Time-out: 3s
[0.0, 5.0, 5.0, 7.8125]
test_main0.0Time-out: 3s
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 398, 'const': 419, 'code+const': 817}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
      Y[i]=float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return float(a)*float(x)**2 + float(b)*x + float(c) 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
     total = 0
     n=5
     i=1
     while i<=n:
      total+=(Y[i]-Y_hat[i])**2
     return
#======================================

00297: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 504, 'const': 433, 'code+const': 937}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2) + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0]) - float(Y_hat[0]))**2 + (float(Y[1]) - float(Y_hat[1]))**2 + (float(Y[2]) - float(Y_hat[2]))**2 + (float(Y[3]) - float(Y_hat[3]))**2 + (float(Y[4]) - float(Y_hat[4]))**2
    return SSE
#======================================

00298: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0 sse = (Y[0]-Y_hat[0])2+(Y[1]-Y_hat[1])2+(Y[2]-Y_hat[2])2+(Y[3]-Y_hat[3])2+(Y[4]-Y_hat[4])**2
^
SyntaxError: invalid syntax
[10.0, 21.25, 87.0625]
test_SSE0.0 sse = (Y[0]-Y_hat[0])2+(Y[1]-Y_hat[1])2+(Y[2]-Y_hat[2])2+(Y[3]-Y_hat[3])2+(Y[4]-Y_hat[4])**2
^
SyntaxError: invalid syntax
[0.0, 5.0, 5.0, 7.8125]
test_main0.0 sse = (Y[0]-Y_hat[0])2+(Y[1]-Y_hat[1])2+(Y[2]-Y_hat[2])2+(Y[3]-Y_hat[3])2+(Y[4]-Y_hat[4])**2
^
SyntaxError: invalid syntax
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = (input('Y = ')).split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # แปลง element ของ List Y ให้เป็น float ทุกตัว
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = ax**2+bx+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])2+(Y[1]-Y_hat[1])2+(Y[2]-Y_hat[2])2+(Y[3]-Y_hat[3])2+(Y[4]-Y_hat[4])**2
    return sse
#======================================

00299: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 454, 'const': 430, 'code+const': 884}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y0, y1, y2, y3, y4 = input().split(' ')  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(y0), float(y1), float(y2), float(y3), float(y4)]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2 
    return sse
#======================================

00300: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0 Return S
^
SyntaxError: invalid syntax
[10.0, 21.25, 87.0625]
test_SSE0.0 Return S
^
SyntaxError: invalid syntax
[0.0, 5.0, 5.0, 7.8125]
test_main0.0 Return S
^
SyntaxError: invalid syntax
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y=a*x**2+b*x+c
    return y 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    S=(Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    Return S
#======================================

00301: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 516, 'const': 433, 'code+const': 949}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
  plt.plot(X,Y,"g+")
  plt.plot(X,Y_hat,'r')
  plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y =input('y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y= [float(y[0]),float(y[1]),float(y[2]),float(y[3]),float(y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[0],a,b,c)),float(f(X[1],a,b,c)),float(f(X[2],a,b,c)),float(f(X[3],a,b,c)),float(f(X[4],a,b,c))]
# ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    return float(a)*(X**2) + float(b)*(X) + float(c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (float(Y[0])-float(Y_hat[0]))**2 + (float(Y[1])-float(Y_hat[1]))**2 + (float(Y[2])-float(Y_hat[2]))**2 + (float(Y[3])-float(Y_hat[3]))**2 + (float(Y[4])-float(Y_hat[4]))**2

00302: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 604, 'const': 419, 'code+const': 1023}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y_f = []
    Y_f.append(float(Y[0]))
    Y_f.append(float(Y[1]))
    Y_f.append(float(Y[2]))
    Y_f.append(float(Y[3]))
    Y_f.append(float(Y[4]))
    Y = Y_f
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    Y_hat.append(f(X[0],a,b,c))
    Y_hat.append(f(X[1],a,b,c))
    Y_hat.append(f(X[2],a,b,c))
    Y_hat.append(f(X[3],a,b,c))
    Y_hat.append(f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x*x + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0] - Y_hat[0])*(Y[0] - Y_hat[0]) + (Y[1] - Y_hat[1])*(Y[1] - Y_hat[1]) + (Y[2] - Y_hat[2])*(Y[2] - Y_hat[2]) + (Y[3] - Y_hat[3])*(Y[3] - Y_hat[3]) + (Y[4] - Y_hat[4])*(Y[4] - Y_hat[4])
#======================================

00303: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 540, 'const': 433, 'code+const': 973}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c) , f(X[1],a,b,c) , f(X[2],a,b,c) , f(X[3],a,b,c) , f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
    #======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (float(a)*(x**2) + (float(b)*x) + float(c))
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats 
    Y0 = float(Y[0])
    Y1 = float(Y[1])
    Y2 = float(Y[2])
    Y3 = float(Y[3])
    Y4 = float(Y[4])
    Y_hat0 = float(Y_hat[0])
    Y_hat1 = float(Y_hat[1])
    Y_hat2 = float(Y_hat[2])
    Y_hat3 = float(Y_hat[3])
    Y_hat4 = float(Y_hat[4])
    return (Y0-Y_hat0)**2 + (Y1-Y_hat1)**2 + (Y2-Y_hat2)**2 + (Y3-Y_hat3)**2 + (Y4-Y_hat4)**2
#======================================

00304: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 476, 'const': 433, 'code+const': 909}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')
    a = float(a) # ลอง 12.8
    b = input('b = ') 
    b = float(b)# ลอง -40.2
    c = input('c = ') 
    c = float(c)
     # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    z = a*(X)**2+b*X+c
    return z 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    K = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return K

00305: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 464, 'const': 433, 'code+const': 897}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]) , float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    Y_hat = (a*X**2) + (b*X) + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00306: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 470, 'const': 429, 'code+const': 899}
import matplotlib.pyplot as plt
import math as m
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = list([float(g) for g in Y])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = list(f(X[i], a, b, c) for i in range(5))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    vec_y = a*m.pow(x,2) + b*x + c
    return vec_y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = m.pow(Y[0]-Y_hat[0],2) + m.pow(Y[1]-Y_hat[1],2) + m.pow(Y[2]-Y_hat[2],2) + m.pow(Y[3]-Y_hat[3],2) + m.pow(Y[4]-Y_hat[4],2)
    return sse
#======================================

00307: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 352, 'const': 379, 'code+const': 731}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(y) for y in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(x ,a , b, c) for x in X]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ret = 0
    for i in range(len(Y)):
        ret += (Y[i]-Y_hat[i])**2
    return ret
#======================================

00308: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 326, 'const': 393, 'code+const': 719}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5):
      Y_hat += [float(f(X[i],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return(y)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    s = 0
    for i in range(5):
      s += (Y_hat[i]-float(Y[i]))**2
    return(s)
#======================================

00309: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 364, 'const': 379, 'code+const': 743}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(len(Y)):
        Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y_hat = float(a)*x**2+float(b)*x+float(c)
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum = 0
    for i in range(len(Y)):
        sum+=(Y[i]-Y_hat[i])**2
    return sum
#======================================

00310: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 348, 'const': 393, 'code+const': 741}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(i) for i in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(5) :
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a * x**2 + b * x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    for i in range(5):
      sse += (Y[i]-Y_hat[i])**2
    return sse
#======================================

00311: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[220.0, 285.0, 285.0, 3407.38125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 30755.6.1875
[]
bytecount: {'code': 376, 'const': 431, 'code+const': 807}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split(" ")  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    i = 0
    while i < 5:
        Y_hat.append(f(X[i], a, b, c))
        i+=1
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat)) 
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*float(x**2) + b*float(x) + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    for i in range (0, 5):
        sse += (Y[i] + Y_hat[i])**2
    return sse
#======================================

00312: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 364, 'const': 379, 'code+const': 743}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(len(Y)):
        Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = float(a)*(x**2) + float(b)*x + float(c)
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    for i in range(len(Y)):
        sse += (Y[i] - Y_hat[i])**2
    return sse
#======================================

00313: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 360, 'const': 393, 'code+const': 753}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(x) for x in Y]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    a = float(a)
    b = input('b = ')  # ลอง -40.2
    b= float(b)
    c = input('c = ')  # ลอง 400.5
    c=float(c)
    Y_hat = []
    for i in range(5):
      Y_hat.append(f(X[i], a, b, c))
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    return (a*x**2)+b*x+c
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    sum = 0
    for i in range(5):
      sum += (Y[i]-Y_hat[i])**2
    return sum
    # Y and Y_hat are lists of five floats
#======================================

00314: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 400, 'const': 392, 'code+const': 792}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input().split()] # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(len(Y)):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  return a*(x**2) + b*x + c 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  sse = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 +(Y[2] - Y_hat[2])**2 +(Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2 
  return sse
#======================================

00315: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 440, 'const': 432, 'code+const': 872}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y =').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00316: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 574, 'const': 446, 'code+const': 1020}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split() # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = ')) # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = ['']*int(5)
    Y_hat[0] = float(f(X[0],a,b,c))
    Y_hat[1] = float(f(X[1],a,b,c))
    Y_hat[2] = float(f(X[2],a,b,c))
    Y_hat[3] = float(f(X[3],a,b,c))
    Y_hat[4] = float(f(X[4],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = (a*(x*x)) + (b*x) + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = 0
    sse += (Y[0]-Y_hat[0])**2
    sse += (Y[1]-Y_hat[1])**2
    sse += (Y[2]-Y_hat[2])**2
    sse += (Y[3]-Y_hat[3])**2
    sse += (Y[4]-Y_hat[4])**2
    return sse
#======================================

00317: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()# ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c) , f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
    # x, a, b and c are floats
    Y_hat = (a*(X**2))+(b*X)+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2  + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2
    return SSE
#======================================

00318: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 402, 'const': 419, 'code+const': 821}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input('Y = ')  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = y.split()
    Y = [float(i) for i in Y]    
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [ f(X[0],a,b,c) , f(X[1],a,b,c) , f(X[2],a,b,c) , f(X[3],a,b,c) , f(X[4],a,b,c) ]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = ( a*(x**2) ) +( b*x ) + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    i = 0
    sum = 0
    while i < 5 : 
      sum = sum +  (Y[i] - Y_hat[i])**2
      i = i+1
    return sum
#======================================

00319: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 388, 'const': 405, 'code+const': 793}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = []
    for i in y:
      Y.append(float(i))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    yhat = a*x**2 + b*x + c
    return yhat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse1 = 0
    for i in range(5):
      sse1 += (Y[i] - Y_hat[i])**2
    return sse1
#======================================

00320: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 442, 'const': 429, 'code+const': 871}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    # ลอง 378.66 379.16 391.94 438.0 510.34
    y = input('Y =').split()
    Y = []
    for P in y:
        Y.append(float(P))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a ='))  # ลอง 12.8
    b = float(input('b ='))  # ลอง -40.2
    c = float(input('c ='))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ((Y[0]-Y_hat[0])**2) + ((Y[1]-Y_hat[1])**2) + ((Y[2]-Y_hat[2])**2) + ((Y[3]-Y_hat[3])**2) + ((Y[4]-Y_hat[4])**2)
    return SSE
#======================================

00321: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 516, 'const': 429, 'code+const': 945}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y0,y1,y2,y3,y4 = [float(z) for z in input('Y =').split()]
    Y = [y0,y1,y2,y3,y4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a ='))  
    b = float(input('b ='))  
    c = float(input('c ='))  
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    y0_hat = f(X[0], a, b, c)
    y1_hat = f(X[1], a, b, c)
    y2_hat = f(X[2], a, b, c)
    y3_hat = f(X[3], a, b, c)
    y4_hat = f(X[4], a, b, c)
    Y_hat = [y0_hat,y1_hat,y2_hat,y3_hat,y4_hat]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    y_hat = a*x**2+b*x+c
    return y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2+(Y[1]-Y_hat[1])**2+(Y[2]-Y_hat[2])**2+(Y[3]-Y_hat[3])**2+(Y[4]-Y_hat[4])**2
    return SSE
#======================================

00322: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 45.0, 45.0, 67.8125]
test_main0.0NameError("name 'Y_hat' is not defined")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 302, 'const': 405, 'code+const': 707}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.3
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    for i in range(0,4):
        Y_hat.append(f(X[i],a,b,c))
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  return (a*(x**2))+(b*x)+c
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  sum = 0
  for i in range(0,4):
        sum +=((Y[i]-Y_hat[i])**2)
  return sum
    # Y and Y_hat are lists of five floats
#======================================

00323: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 498, 'const': 433, 'code+const': 931}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    for i in range(0, len(Y)):
      Y[i] = float(Y[i])
    for i in range(0, len(Y_hat)):
      Y_hat[i] = float(Y_hat[i])
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X, a, b, c):
   # x, a, b and c are floats
    x = float(X)
    Y_hat = a*(x**2) + b*x + c 
    return  Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = ( (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2)
    return SSE
#======================================

00324: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 472, 'const': 433, 'code+const': 905}
import matplotlib.pyplot as plt
def plot(X, Y, g):
    plt.plot(X, Y, 'g+')
    plt.plot(X, g,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    new_list = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])]
    Y = new_list
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    g = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    Y_hat = g
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    func_of_Y=(a*(x**2))+(b*x)+c
    return func_of_Y
#======================================
def SSE(Y, g):
    # Y and Y_hat are lists of five floats
    sssum = ((Y[0]-g[0])**2)+((Y[1]-g[1])**2)+((Y[2]-g[2])**2)+((Y[3]-g[3])**2)+((Y[4]-g[4])**2)
    return sssum  
#======================================

00325: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 484, 'const': 433, 'code+const': 917}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    n0 = float(Y[0])
    n1 = float(Y[1])
    n2 = float(Y[2])
    n3 = float(Y[3])
    n4 = float(Y[4])
    Y = [n0, n1, n2, n3, n4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat= [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat_= a*(x**2)+b*x+c
    return Y_hat_
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    error_sum = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return error_sum
    # Y and Y_hat are lists of five floats
#======================================

00326: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
[9.75, 15.5, 27.75, 46.5, 71.75]
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 574, 'const': 433, 'code+const': 1007}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = 5*[0]
    Y_hat[0] = f(X[0],a,b,c)
    Y_hat[1] = f(X[1],a,b,c)
    Y_hat[2] = f(X[2],a,b,c)
    Y_hat[3] = f(X[3],a,b,c)
    Y_hat[4] = f(X[4],a,b,c)
    print(Y_hat)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Z = (float(Y_hat[0])-float(Y[0]))**2 + (float(Y_hat[1])-float(Y[1]))**2 + (float(Y_hat[2])-float(Y[2]))**2 +(float(Y_hat[3])-float(Y[3]))**2 + (float(Y_hat[4])-float(Y[4]))**2
    return Z
#======================================

00327: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[[0.0], [5.0], [5.0], [7.8125]]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = [75.6875]
[]
bytecount: {'code': 508, 'const': 433, 'code+const': 941}
import matplotlib.pyplot as plt
def plot(X, Y, k):
    plt.plot(X, Y, 'g+')
    plt.plot(X, k,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    a = float(a)
    b = float(b)
    c = float(c)
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    func_Y = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    Y_hat = func_Y
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    kkk = a*(x)**2+b*x+c
    return kkk
#======================================
def SSE(y, k):
    # Y and Y_hat are lists of five floats
    vvv =[((y[0]-k[0])**2)+((y[1]-k[1])**2)+((y[2]-k[2])**2)+((y[3]-k[3])**2)+((y[4])-k[4])**2]
    return vvv
#======================================

00328: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 528, 'const': 433, 'code+const': 961}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = list([Y[0], Y[1], Y[2], Y[3], Y[4]])
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c) ,f(X[1],a,b,c) ,f(X[2],a,b,c) ,f(X[3],a,b,c) ,f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2) + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return SSE
#======================================

00329: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 326, 'const': 383, 'code+const': 709}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = list(map(float,Y))
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = ')) # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in X :
      Y_hat.append(f(i,a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2+b*x+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sum_lost = 0.0
    for i in range(len(Y)) :
      sum_lost += pow( Y_hat[i]-Y[i],2 )
    return sum_lost    
#======================================

00330: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 488, 'const': 433, 'code+const': 921}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    Y2 = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    Y = Y2
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat = a*(x**2) + (b*x) + c
    return Y_hat 
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0]) - Y_hat[0])**2 + (float(Y[1]) - Y_hat[1])**2 + (float(Y[2]) - Y_hat[2])**2 + (float(Y[3]) - Y_hat[3])**2 + (float(Y[4]) - Y_hat[4])**2
    return SSE
#======================================

00331: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float (input('a = '))  # ลอง 12.8
    b = float (input('b = '))  # ลอง -40.2
    c = float (input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*(x**2) + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSD = (Y_hat[0]-Y[0])**2 + (Y_hat[1]-Y[1])**2 + (Y_hat[2]-Y[2])**2 +(Y_hat[3]-Y[3])**2 + (Y_hat[4]-Y[4])**2
    return SSD
#======================================

00332: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0]=float(Y[0])
    Y[1]=float(Y[1])
    Y[2]=float(Y[2])
    Y[3]=float(Y[3])
    Y[4]=float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = ') ) # ลอง -40.2
    c = float(input('c = ') ) # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
  y=a*x**2 + b*x + c
  return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 +(Y[2]-Y_hat[2])**2 +(Y[3]-Y_hat[3])**2 +(Y[4]-Y_hat[4])**2
  return sse
    # Y and Y_hat are lists of five floats
#======================================

00333: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE0.0
[0.0, 15.0, 15.0, 17.568125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 075.062875
[]
bytecount: {'code': 322, 'const': 367, 'code+const': 689}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for x in X :
      Y_hat.append(f(x,a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = float()
    for i in range(len(Y)):
      SSE = SSE + (float(Y[i])-Y_hat[i])**2
      return SSE
#======================================

00334: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 398, 'const': 419, 'code+const': 817}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main() :
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(5) :
      Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y = (a*x**2) + (b*x) + c
    return(Y)
#======================================
def SSE(Y, Y_hat) :
    # Y and Y_hat are lists of five floats
    i = 0
    SSE = 0
    while i < 5 :
      SSE += (Y[i] - Y_hat[i])**2
      i += 1
    return(SSE)
#======================================

00335: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0

Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 438, 'const': 433, 'code+const': 871}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()] # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat =[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    print()
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
#======================================

00336: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 524, 'const': 433, 'code+const': 957}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4]) ]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    Y_hat = a*(x**2)+b*x+c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (float(Y[0])-float(Y_hat[0]))**2 + (float(Y[1])-float(Y_hat[1]))**2 +            (float(Y[2])-float(Y_hat[2]))**2 + (float(Y[3])-float(Y_hat[3]))**2 +            (float(Y[4])-float(Y_hat[4]))**2
    return SSE
#======================================

00337: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
[9.75, 15.5, 27.75, 46.5, 71.75]
Sum of squared errors =  75.6875
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 394, 'const': 454, 'code+const': 848}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    print(Y_hat)
    print("Sum of squared errors = ", SSE(Y, Y_hat))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = (a*(x**2)) + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    result = 0
    for i in range(0, 5):
      error = (float(Y[i])-float(Y_hat[i]))**2
      result += error
    return result
#======================================

00338: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0NameError("name 'Y_hat' is not defined")
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 424, 'const': 421, 'code+const': 845}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    x = float(x)
    a = float(a)
    b = float(b)
    c = float(c)
    y = a*(x**2)+b*x+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y_hat[0] = float(Y_hat[0])
    Y_hat[1] = float(Y_hat[1])
    Y_hat[2] = float(Y_hat[2])
    Y_hat[3] = float(Y_hat[3])
    Y_hat[4] = float(Y_hat[4])
    det = ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
    return det
#======================================

00339: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 544, 'const': 433, 'code+const': 977}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [Y[0], Y[1], Y[2], Y[3], Y[4]]
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    Y_hat = a*x**2 + b*x +c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    sum1 = (Y[0] - Y_hat[0])**2
    sum2 = (Y[1] - Y_hat[1])**2
    sum3 = (Y[2] - Y_hat[2])**2
    sum4 = (Y[3] - Y_hat[3])**2
    sum5 = (Y[4] - Y_hat[4])**2
    SSE = sum1 + sum2 + sum3 + sum4 + sum5
    return SSE
#======================================

00340: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 468, 'const': 433, 'code+const': 901}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4])]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    f = a*x**2 + b*x + c
    Y_hat = f
    return Y_hat 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return SSE
#======================================

00341: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 490, 'const': 433, 'code+const': 923}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = ')) # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat = a*x**2 + b*x + c
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    SSE =  (Y[0]-Y_hat[0])**2 +  (Y[1]-Y_hat[1])**2 +  (Y[2]-Y_hat[2])**2 +  (Y[3]-Y_hat[3])**2 +  (Y[4]-Y_hat[4])**2 
    return SSE
#======================================

00342: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 572, 'const': 433, 'code+const': 1005}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y0=float(Y[0])
    Y1=float(Y[1])
    Y2=float(Y[2])
    Y3=float(Y[3])
    Y4=float(Y[4])
    Y=[Y0,Y1,Y2,Y3,Y4]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c),]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  a=float(a)
  b=float(b)
  c=float(c)
  return (a*(x**2))+(b*x)+c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y0=float(Y[0])
    Y1=float(Y[1])
    Y2=float(Y[2])
    Y3=float(Y[3])
    Y4=float(Y[4])
    Yh0=float(Y_hat[0])
    Yh1=float(Y_hat[1])
    Yh2=float(Y_hat[2])
    Yh3=float(Y_hat[3])
    Yh4=float(Y_hat[4])
    final=((Y0-Yh0)**2)+((Y1-Yh1)**2)+((Y2-Yh2)**2)+((Y3-Yh3)**2)+((Y4-Yh4)**2)
    return final
#======================================

00343: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 344, 'const': 379, 'code+const': 723}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in X :
      Y_hat.append(f(i,a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*(x**2)+(b*x)+c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    ans = 0
    for i in range(len(Y)):
      ans += (Y[i]-Y_hat[i])**2
    return ans
#======================================

00344: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f0.0TypeError("'float' object is not subscriptable")
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 734, 'const': 487, 'code+const': 1221}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    k = float(y[0])
    l = float(y[1])
    m = float(y[2])
    n = float(y[3])
    o = float(y[4])
    Y = [k, l, m, n, o]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    A = input('a = ')  # ลอง 12.8
    B = input('b = ')  # ลอง -40.2
    C = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    a=float(A)
    b=float(B)
    c=float(C)
    Y_hat=[a*(X[0]**2)+(b*X[0])+c, a*(X[1]**2)+(b*X[1])+c, a*(X[2]**2)+(b*X[2])+c, a*(X[3]**2)+(b*X[3])+c, a*(X[4]**2)+(b*X[4])+c]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    Y_hat=[a*(x[0]**2)+(b*x[0])+c, a*(x[1]**2)+(b*x[1])+c, a*(x[2]**2)+(b*x[2])+c, a*(x[3]**2)+(b*x[3])+c, a*(x[4]**2)+(b*x[4])+c]
    return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    S = ((float(Y_hat[0])-float(Y[0]))**2)+((float(Y_hat[1])-float(Y[1]))**2)+((float(Y_hat[2])-float(Y[2]))**2)+((float(Y_hat[3])-float(Y[3]))**2)+((float(Y_hat[4])-float(Y[4]))**2)
    return S
#======================================

00345: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0TypeError("unsupported operand type(s) for -: 'str' and 'str'")
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 314, 'const': 379, 'code+const': 693}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[]
    for i in range(len(X)):
      Y_hat.append(f(X[i],a,b,c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    y = a*(x**2) + b*x + c
    return y
    # x, a, b and c are floats
#======================================
def SSE(Y, Y_hat):
  x=0
  for i in range(len(Y)):
    x+=(Y[i]-Y_hat[i])**2
  return x
    # Y and Y_hat are lists of five floats
#======================================

00346: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 494, 'const': 433, 'code+const': 927}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0], Y[1], Y[2], Y[3], Y[4] = float(Y[0]), float(Y[1]), float(Y[2]), float(Y[3]), float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  y_hat_element = a*(x**2) + b*x + c
  return y_hat_element
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse_r = (Y[0] - Y_hat[0])**2 + (Y[1] - Y_hat[1])**2 + (Y[2] - Y_hat[2])**2 + (Y[3] - Y_hat[3])**2 + (Y[4] - Y_hat[4])**2 
    return sse_r
#======================================

00347: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 530, 'const': 433, 'code+const': 963}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c),f(X[2],a,b,c), f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
  x = float(x)
  a = float(a)
  b = float(b)
  c = float(c)
  Y_hat = a*(x**2) + b*x + c
  return Y_hat
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
  s0=(Y[0]-Y_hat[0])**2
  s1=(Y[1]-Y_hat[1])**2
  s2=(Y[2]-Y_hat[2])**2
  s3=(Y[3]-Y_hat[3])**2
  s4=(Y[4]-Y_hat[4])**2
  SSE = s0 + s1 + s2 +s3 +s4
  return SSE
#======================================

00348: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 452, 'const': 401, 'code+const': 853}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    fx = a*(x**2)+b*x+c
    return fx 
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    delta = sum(((Y[i]-Y_hat[i])**2) for i in range (5))
    return delta
#======================================

00349: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 426, 'const': 433, 'code+const': 859}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    Y_hat = [f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)] # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    y_hat = a*x**2+b*x+c
    return y_hat # x, a, b and c are floats
#======================================
def SSE(Y,Y_hat):
    return (float(Y[0])-Y_hat[0])**2+(float(Y[1])-Y_hat[1])**2+(float(Y[2])-Y_hat[2])**2+(float(Y[3])-Y_hat[3])**2+(float(Y[4])-Y_hat[4])**2
 # Y and Y_hat are lists of five floats
#======================================

00350: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
<function SSE at 0x0E9E2108>
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 460, 'const': 433, 'code+const': 893}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(x) for x in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[float(f(X[0],a,b,c)),float(f(X[1],a,b,c)),float(f(X[2],a,b,c)),float(f(X[3],a,b,c)),float(f(X[4],a,b,c))]
    print(SSE)
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return ((a*((x)**2))+(b*x)+c)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return ((Y[0]-Y_hat[0])**2)+((Y[1]-Y_hat[1])**2)+((Y[2]-Y_hat[2])**2)+((Y[3]-Y_hat[3])**2)+((Y[4]-Y_hat[4])**2)
#======================================

00351: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 522, 'const': 433, 'code+const': 955}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y[0] = float(Y[0])
    Y[1] = float(Y[1])
    Y[2] = float(Y[2])
    Y[3] = float(Y[3])
    Y[4] = float(Y[4])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0],a,b,c), f(X[1],a,b,c), f(X[2],a,b,c), f(X[3],a,b,c), f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
      x = float(x)
      a = float(a)
      b = float(b)
      c = float(c)
      return a*x**2 + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return ((float(Y[0])-Y_hat[0])**2 + (float(Y[1])-Y_hat[1])**2 + (float(Y[2])-Y_hat[2])**2 + (float(Y[3])-Y_hat[3])**2 + (float(Y[4])-Y_hat[4])**2 )
#======================================

00352: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 576, 'const': 433, 'code+const': 1009}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34   
    Y=[float(Y[0]),float(Y[1]),float(Y[2]),float(Y[3]),float(Y[4]),]
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [float(f(X[0],a,b,c)), float(f(X[1],a,b,c)),float(f(X[2],a,b,c)),float(f(X[3],a,b,c)),float(f(X[4],a,b,c))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(X,a,b,c):
    # x, a, b and c are floats
    A=float(a)
    B=float(b)
    C=float(c)
    x=float(X)
    return(A*x**2+B*x+C)
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    Y0 = float(Y[0])
    Y1 = float(Y[1])
    Y2 = float(Y[2])
    Y3 = float(Y[3])
    Y4 = float(Y[4])
    Y_hat0 = float(Y_hat[0])
    Y_hat1 = float(Y_hat[1])
    Y_hat2 = float(Y_hat[2])
    Y_hat3 = float(Y_hat[3])
    Y_hat4 = float(Y_hat[4])
    return(((Y0-Y_hat0)**2)+((Y1-Y_hat1)**2)+((Y2-Y_hat2)**2)+((Y3-Y_hat3)**2)+((Y4-Y_hat4)**2))
#======================================

00353: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main0.0
Y >> ['9.5', '14'.0, '25'.0, '42'.0, '65'.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 430, 'const': 433, 'code+const': 863}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = input('a = ')  # ลอง 12.8
    b = input('b = ')  # ลอง -40.2
    c = input('c = ')  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat=[f(X[0],a,b,c),f(X[1],a,b,c),f(X[2],a,b,c),f(X[3],a,b,c),f(X[4],a,b,c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =",SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
# x, a, b and c are floats
  y = float(a)*(x**2)+float(b)*(x)+float(c)
  return y
#======================================
def SSE(Y,Y_hat):
# Y and Y_hat are lists of five floats
  sse = ((float(Y[0])-Y_hat[0])**2)+((float(Y[1])-Y_hat[1])**2)+((float(Y[2])-Y_hat[2])**2)+((float(Y[3])-Y_hat[3])**2)+((float(Y[4])-Y_hat[4])**2)
  return sse
#======================================

00354: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 390, 'const': 431, 'code+const': 821}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
def main():
    X = [1,2,3,4,5]
    Y = input('Y = ').split(' ')  # ลอง 378.66 379.16 391.94 438.0 510.34
    i = 0
    while i != len(Y) :
        Y[i] = float(Y[i])
        i+=1
    a = float(input('a = ')) 
    b = float(input('b = '))
    c = float(input('c = '))
    Y_hat = []
    i = 0
    while i != len(X) :
        Y_hat.append(f(X[i],a,b,c))
        i += 1
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
def f(x, a, b, c):
    return a*(x**2) + b*x + c
def SSE(Y, Y_hat):
    a = 0
    i = 0
    while i != len(Y) :
        a += float((Y_hat[i] - Y[i])**2)
        i += 1
    return a

00355: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 348, 'const': 407, 'code+const': 755}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main() :
    X = [1, 2, 3, 4, 5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(e) for e in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = []
    for i in range(0, 5) :
        Y_hat.append(f(X[i], a, b, c))
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c) : 
    # x, a, b and c are floats
    return a * x * x + b * x + c
#======================================
def SSE(Y, Y_hat) :
    # Y and Y_hat are lists of five floats
    sse = 0.0
    for i in range(0, 5) :
        sse += (Y[i] - Y_hat[i]) ** 2
    return sse
#======================================

00356: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 370, 'const': 389, 'code+const': 759}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = [float(x) for x in input('Y = ').split()]  # ลอง 378.66 379.16 391.94 438.0 510.34
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[i], a, b, c) for i in range(5)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a * x ** 2 + b * x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return sum((Y[i] - Y_hat[i]) ** 2 for i in range(5))
#======================================

00357: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 382, 'const': 375, 'code+const': 757}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    Y = [float(x) for x in Y]  # 378.66, 372.16, 391.94, 438.0, 510.34?
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = ')) # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5 => 400.05?
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[i], a, b, c) for i in range(len(X))]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    return a*(x**2) + b*x + c
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    return sum((Y[i]-Y_hat[i])**2 for i in range(len(Y)))
#======================================

00358: HW1
testfuncscerrstu_stdoutstu_keptstu_fout
test_f1.0
[10.0, 21.25, 87.0625]
test_SSE1.0
[0.0, 5.0, 5.0, 7.8125]
test_main1.0
Y >> [9.5, 14.0, 25.0, 42.0, 65.0]
Sum of squared errors = 75.6875
[]
bytecount: {'code': 448, 'const': 433, 'code+const': 881}
import matplotlib.pyplot as plt
def plot(X, Y, Y_hat):
    plt.plot(X, Y, 'g+')
    plt.plot(X, Y_hat,'r')
    plt.show()
#======================================
def main():
    X = [1,2,3,4,5]
    # รับค่าของ y ที่เป็นจำนวนจริงจากแป้นพิมพ์ ห้าจำนวน แต่ละจำนวนคั่นด้วยช่องว่าง
    # เก็บใส่ตัวแปร Y ที่เป็นลิสต์ห้าช่อง
    Y = input('Y = ').split()  # ลอง 378.66 379.16 391.94 438.0 510.34
    for i in range(len(Y)):
        Y[i] = float(Y[i])
    # รับค่าของ a, b, c ที่เป็นจำนวนจริงจากแป้นพิมพ์ สามจำนวน
    a = float(input('a = '))  # ลอง 12.8
    b = float(input('b = '))  # ลอง -40.2
    c = float(input('c = '))  # ลอง 400.5
    # สร้างลิสต์ Y_hat ที่มี 5 ช่อง เก็บค่าของ f(X[0],a,b,c), f(X[1],a,b,c), ..., f(X[4],a,b,c)
    Y_hat = [f(X[0], a, b, c), f(X[1], a, b, c), f(X[2], a, b, c), f(X[3], a, b, c), f(X[4], a, b, c)]
    # ไม่ต้องแก้ไขสองคำสั่งข้างล่างนี้
    plot(X, Y, Y_hat)
    print("Sum of squared errors =", SSE(Y, Y_hat))
#======================================
def f(x, a, b, c):
    # x, a, b and c are floats
    y = a*x**2 + b*x + c
    return y
#======================================
def SSE(Y, Y_hat):
    # Y and Y_hat are lists of five floats
    sse = (Y[0]-Y_hat[0])**2 + (Y[1]-Y_hat[1])**2 + (Y[2]-Y_hat[2])**2 + (Y[3]-Y_hat[3])**2 + (Y[4]-Y_hat[4])**2
    return sse
#======================================