Skip to content

Commit 8a842d5

Browse files
committed
add ch1.py
1 parent 5091dec commit 8a842d5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

ch1.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from matplotlib import pyplot as plt
2+
#%matplotlib inline
3+
variance = [1,2,4,8,16,32,64,128,256]
4+
bias_squared=[256,128,64,32,16,8,4,2,1]
5+
total_error=[x+y for x,y in zip(variance,bias_squared)]
6+
xs = [i for i,_ in enumerate(variance)]
7+
plt.plot(xs,variance,'g-',label='variance')
8+
plt.plot(xs,bias_squared,'r-',label='bias^2')
9+
plt.plot(xs,total_error,'b:',label='total_error')
10+
plt.title('bias variance')
11+
plt.legend(loc=9)
12+
plt.show()

0 commit comments

Comments
 (0)