{"id":1320,"date":"2023-03-25T10:12:45","date_gmt":"2023-03-25T02:12:45","guid":{"rendered":""},"modified":"2023-03-25T10:12:45","modified_gmt":"2023-03-25T02:12:45","slug":"\u795e\u7ecf\u7f51\u7edc","status":"publish","type":"post","link":"https:\/\/bianchenghao6.com\/1320.html","title":{"rendered":"\u795e\u7ecf\u7f51\u7edc"},"content":{"rendered":"


\n <\/head>
\n <\/p>\n

\n

\u795e\u7ecf\u7f51\u7edc<\/h1>\n

\u795e\u7ecf\u7f51\u7edc\u8be6\u7ec6\u64cd\u4f5c\u6559\u7a0b<\/span>\n <\/div>\n

\n \u795e\u7ecf\u7f51\u7edc\u662f\u5e76\u884c\u8ba1\u7b97\u8bbe\u5907\uff0c\u5b83\u4eec\u8bd5\u56fe\u6784\u5efa\u5927\u8111\u7684\u8ba1\u7b97\u673a\u6a21\u578b\u3002 \u80cc\u540e\u7684\u4e3b\u8981\u76ee\u6807\u662f\u5f00\u53d1\u4e00\u4e2a\u7cfb\u7edf\u6765\u6267\u884c\u5404\u79cd\u8ba1\u7b97\u4efb\u52a1\u6bd4\u4f20\u7edf\u7cfb\u7edf\u66f4\u5feb\u3002 \u8fd9\u4e9b\u4efb\u52a1\u5305\u62ec\u6a21\u5f0f\u8bc6\u522b\u548c\u5206\u7c7b\uff0c\u8fd1\u4f3c\uff0c\u4f18\u5316\u548c\u6570\u636e\u805a\u7c7b\u3002\n <\/div>\n

\u4ec0\u4e48\u662f\u4eba\u5de5\u795e\u7ecf\u7f51\u7edc(ANN)<\/h2>\n
\n \u4eba\u5de5\u795e\u7ecf\u7f51\u7edc(ANN)\u662f\u4e00\u4e2a\u9ad8\u6548\u7684\u8ba1\u7b97\u7cfb\u7edf\uff0c\u5176\u6838\u5fc3\u4e3b\u9898\u662f\u501f\u7528\u751f\u7269\u795e\u7ecf\u7f51\u7edc\u7684\u7c7b\u6bd4\u3002\u4eba\u5de5\u795e\u7ecf\u7f51\u7edc\u4e5f\u88ab\u79f0\u4e3a\u4eba\u5de5\u795e\u7ecf\u7cfb\u7edf\uff0c\u5e76\u884c\u5206\u5e03\u5f0f\u5904\u7406\u7cfb\u7edf\u548c\u8fde\u63a5\u7cfb\u7edf\u3002 ANN\u83b7\u53d6\u4e86\u5927\u91cf\u4ee5\u67d0\u79cd\u6a21\u5f0f\u76f8\u4e92\u8fde\u63a5\u7684\u5355\u5143\uff0c\u4ee5\u5141\u8bb8\u5b83\u4eec\u4e4b\u95f4\u7684\u901a\u4fe1\u3002\u8fd9\u4e9b\u5355\u5143\u4e5f\u79f0\u4e3a\u8282\u70b9\u6216\u795e\u7ecf\u5143\uff0c\u662f\u5e76\u884c\u64cd\u4f5c\u7684\u7b80\u5355\u5904\u7406\u5668\u3002\n <\/div>\n
\n \u6bcf\u4e2a\u795e\u7ecf\u5143\u901a\u8fc7\u8fde\u63a5\u94fe\u63a5\u4e0e\u5176\u4ed6\u795e\u7ecf\u5143\u8fde\u63a5\u3002\u6bcf\u4e2a\u8fde\u63a5\u94fe\u8def\u4e0e\u5177\u6709\u5173\u4e8e\u8f93\u5165\u4fe1\u53f7\u7684\u4fe1\u606f\u7684\u6743\u91cd\u76f8\u5173\u8054\u3002\u8fd9\u662f\u795e\u7ecf\u5143\u89e3\u51b3\u7279\u5b9a\u95ee\u9898\u6700\u6709\u7528\u7684\u4fe1\u606f\uff0c\u56e0\u4e3a\u4f53\u91cd\u901a\u5e38\u4f1a\u6fc0\u53d1\u6216\u6291\u5236\u6b63\u5728\u4f20\u9012\u7684\u4fe1\u53f7\u3002\u6bcf\u4e2a\u795e\u7ecf\u5143\u90fd\u6709\u5176\u5185\u90e8\u72b6\u6001\uff0c\u79f0\u4e3a\u6fc0\u6d3b\u4fe1\u53f7\u3002\u5728\u7ec4\u5408\u8f93\u5165\u4fe1\u53f7\u548c\u6fc0\u6d3b\u89c4\u5219\u4e4b\u540e\u4ea7\u751f\u7684\u8f93\u51fa\u4fe1\u53f7\u53ef\u4ee5\u88ab\u53d1\u9001\u5230\u5176\u4ed6\u5355\u5143\u3002\n <\/div>\n

\u5b89\u88c5\u6709\u7528\u7684\u5305<\/h2>\n
\n \u5728Python\u4e2d\u521b\u5efa\u795e\u7ecf\u7f51\u7edc\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u5f3a\u5927\u7684NeuroLab\u795e\u7ecf\u7f51\u7edc\u5305\u3002\u5b83\u662f\u4e00\u4e2a\u57fa\u672c\u7684\u795e\u7ecf\u7f51\u7edc\u7b97\u6cd5\u5e93\uff0c\u5177\u6709\u7075\u6d3b\u7684\u7f51\u7edc\u914d\u7f6e\u548cPython\u5b66\u4e60\u7b97\u6cd5\u3002\u53ef\u4ee5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e0b\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u6b64\u8f6f\u4ef6\u5305 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
pip install NeuroLab
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u5982\u679c\u4f7f\u7528\u7684\u662fAnaconda\u73af\u5883\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5NeuroLab -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
conda install -c labfabulous neurolab
<\/span><\/code><\/pre>\n<\/p><\/div>\n

\u6784\u5efa\u795e\u7ecf\u7f51\u7edc<\/h2>\n
\n \u5728\u672c\u8282\u4e2d\uff0c\u8ba9\u6211\u4eec\u4f7f\u7528NeuroLab\u8f6f\u4ef6\u5305\u5728Python\u4e2d\u6784\u5efa\u4e00\u4e9b\u795e\u7ecf\u7f51\u7edc\u3002\n <\/div>\n

\u57fa\u4e8e\u611f\u77e5\u5668\u7684\u5206\u7c7b\u5668<\/h2>\n
\n \u4ee5\u4e0b\u662f\u9010\u6b65\u6267\u884cPython\u4ee3\u7801\uff0c\u7528\u4e8e\u6784\u5efa\u57fa\u4e8e\u611f\u77e5\u5668\u7684\u7b80\u5355\u795e\u7ecf\u7f51\u7edc\u5206\u7c7b\u5668 -\n <\/div>\n
\n \u5982\u4e0b\u6240\u793a\u5bfc\u5165\u5fc5\u8981\u7684\u8f6f\u4ef6\u5305 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
import <\/span>matplotlib.pyplot as <\/span>plt
import <\/span>neurolab as <\/span>nl
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8bf7\u6ce8\u610f\uff0c\u8fd9\u662f\u4e00\u4e2a\u76d1\u7763\u5b66\u4e60\u7684\u4f8b\u5b50\uff0c\u56e0\u6b64\u60a8\u4e5f\u5fc5\u987b\u63d0\u4f9b\u76ee\u6807\u503c\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
input = [[0, 0], [0, 1], [1, 0], [1, 1]]
target = [[0], [0], [0], [1]]
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u75282\u4e2a\u8f93\u5165\u548c1\u4e2a\u795e\u7ecf\u5143\u521b\u5efa\u7f51\u7edc -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
net = nl.net.newp<\/span>([[0, 1],[0, 1]], 1)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u8bad\u7ec3\u7f51\u7edc\u3002 \u5728\u8fd9\u91cc\u4f7f\u7528Delta\u89c4\u5219\u8fdb\u884c\u8bad\u7ec3\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
error_progress = net.train<\/span>(input, target, epochs=100, show=10, lr=0.1)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u63a5\u4e0b\u6765\uff0c\u53ef\u89c6\u5316\u8f93\u51fa\u5e76\u7ed8\u5236\u56fe\u8868 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
plt.figure<\/span>()
plt.plot<\/span>(error_progress)
plt.xlabel<\/span>('Number of epochs'<\/span>)
plt.ylabel<\/span>('Training error'<\/span>)
plt.grid<\/span>()
plt.show<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u53ef\u4ee5\u770b\u5230\u4e0b\u56fe\u663e\u793a\u4e86\u4f7f\u7528\u9519\u8bef\u5ea6\u91cf\u6807\u51c6\u7684\u8bad\u7ec3\u8fdb\u5ea6 -\n <\/div>\n
\n \u795e\u7ecf\u7f51\u7edc_https:\/\/bianchenghao6.com_\u3010\u4eba\u5de5\u667a\u80fd\u6559\u7a0b\u3011_\u7b2c1\u5f20\n <\/div>\n

\u5355\u5c42\u795e\u7ecf\u7f51\u7edc<\/h2>\n
\n \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6765\u521b\u5efa\u4e00\u4e2a\u5355\u5c42\u795e\u7ecf\u7f51\u7edc\uff0c\u5b83\u7531\u72ec\u7acb\u7684\u795e\u7ecf\u5143\u7ec4\u6210\uff0c\u8fd9\u4e9b\u795e\u7ecf\u5143\u5728\u8f93\u5165\u6570\u636e\u4e0a\u8d77\u4f5c\u7528\u4ee5\u4ea7\u751f\u8f93\u51fa\u3002 \u8bf7\u6ce8\u610f\uff0c\u8fd9\u91cc\u4f7f\u7528neural_simple.txt\u6587\u4ef6\u4f5c\u4e3a\u8f93\u5165\u3002\n <\/div>\n
\n \u5982\u4e0b\u6240\u793a\u5bfc\u5165\u6240\u9700\u7684\u8f6f\u4ef6\u5305 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
import <\/span>numpy as <\/span>np
import <\/span>matplotlib.pyplot as <\/span>plt
import <\/span>neurolab as <\/span>nl
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u52a0\u8f7d\u6570\u636e\u96c6\u5982\u4e0b\u4ee3\u7801 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
input_data = np.loadtxt<\/span>(\u201c\/Users\/admin\/neural_simple.txt')
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u4ee5\u4e0b\u662f\u6211\u4eec\u8981\u4f7f\u7528\u7684\u6570\u636e\u3002 \u8bf7\u6ce8\u610f\uff0c\u5728\u6b64\u6570\u636e\u4e2d\uff0c\u524d\u4e24\u5217\u662f\u7279\u5f81\uff0c\u6700\u540e\u4e24\u5217\u662f\u6807\u7b7e\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
array([[2. , 4. , 0. , 0. ],
      [1.5, 3.9, 0. , 0. ],
      [2.2, 4.1, 0. , 0. ],
      [1.9, 4.7, 0. , 0. ],
      [5.4, 2.2, 0. , 1. ],
      [4.3, 7.1, 0. , 1. ],
      [5.8, 4.9, 0. , 1. ],
      [6.5, 3.2, 0. , 1. ],
      [3. , 2. , 1. , 0. ],
      [2.5, 0.5, 1. , 0. ],
      [3.5, 2.1, 1. , 0. ],
      [2.9, 0.3, 1. , 0. ],
      [6.5, 8.3, 1. , 1. ],
      [3.2, 6.2, 1. , 1. ],
      [4.9, 7.8, 1. , 1. ],
      [2.1, 4.8, 1. , 1. ]])
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u5c06\u8fd9\u56db\u5217\u5206\u62102\u4e2a\u6570\u636e\u5217\u548c2\u4e2a\u6807\u7b7e -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
data = input_data[:, 0:2]
labels = input_data[:, 2:]
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u7ed8\u5236\u8f93\u5165\u6570\u636e -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
plt.figure<\/span>()
plt.scatter<\/span>(data[:,0], data[:,1])
plt.xlabel<\/span>('Dimension 1'<\/span>)
plt.ylabel<\/span>('Dimension 2'<\/span>)
plt.title<\/span>('Input data'<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u4e3a\u6bcf\u4e2a\u7ef4\u5ea6\u5b9a\u4e49\u6700\u5c0f\u503c\u548c\u6700\u5927\u503c\uff0c\u5982\u4e0b\u6240\u793a -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
dim1_min, dim1_max = data[:,0].min<\/span>(), data[:,0].max<\/span>()
dim2_min, dim2_max = data[:,1].min<\/span>(), data[:,1].max<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u63a5\u4e0b\u6765\uff0c\u5982\u4e0b\u5b9a\u4e49\u8f93\u51fa\u5c42\u4e2d\u795e\u7ecf\u5143\u7684\u6570\u91cf -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
nn_output_layer = labels.shape[1]
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u5b9a\u4e49\u4e00\u4e2a\u5355\u5c42\u795e\u7ecf\u7f51\u7edc -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
dim1 = [dim1_min, dim1_max]
dim2 = [dim2_min, dim2_max]
neural_net = nl.net.newp<\/span>([dim1, dim2], nn_output_layer)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8bad\u7ec3\u795e\u7ecf\u7f51\u7edc\u7684\u65f6\u4ee3\u6570\u548c\u5b66\u4e60\u7387\u5982\u4e0b\u6240\u793a -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
error <\/span>= neural_net.train<\/span>(data, labels, epochs = 200, show = 20, lr = 0.01)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u53ef\u89c6\u5316\u5e76\u7ed8\u5236\u8bad\u7ec3\u8fdb\u5ea6 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
plt.figure<\/span>()
plt.plot<\/span>(error)
plt.xlabel<\/span>('Number of epochs'<\/span>)
plt.ylabel<\/span>('Training error'<\/span>)
plt.title<\/span>('Training error <\/span>progress'<\/span>)
plt.grid<\/span>()
plt.show<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u4f7f\u7528\u4e0a\u8ff0\u5206\u7c7b\u5668\u4e2d\u7684\u6d4b\u8bd5\u6570\u636e\u70b9 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
print('\\nTest Results:'<\/span>)
data_test = [[1.5, 3.2], [3.6, 1.7], [3.6, 5.7],[1.6, 3.9]] for <\/span><\/span>item in <\/span>data_test:
   print(item, '-->'<\/span>, neural_net.sim<\/span>([item])[0])
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u4e0b\u9762\u662f\u6d4b\u8bd5\u7ed3\u679c -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
[1.5, 3.2] --> [1. 0.]
[3.6, 1.7] --> [1. 0.]
[3.6, 5.7] --> [1. 1.]
[1.6, 3.9] --> [1. 0.]
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u60a8\u53ef\u4ee5\u770b\u5230\u8fc4\u4eca\u4e3a\u6b62\u8ba8\u8bba\u7684\u4ee3\u7801\u7684\u8f93\u51fa\u56fe\u8868 -\n <\/div>\n
\n \u795e\u7ecf\u7f51\u7edc_https:\/\/bianchenghao6.com_\u3010\u4eba\u5de5\u667a\u80fd\u6559\u7a0b\u3011_\u7b2c2\u5f20\n <\/div>\n
\n \u795e\u7ecf\u7f51\u7edc_https:\/\/bianchenghao6.com_\u3010\u4eba\u5de5\u667a\u80fd\u6559\u7a0b\u3011_\u7b2c3\u5f20\n <\/div>\n

\u591a\u5c42\u795e\u7ecf\u7f51\u7edc<\/h2>\n
\n \u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u7531\u591a\u4e2a\u5c42\u7ec4\u6210\u7684\u591a\u5c42\u795e\u7ecf\u7f51\u7edc\uff0c\u4ee5\u63d0\u53d6\u8bad\u7ec3\u6570\u636e\u4e2d\u7684\u57fa\u7840\u6a21\u5f0f\u3002 \u8fd9\u4e2a\u591a\u5c42\u795e\u7ecf\u7f51\u7edc\u5c06\u50cf\u4e00\u4e2a\u56de\u5f52\u5668\u4e00\u6837\u5de5\u4f5c\u3002 \u6211\u4eec\u5c06\u6839\u636e\u4e0b\u9762\u7b49\u5f0f\u751f\u6210\u4e00\u4e9b\u6570\u636e\u70b9:y = 2x2 + 8\u3002\n <\/div>\n
\n \u5982\u4e0b\u6240\u793a\u5bfc\u5165\u5fc5\u8981\u7684\u8f6f\u4ef6\u5305 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
import <\/span>numpy as <\/span>np
import <\/span>matplotlib.pyplot as <\/span>plt
import <\/span>neurolab as <\/span>nl
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6839\u636e\u4e0a\u8ff0\u516c\u5f0f\u751f\u6210\u4e00\u4e9b\u6570\u636e\u70b9 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
min_val = -30
max_val = 30
num_points = 160
x = np.linspace<\/span>(min_val, max_val, num_points)
y = 2 * np.square<\/span>(x) + 8
y \/= np.linalg.norm<\/span>(y)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u91cd\u5851\u8fd9\u4e2a\u6570\u636e\u96c6\u5982\u4e0b -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
data = x.reshape<\/span>(num_points, 1)
labels = y.reshape<\/span>(num_points, 1)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u53ef\u89c6\u5316\u5e76\u7ed8\u5236\u8f93\u5165\u6570\u636e\u96c6 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
plt.figure<\/span>()
plt.scatter<\/span>(data, labels)
plt.xlabel<\/span>('Dimension 1'<\/span>)
plt.ylabel<\/span>('Dimension 2'<\/span>)
plt.title<\/span>('Data-points'<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\uff0c\u6784\u5efa\u795e\u7ecf\u7f51\u7edc\uff0c\u5176\u5177\u6709\u4e24\u4e2a\u9690\u85cf\u5c42\uff0c\u7b2c\u4e00\u9690\u85cf\u5c42\u4e2d\u5177\u6709\u5341\u4e2a\u795e\u7ecf\u5143\u7684\u795e\u7ecf\u5143\uff0c\u7b2c\u4e8c\u9690\u85cf\u5c42\u4e2d\u516d\u4e2a\uff0c\u8f93\u51fa\u5c42\u4e2d\u4e00\u4e2a\u795e\u7ecf\u5143\u3002\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
neural_net = nl.net.newff<\/span>([[min_val, max_val]], [10, 6, 1])
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\u4f7f\u7528\u68af\u5ea6\u8bad\u7ec3\u7b97\u6cd5 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
neural_net.trainf = nl.train.train_gd
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\u8bad\u7ec3\u7f51\u7edc\u7684\u76ee\u6807\u662f\u5b66\u4e60\u4e0a\u9762\u751f\u6210\u7684\u6570\u636e -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
error <\/span>= neural_net.train<\/span>(data, labels, epochs = 1000, show = 100, goal = 0.01)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u8bad\u7ec3\u6570\u636e\u70b9\u4e0a\u8fd0\u884c\u795e\u7ecf\u7f51\u7edc -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
output = neural_net.sim<\/span>(data)
y_pred = output.reshape<\/span>(num_points)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\u7ed8\u56fe\u5e76\u53ef\u89c6\u5316\u4efb\u52a1 -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
plt.figure<\/span>()
plt.plot<\/span>(error)
plt.xlabel<\/span>('Number of epochs'<\/span>)
plt.ylabel<\/span>('Error'<\/span>)
plt.title<\/span>('Training error <\/span>progress'<\/span>)
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u73b0\u5728\u5c06\u7ed8\u5236\u5b9e\u9645\u4e0e\u9884\u6d4b\u8f93\u51fa\u5173\u7cfb\u56fe -\n <\/div>\n
\n
 # Filename : example.py<\/span>
# Copyright : 2020 By Lidihuo<\/span>
# Author by : www.lidihuo.com<\/span>
# Date : 2020-08-26<\/span>
x_dense = np.linspace<\/span>(min_val, max_val, num_points * 2)
y_dense_pred = neural_net.sim<\/span>(x_dense.reshape<\/span>(x_dense.size,1)).reshape<\/span>(x_dense.size)
plt.figure<\/span>()
plt.plot<\/span>(x_dense, y_dense_pred, '-'<\/span>, x, y, '.'<\/span>, x, y_pred, 'p'<\/span>)
plt.title<\/span>('Actual vs predicted'<\/span>)
plt.show<\/span>()
<\/span><\/code><\/pre>\n<\/p><\/div>\n
\n \u6267\u884c\u4e0a\u8ff0\u4ee3\u7801\uff0c\u60a8\u53ef\u4ee5\u89c2\u5bdf\u5982\u4e0b\u6240\u793a\u7684\u56fe\u5f62 -\n <\/div>\n
\n \u795e\u7ecf\u7f51\u7edc_https:\/\/bianchenghao6.com_\u3010\u4eba\u5de5\u667a\u80fd\u6559\u7a0b\u3011_\u7b2c4\u5f20\n <\/div>\n
\n \u795e\u7ecf\u7f51\u7edc_https:\/\/bianchenghao6.com_\u3010\u4eba\u5de5\u667a\u80fd\u6559\u7a0b\u3011_\u7b2c5\u5f20\n <\/div>\n
\n \u795e\u7ecf\u7f51\u7edc_https:\/\/bianchenghao6.com_\u3010\u4eba\u5de5\u667a\u80fd\u6559\u7a0b\u3011_\u7b2c6\u5f20\n <\/div>\n

<\/body>
\n<\/html><\/p>\n","protected":false},"excerpt":{"rendered":"\u795e\u7ecf\u7f51\u7edczh-cn","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[137],"tags":[],"class_list":["post-1320","post","type-post","status-publish","format-standard","hentry","category-rgznjc1"],"_links":{"self":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1320"}],"collection":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/comments?post=1320"}],"version-history":[{"count":0,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/posts\/1320\/revisions"}],"wp:attachment":[{"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/media?parent=1320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/categories?post=1320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bianchenghao6.com\/wp-json\/wp\/v2\/tags?post=1320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}