Google深度学习系列视频
谷歌开发者视频中文频道:https://www.youtube.com/playlist?list=PLwv-rHS37fS9s3udyMoPPpaROL4u_tF5k
____tz_zs学习笔记
一、在Spyder中写第一个机器学习的程序:
from sklearn import tree
feature = [[140,1],[130,1],[150,0],[170,0]]
#labels = ["apple","apple","orange","orange"]
labels = [0,0,1,1]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(feature,labels)
print (clf.predict([[150,0]]))
二、下面是根据google机器学习视频,写的鸢尾花数据集的决策树训练、测试、可视化代码
鸢尾花数据集:http://download.csdn.net/detail/tz_zs/9874935 (可以下载下来对照理解) 参考资料:http://cda.pinggu.org/view/3074.html# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
#引入数据集
import numpy as np
from sklearn.datasets import load_iris
from sklearn import tree
iris = load_iris()
#print (iris.feature_names)
#print (iris.target_names)
#print (iris.data[0])
#print (iris.target[0])
test_idx = [0,50,100]
#training data
train_target = np.delete(iris.target, test_idx)
train_data = np.delete(iris.data, test_idx, axis=0)
#testing data
test_target = iris.target[test_idx]
test_data = iris.data[test_idx]
clf = tree.DecisionTreeClassifier()
clf = clf.fit(train_data,train_target)
print (test_target)
print (clf.predict(test_data))
#viz code 可视化 制作一个简单易读的PDF
from sklearn.externals.six import StringIO
import pydot
dot_data = StringIO()
tree.export_graphviz(clf, out_file=dot_data,
feature_names=iris.feature_names,
class_names=iris.target_names,
filled=True, rounded=True,
special_characters=True)
graph = pydot.graph_from_dot_data(dot_data.getvalue())
graph.write_pdf("iris.pdf")
三、本项目中导入包的问题
import pydot:
要在python2.7环境安装,需要安装如图的包,才能在开始菜单有Anaconda prompt2.7在Anaconda命令栏中输入pip install pydot 安装
此时已经在python2.7环境下安装好了pydot包。 python3.6直接打开Anaconda prompt安装即可