|
|
|
@@ -52,7 +52,7 @@ |
|
|
|
}, |
|
|
|
{ |
|
|
|
"cell_type": "code", |
|
|
|
"execution_count": 1, |
|
|
|
"execution_count": 2, |
|
|
|
"metadata": {}, |
|
|
|
"outputs": [ |
|
|
|
{ |
|
|
|
@@ -80,6 +80,7 @@ |
|
|
|
"y=1/(1+np.e**(-X))\n", |
|
|
|
"plt.plot(X,y,'b-')\n", |
|
|
|
"plt.title(\"Logistic function\")\n", |
|
|
|
"plt.savefig(\"logstic_fuction.pdf\")\n", |
|
|
|
"plt.show()" |
|
|
|
] |
|
|
|
}, |
|
|
|
@@ -179,7 +180,7 @@ |
|
|
|
}, |
|
|
|
{ |
|
|
|
"cell_type": "code", |
|
|
|
"execution_count": 2, |
|
|
|
"execution_count": 5, |
|
|
|
"metadata": {}, |
|
|
|
"outputs": [], |
|
|
|
"source": [ |
|
|
|
@@ -195,7 +196,7 @@ |
|
|
|
}, |
|
|
|
{ |
|
|
|
"cell_type": "code", |
|
|
|
"execution_count": 3, |
|
|
|
"execution_count": 6, |
|
|
|
"metadata": {}, |
|
|
|
"outputs": [ |
|
|
|
{ |
|
|
|
@@ -204,7 +205,7 @@ |
|
|
|
"Text(0.5, 1.0, 'Original Data')" |
|
|
|
] |
|
|
|
}, |
|
|
|
"execution_count": 3, |
|
|
|
"execution_count": 6, |
|
|
|
"metadata": {}, |
|
|
|
"output_type": "execute_result" |
|
|
|
}, |
|
|
|
@@ -226,16 +227,17 @@ |
|
|
|
"data, label = sklearn.datasets.make_moons(200, noise=0.30)\n", |
|
|
|
"\n", |
|
|
|
"plt.scatter(data[:,0], data[:,1], c=label)\n", |
|
|
|
"plt.savefig(\"logistic_train_data.pdf\")\n", |
|
|
|
"plt.title(\"Original Data\")" |
|
|
|
] |
|
|
|
}, |
|
|
|
{ |
|
|
|
"cell_type": "code", |
|
|
|
"execution_count": 4, |
|
|
|
"execution_count": 7, |
|
|
|
"metadata": {}, |
|
|
|
"outputs": [], |
|
|
|
"source": [ |
|
|
|
"def plot_decision_boundary(predict_func, data, label):\n", |
|
|
|
"def plot_decision_boundary(predict_func, data, label, figName=None):\n", |
|
|
|
" \"\"\"画出结果图\n", |
|
|
|
" Args:\n", |
|
|
|
" pred_func (callable): 预测函数\n", |
|
|
|
@@ -253,13 +255,14 @@ |
|
|
|
"\n", |
|
|
|
" plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral) #画出登高线并填充\n", |
|
|
|
" plt.scatter(data[:, 0], data[:, 1], c=label, cmap=plt.cm.Spectral)\n", |
|
|
|
" if figName != None: plt.savefig(figName)\n", |
|
|
|
" plt.show()\n", |
|
|
|
"\n" |
|
|
|
] |
|
|
|
}, |
|
|
|
{ |
|
|
|
"cell_type": "code", |
|
|
|
"execution_count": 5, |
|
|
|
"execution_count": 8, |
|
|
|
"metadata": {}, |
|
|
|
"outputs": [], |
|
|
|
"source": [ |
|
|
|
@@ -305,7 +308,7 @@ |
|
|
|
}, |
|
|
|
{ |
|
|
|
"cell_type": "code", |
|
|
|
"execution_count": 6, |
|
|
|
"execution_count": 9, |
|
|
|
"metadata": {}, |
|
|
|
"outputs": [ |
|
|
|
{ |
|
|
|
@@ -324,7 +327,7 @@ |
|
|
|
"source": [ |
|
|
|
"logistic = Logistic(data, label)\n", |
|
|
|
"logistic.train(200)\n", |
|
|
|
"plot_decision_boundary(lambda x: logistic.predict(x), data, label)" |
|
|
|
"plot_decision_boundary(lambda x: logistic.predict(x), data, label, \"logistic_pred_res.pdf\")" |
|
|
|
] |
|
|
|
}, |
|
|
|
{ |
|
|
|
|