Latex 如何画出决策树示意图

39 篇文章 5 订阅
30 篇文章 8 订阅

以《机器学习》第85页的图为例:

使用包:

\usepackage{tikz}

代码:

\documentclass[UTF8]{ctexart}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}
\begin{document}
\thispagestyle{empty}
% 定义基本形状
\tikzstyle{results}=[ellipse ,text centered,draw=black]
\tikzstyle{decisions} =[rectangle, rounded corners,text centered, draw = black]
% 箭头形式
\tikzstyle{arrow} = [-,>=stealth]
\begin{tikzpicture}[node distance=1cm]
%定义具体形状和相关位置
\node[decisions](rootnode){ 纹理$=?$ };
\node[decisions,below of=rootnode,yshift=-0.5cm,xshift=-2cm](rhopoint){密度$\leq0.381?$};
\node[decisions,below of=rootnode,yshift=-0.5cm,xshift=0.5cm](touchpoint){触感$=?$};
\node[results,below of=rootnode,yshift=-0.5cm,xshift=2.5cm](result1){坏瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=-1cm](result2){坏瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=0.5cm](result3){好瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=2cm](result4){坏瓜};
\node[results,below of=rhopoint,yshift=-0.5cm,xshift=3.5cm](result5){好瓜};
%连接形状
\draw [arrow] (rootnode) -- node [left,font=\small] {清晰} (rhopoint);
\draw [arrow] (rootnode) -- node [right,font=\small] {稍糊} (touchpoint);
\draw [arrow] (rootnode) -- node [right,font=\small] {模糊} (result1);
\draw [arrow] (rhopoint) -- node [left,font=\small] {是} (result2);
\draw [arrow] (rhopoint) -- node [right,font=\small] {否} (result3);
\draw [arrow] (touchpoint) -- node [left,font=\small] {硬滑} (result4);
\draw [arrow] (touchpoint) -- node [right,font=\small] {软粘} (result5);
\end{tikzpicture}
\end{document}

结果:

这里写图片描述

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值