代码看完今天的了

This commit is contained in:
yinkanglong_lab
2021-03-21 00:08:21 +08:00
parent 90e4065120
commit defe7c6776
5 changed files with 108 additions and 64 deletions

View File

@@ -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. 每天数据集处理一小步。

View File

@@ -0,0 +1,13 @@
1. 每天sklearn一个机器学习小算法
- [ ] 朴素贝叶斯学习原理、sklearn实践
- [ ] 、malware
- [ ] 逻辑回归学习原理、sklearn实践
- [ ] 、malware
2. 每天一个联邦学习框架
- [ ] tensorflow federated
3. 每天一篇联邦学习的文章。
- [ ] CIC动态数据处理和静态数据处理方式
4. 每天数据集处理一小步。
- [ ] 实现静态数据处理脚本
> 明天实现动态数据处理的脚本

View File

@@ -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()

View File

@@ -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()