In [1]:
import numpy as np
import pandas as pd
pd = pd.read_csv("./pokemon.csv")
newcp = np.array(pd['cp_new'])
cp = np.array(pd['cp'])
cp = cp[:50]
newcp = newcp[:50]
import matplotlib.pyplot as plt
# plt.plot(newcp,cp)
plt.scatter(cp, newcp)
# plt.ylabel('some numbers')
plt.show()
In [4]:
w = 1
b = 1
n = len(cp)
r= 0.000001
for i in range(100000):
dw = 0
db = 0
error = 0
for x , y in zip(cp,newcp):
# 加上 2*w 是考量到 Regularization
dw = -2*x*(y- (w*x+b)) + 2*w
db = -2*(y- (w*x+b))
# print dw,db
y_head = w*x + b
w = w - dw*r
b = b - db*r
error +=(y_head-y)*(y_head-y)
if i % 10000 ==0 :
print("w={:0.3f}, b={:0.3f}, error={:0.3f} ".format(w,b,error/n))
In [8]:
y_head = []
for x in cp :
predict = w*x +b
y_head.append(predict)
plt.scatter(y_head, newcp)
plt.show()
In [ ]: