#!/usr/bin/env python # coding: utf-8 # # SYA-KE Deep Learning Training # OReilyBook # ## Parent Repository URL # [https://github.com/oreilly-japan/deep-learning-from-scratch](https://github.com/oreilly-japan/deep-learning-from-scratch) # ## Pythonに慣れる # In[1]: get_ipython().system('python --version') # In[2]: #もう何年もやってるので省略 # ## Numpyに慣れる # ### 参考URL # [http://www.sist.ac.jp/~kanakubo/research/hosoku/gyoretu.html](http://www.sist.ac.jp/~kanakubo/research/hosoku/gyoretu.html) # ### 配列、行列 # In[3]: import numpy as np # In[4]: np.__version__ # In[5]: x = np.array([1.0,2.0,3.0]) # In[6]: y = np.array([2.0,4.0,6.0]) # In[7]: x + y # In[8]: x - y # In[9]: x * y # In[10]: x / y # In[11]: x / 2.0 # In[12]: A = np.array([[1,2],[3,4]]) # In[13]: print(A) # In[14]: A.shape # In[15]: A.dtype # In[16]: B = np.array([[3,0],[0,6]]) # In[17]: A + B # In[18]: A * B # In[19]: A*10 # [参考](http://www.scipy-lectures.org/intro/numpy/operations.html) # In[20]: X = np.array([[51,55],[14,19],[0,4]]) X # In[21]: X[0] #0行目 # In[22]: X[0][1] #(0,1) =>(0行1列) # In[23]: for row in X: print(row) # In[24]: AX = X.flatten() #行列を配列に AX # In[25]: AX[AX>15]#配列から条件の値を抽出 # In[26]: X>15 # In[27]: X[X>15]#行列でもできる。 # ニューラルネットワークにおいては行列は 行数=入力数 列数=重み数 # ## Matplotlibに慣れる # [参考URL](http://qiita.com/hik0107/items/de5785f680096df93efa) # In[28]: get_ipython().run_line_magic('matplotlib', 'inline') import matplotlib.pyplot as plt import numpy as np x = np.arange(0,6,0.1) #0to6 by 0.1 => sin(0to6) y = np.sin(x) plt.plot(x,y) plt.show() plt.close() # In[29]: get_ipython().run_line_magic('matplotlib', 'inline') import matplotlib.pyplot as plt import numpy as np x = np.arange(0,6,0.1) #0to6 by 0.1 => sin(0to6) y1 = np.sin(x) y2 = np.cos(x) plt.plot(x,y1,label="sin(x)") plt.plot(x,y2,label="cos(x)", linestyle="--") plt.xlabel("x") plt.ylabel("y") plt.title("sin(x), cos(x)") plt.legend()#show label box plt.show() plt.close() # In[30]: get_ipython().run_line_magic('matplotlib', 'inline') #plt.show()をinlineにて表示する #Esc+Lで行番号を表示する import matplotlib.pyplot as plt import numpy as np x = np.arange(0,6,0.1) #0to6 by 0.1 => sin(0to6) y1 = np.sin(x) y2 = np.cos(x) plt.plot(x,y1,label="sin(x)") plt.plot(x,y2,label="cos(x)", linestyle="--") plt.axhline(color='black',linestyle="--") plt.xlabel("x") plt.ylabel("y") plt.title("sin(x), cos(x), y=0") plt.legend()#show label box plt.show() plt.close() # # パーセプトロンに慣れる # In[31]: from graphviz import Digraph dot = Digraph(comment="単純パーセプトロン") dot.attr(rankdir="LR") dot.attr(splines="line") dot.attr(fixedsize="true") with dot.subgraph(name="cluster_x") as x: x.attr(label="入力層") x.attr(color="white") x.node("x1","x1:入力1") x.node("x2","x2:入力2") with dot.subgraph(name="cluster_y") as y: y.attr(label="出力層") y.attr(color="white") y.node("y","y:出力1") dot.edge("x1", "y", label="w1:重み1") dot.edge("x2", "y", label="w2:重み2") #print(dot) dot # In[ ]: # In[ ]: # In[ ]: # In[ ]: # In[ ]: # In[ ]: