Browse Source

Improve notebook

pull/4/head
bushuhui 5 years ago
parent
commit
8a29582547
11 changed files with 1036 additions and 4576 deletions
  1. +14
    -10
      2_knn/knn_classification.ipynb
  2. +188
    -87
      3_kmeans/1-k-means.ipynb
  3. +41
    -68
      3_kmeans/2-kmeans-color-vq.ipynb
  4. +37
    -16
      3_kmeans/3-ClusteringAlgorithms.ipynb
  5. +4
    -0
      3_kmeans/README.md
  6. +569
    -4268
      4_logistic_regression/1-Least_squares.ipynb
  7. +40
    -21
      4_logistic_regression/2-Logistic_regression.ipynb
  8. +60
    -45
      4_logistic_regression/3-PCA_and_Logistic_Regression.ipynb
  9. +1
    -1
      4_logistic_regression/PCA.ipynb
  10. +20
    -18
      5_nn/1-Perceptron.ipynb
  11. +62
    -42
      5_nn/2-mlp_bp.ipynb

+ 14
- 10
2_knn/knn_classification.ipynb View File

@@ -80,7 +80,7 @@
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"# data generation\n",
"# data generation (FIXME: feature name not good)\n",
"np.random.seed(314)\n",
"data_size_1 = 300\n",
"x1_1 = np.random.normal(loc=5.0, scale=1.0, size=data_size_1)\n",
@@ -127,7 +127,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 5,
"metadata": {},
"outputs": [
{
@@ -147,6 +147,7 @@
"\n",
"def knn_vote(ys):\n",
" vote_dict = {}\n",
" \n",
" for y in ys:\n",
" if y not in vote_dict.keys():\n",
" vote_dict[y] = 1\n",
@@ -166,13 +167,14 @@
" \n",
"\n",
"#a = knn_predict(x_train[0], x_train, y_train)\n",
"\n",
"y_train_est = [knn_predict(x_train[i], x_train, y_train) for i in range(len(x_train))]\n",
"print(y_train_est)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"metadata": {},
"outputs": [
{
@@ -194,7 +196,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"outputs": [
{
@@ -224,7 +226,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
@@ -278,7 +280,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 10,
"metadata": {},
"outputs": [
{
@@ -298,6 +300,8 @@
"# knn classifier\n",
"clf = KNN(k=3)\n",
"train_acc = clf.fit(x_train, y_train).score() * 100.0\n",
"\n",
"y_test_pred = clf.predict(x_test)\n",
"test_acc = clf.score(y_test, y_test_pred) * 100.0\n",
"\n",
"print('train accuracy: %f %%' % train_acc)\n",
@@ -313,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": 33,
"execution_count": 11,
"metadata": {},
"outputs": [
{
@@ -342,7 +346,7 @@
},
{
"cell_type": "code",
"execution_count": 34,
"execution_count": 12,
"metadata": {},
"outputs": [
{
@@ -371,7 +375,7 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
@@ -387,7 +391,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 14,
"metadata": {},
"outputs": [
{


+ 188
- 87
3_kmeans/1-k-means.ipynb
File diff suppressed because it is too large
View File


+ 41
- 68
3_kmeans/2-kmeans-color-vq.ipynb
File diff suppressed because it is too large
View File


+ 37
- 16
3_kmeans/3-ClusteringAlgorithms.ipynb
File diff suppressed because it is too large
View File


+ 4
- 0
3_kmeans/README.md View File

@@ -1,3 +1,7 @@
## 内容

增加一个Bag of Words的说明和例子程序 (https://blog.csdn.net/wsj998689aa/article/details/47089153)



## References


+ 569
- 4268
4_logistic_regression/1-Least_squares.ipynb
File diff suppressed because it is too large
View File


+ 40
- 21
4_logistic_regression/2-Logistic_regression.ipynb
File diff suppressed because it is too large
View File


+ 60
- 45
4_logistic_regression/3-PCA_and_Logistic_Regression.ipynb
File diff suppressed because it is too large
View File


+ 1
- 1
4_logistic_regression/PCA.ipynb View File

@@ -24,7 +24,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
}
},
"nbformat": 4,


+ 20
- 18
5_nn/1-Perceptron.ipynb View File

@@ -119,17 +119,22 @@
"\n",
"\n",
"算法\n",
"```\n",
"\n",
"\n",
"输入:T={(x1,y1),(x2,y2)...(xN,yN)}(其中xi∈X=Rn,yi∈Y={-1, +1},i=1,2...N,学习速率为η)\n",
"\n",
"输出:w, b;感知机模型f(x)=sign(w·x+b)\n",
"(1) 初始化w0,b0\n",
"(2) 在训练数据集中选取(xi, yi)\n",
"(3) 如果yi(w * xi+b)≤0\n",
" w = w + ηyixi\n",
" b = b + ηyi\n",
"(4) 如果所有的样本都正确分类,或者迭代次数超过设定值,则终止\n",
"(5) 否则,跳转至(2)\n",
"```\n",
"\n",
"1. 初始化$w_0$,$b_0$\n",
"2. 在训练数据集中选取$(x_i, y_i)$\n",
"3. 如果$y_i(w * x_i+b)≤0$\n",
" \n",
" $w = w + η y_i x_i$\n",
" \n",
" $b = b + η y_i$\n",
"\n",
"4. 如果所有的样本都正确分类,或者迭代次数超过设定值,则终止\n",
"5. 否则,跳转至(2)\n",
"\n"
]
},
@@ -142,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 1,
"metadata": {
"lines_to_end_of_cell_marker": 2
},
@@ -151,13 +156,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"update weight and bias: 1.0 2.5 0.5\n",
"update weight and bias: -2.5 1.0 0.0\n",
"update weight and bias: -1.5 3.5 0.5\n",
"update weight and bias: -5.0 2.0 0.0\n",
"update weight and bias: -4.0 4.5 0.5\n",
"w = [-4.0, 4.5]\n",
"b = 0.5\n",
"update weight and bias: 1.0 3.0 0.5\n",
"update weight and bias: -2.5 1.5 0.0\n",
"w = [-2.5, 1.5]\n",
"b = 0.0\n",
"ground_truth: [1, 1, 1, 1, -1, -1, -1, -1]\n",
"predicted: [1, 1, 1, 1, -1, -1, -1, -1]\n"
]
@@ -248,7 +250,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.6.9"
}
},
"nbformat": 4,


+ 62
- 42
5_nn/2-mlp_bp.ipynb
File diff suppressed because it is too large
View File


Loading…
Cancel
Save