mirror of
https://github.com/Estom/notes.git
synced 2026-04-10 06:18:46 +08:00
代码看完今天的了
This commit is contained in:
@@ -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. 每天数据集处理一小步。
|
||||
|
||||
13
工作日志/2021年3月21日-今日计划.md
Normal file
13
工作日志/2021年3月21日-今日计划.md
Normal file
@@ -0,0 +1,13 @@
|
||||
1. 每天sklearn一个机器学习小算法
|
||||
- [ ] 朴素贝叶斯(学习原理、sklearn实践
|
||||
- [ ] 、malware)
|
||||
- [ ] 逻辑回归(学习原理、sklearn实践
|
||||
- [ ] 、malware)
|
||||
2. 每天一个联邦学习框架
|
||||
- [ ] tensorflow federated
|
||||
3. 每天一篇联邦学习的文章。
|
||||
- [ ] CIC动态数据处理和静态数据处理方式
|
||||
4. 每天数据集处理一小步。
|
||||
- [ ] 实现静态数据处理脚本
|
||||
|
||||
> 明天实现动态数据处理的脚本
|
||||
91
机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify.py
Normal file
91
机器学习/殷康龙/机器学习实战1源代码/3.DecisionTree/sklearn_dts_classify.py
Normal 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()
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user