From defe7c67761b09c1de64f275e3c3a7ff340f226d Mon Sep 17 00:00:00 2001 From: yinkanglong_lab Date: Sun, 21 Mar 2021 00:08:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=9C=8B=E5=AE=8C=E4=BB=8A?= =?UTF-8?q?=E5=A4=A9=E7=9A=84=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工作日志/2021年3月20日-今日计划.md | 7 +- 工作日志/2021年3月21日-今日计划.md | 13 +++ ...elearn_dts_regressor_demo.py => skelearn_dts_regressor.py} | 0 .../3.DecisionTree/sklearn_dts_classify.py | 91 +++++++++++++++++++ .../3.DecisionTree/sklearn_dts_classify_demo.py | 61 ------------- 5 files changed, 108 insertions(+), 64 deletions(-) create mode 100644 工作日志/2021年3月21日-今日计划.md rename 机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/{skelearn_dts_regressor_demo.py => skelearn_dts_regressor.py} (100%) create mode 100644 机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify.py delete mode 100644 机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify_demo.py diff --git a/工作日志/2021年3月20日-今日计划.md b/工作日志/2021年3月20日-今日计划.md index 392d2399..2e69ff67 100644 --- a/工作日志/2021年3月20日-今日计划.md +++ b/工作日志/2021年3月20日-今日计划.md @@ -9,14 +9,15 @@ > 学习深度学习框架pytorch和TensorFlow。 1. 每天sklearn一个机器学习小算法 - - [ ] k-近邻算法(学习原理、sklearn实践、malware) - - [ ] 决策树(学习原理、sklearn实践、malware) + - [x] k-近邻算法(学习原理、sklearn实践 + - [ ] 、malware) + - [x] 决策树(学习原理、sklearn实践 + - [ ] 、malware) - [x] 复习吴恩达机器学习笔记 - [x] 复习吴恩达深度学习笔记 - [x] 复习Python-numpy-scipy那一套 2. 每天一个联邦学习框架 - [ ] tensorflow - - [ ] tensorflow federated 3. 每天一篇联邦学习的文章。 - [ ] deepAMD 4. 每天数据集处理一小步。 diff --git a/工作日志/2021年3月21日-今日计划.md b/工作日志/2021年3月21日-今日计划.md new file mode 100644 index 00000000..d5f4644a --- /dev/null +++ b/工作日志/2021年3月21日-今日计划.md @@ -0,0 +1,13 @@ +1. 每天sklearn一个机器学习小算法 + - [ ] 朴素贝叶斯(学习原理、sklearn实践 + - [ ] 、malware) + - [ ] 逻辑回归(学习原理、sklearn实践 + - [ ] 、malware) +2. 每天一个联邦学习框架 + - [ ] tensorflow federated +3. 每天一篇联邦学习的文章。 + - [ ] CIC动态数据处理和静态数据处理方式 +4. 每天数据集处理一小步。 + - [ ] 实现静态数据处理脚本 + +> 明天实现动态数据处理的脚本 diff --git a/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/skelearn_dts_regressor_demo.py b/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/skelearn_dts_regressor.py similarity index 100% rename from 机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/skelearn_dts_regressor_demo.py rename to 机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/skelearn_dts_regressor.py diff --git a/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify.py b/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify.py new file mode 100644 index 00000000..439a8057 --- /dev/null +++ b/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify.py @@ -0,0 +1,91 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- + +""" +Created on 2017-06-29 +Updated on 2017-06-29 +DecisionTree: 决策树 +Author: 小瑶 +GitHub: https://github.com/apachecn/AiLearning +""" +print(__doc__) + +import numpy as np +import matplotlib.pyplot as plt + +from sklearn.datasets import load_iris +from sklearn.tree import DecisionTreeClassifier + + + +def createDataSet(): + """ + Desc: + 创建数据集 + Args: + 无需传入参数 + Returns: + 返回数据集和对应的label标签 + """ + # dataSet 前两列是特征,最后一列对应的是每条数据对应的分类标签 + dataSet = [[1, 1, 1], + [1, 1, 1], + [1, 0, 2], + [0, 1, 2], + [0, 1, 2]] + # labels 露出水面 脚蹼,注意: 这里的labels是写的 dataSet 中特征的含义,并不是对应的分类标签或者说目标变量 + # 返回 + return dataSet + +def test_dts_fish(): + datasets = np.array(createDataSet()) + dataset = datasets[:,[0,1]] + labels = datasets[:,2] + dt_classifer = DecisionTreeClassifier().fit(dataset,labels) + Z = dt_classifer.predict(dataset) + + +def test_dts_iris(): + # 参数 + n_classes = 3 + plot_colors = "bry" + plot_step = 0.02 + + # 加载数据 + iris = load_iris() + + for pairidx, pair in enumerate([[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]): + # 我们只用两个相应的features + X = iris.data[:, pair] + y = iris.target + + # 训练 + clf = DecisionTreeClassifier().fit(X, y) + + # 绘制决策边界 + plt.subplot(2, 3, pairidx + 1) + + x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1 + y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1 + xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step), + np.arange(y_min, y_max, plot_step)) + + Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) + Z = Z.reshape(xx.shape) + cs = plt.contourf(xx, yy, Z, cmap=plt.cm.Paired) + + plt.xlabel(iris.feature_names[pair[0]]) + plt.ylabel(iris.feature_names[pair[1]]) + plt.axis("tight") + + # 绘制训练点 + for i, color in zip(range(n_classes), plot_colors): + idx = np.where(y == i) + plt.scatter(X[idx, 0], X[idx, 1], c=color, label=iris.target_names[i], + cmap=plt.cm.Paired) + + plt.axis("tight") + + plt.suptitle("Decision surface of a decision tree using paired features") + plt.legend() + plt.show() diff --git a/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify_demo.py b/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify_demo.py deleted file mode 100644 index 7162fd5a..00000000 --- a/机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify_demo.py +++ /dev/null @@ -1,61 +0,0 @@ -#!/usr/bin/python -# -*- coding: UTF-8 -*- - -""" -Created on 2017-06-29 -Updated on 2017-06-29 -DecisionTree: 决策树 -Author: 小瑶 -GitHub: https://github.com/apachecn/AiLearning -""" -print(__doc__) - -import numpy as np -import matplotlib.pyplot as plt - -from sklearn.datasets import load_iris -from sklearn.tree import DecisionTreeClassifier - -# 参数 -n_classes = 3 -plot_colors = "bry" -plot_step = 0.02 - -# 加载数据 -iris = load_iris() - -for pairidx, pair in enumerate([[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]]): - # 我们只用两个相应的features - X = iris.data[:, pair] - y = iris.target - - # 训练 - clf = DecisionTreeClassifier().fit(X, y) - - # 绘制决策边界 - plt.subplot(2, 3, pairidx + 1) - - x_min, x_max = X[:, 0].min() - 1, X[:, 0].max() + 1 - y_min, y_max = X[:, 1].min() - 1, X[:, 1].max() + 1 - xx, yy = np.meshgrid(np.arange(x_min, x_max, plot_step), - np.arange(y_min, y_max, plot_step)) - - Z = clf.predict(np.c_[xx.ravel(), yy.ravel()]) - Z = Z.reshape(xx.shape) - cs = plt.contourf(xx, yy, Z, cmap=plt.cm.Paired) - - plt.xlabel(iris.feature_names[pair[0]]) - plt.ylabel(iris.feature_names[pair[1]]) - plt.axis("tight") - - # 绘制训练点 - for i, color in zip(range(n_classes), plot_colors): - idx = np.where(y == i) - plt.scatter(X[idx, 0], X[idx, 1], c=color, label=iris.target_names[i], - cmap=plt.cm.Paired) - - plt.axis("tight") - -plt.suptitle("Decision surface of a decision tree using paired features") -plt.legend() -plt.show()