As a starting point:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,
positioning, % <--- added
shapes}
\usepackage{xparse}% So that we can have two optional parameters
\NewDocumentCommand\DownArrow{O{2.0ex} O{black}}%
{%
\mathrel{\tikz[baseline] \draw [<-, line width=0.5pt, #2] (0,0) -- ++(0,#1);}
}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm,
block/.style = {rectangle, draw, rounded corners,
text width =15em, align=center},
cloud/.style = {draw, ellipse, aspect=1.2, align=center}
]
% Place nodes
\node [block] (init) {\underline{Machine}\\
$f(\vec{x}) = \theta_0 + \theta_1x_1 + \dotsm + \theta_n x_n$\\[1ex]
$\DownArrow[30pt]$\\[1ex]
$y=\phi\bigl(f(\vec{x})\bigr)$
};
\node [cloud, left=of init] (data)
{\underline{Training data set}\\
dog, cat, pig, etc};
\node [cloud, above right=of init.east] (input)
{\underline{Input}\\
features data $\vec{x}$};
\node [cloud, below right=of init.east] (output)
{\underline{Output}\\
class: $y$};
% Draw edges
\draw[-latex'] (data) -- (init);
\draw[-latex'] (input) -- (init.east |- input);
\draw[-latex'] (init.east |- output) -- (output);
\end{tikzpicture}
\end{document}
You were on the right track :). To your code I made the following changes:
- Correct the input encoding (it should be only one, recent
article
for default use utf8
).
- For positioning, use the library
positioning
and its syntax (note above right=of ...
instead your above of = ...
).
- The use of
\tikzstyle
is not recomended. Instead of it, use \tikzset
or define styles as options to tikzpicture
(as I do in the above MWE).
- After defining
align=center
, you can write multi line (centered) text in the nodes
edit:
next iteration (should be closer to your sketch):
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows,
positioning, % <--- added
shapes}
\usepackage{xparse}% So that we can have two optional parameters
\NewDocumentCommand\DownArrow{O{2.0ex} O{black}}%
{%
\mathrel{\tikz[baseline] \draw [<-, line width=0.5pt, #2] (0,0) -- ++(0,#1);}
}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm,
block/.style = {rectangle, draw, rounded corners,
text width =15em, align=center},
cloud/.style = {draw, ellipse, aspect=1.2, align=center},
]
% Place nodes
\node [block, label={[anchor=east, align=center, xshift=-1em,
font=\small\linespread{0.8}\selectfont,
text=purple]right:
$x_1,\dotsc,x_n$:\\
features\\
variables}
] (init) {\underline{Machine}\\
$f(\vec{x}) = \theta_0 + \theta_1 x_1 + \dotsm + \theta_n x_n$\\[1ex]
$\DownArrow[30pt]$\\[1ex]
$y=\phi\bigl(f(\vec{x})\bigr)$
};
\node [cloud, left=of init] (data)
{\underline{Training data set}\\
dog, cat, pig, etc};
\node [cloud, above right=of init.east] (input)
{\underline{Input}\\
features data $\vec{x}$};
\node [cloud, below right=of init.east] (output)
{\underline{Output}\\
class: $y$};
% Draw edges
\draw[-latex'] (data) -- (init);
\draw[red,-latex'] (input) -- (init.east |- input);
\draw[red,-latex'] (init.east |- output) -- (output);
\end{tikzpicture}
\end{document}
Addendum:
In the last three years, packages tikz
and document class article
have undergone several additions, with which the above solution proposal can/had to be now written as follows:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, % changed
positioning, % <--- added
shapes}
\NewDocumentCommand\DownArrow{O{2.0ex} O{black}}%
{%
\mathrel{\tikz[baseline] \draw [Straight Barb-, semithick, #2] (0,0) -- ++(0,#1);}
}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm,
block/.style = {rectangle, draw, rounded corners,
text width =15em, align=center},
cloud/.style = {draw, ellipse, aspect=1.2, align=center},
]
% Place nodes
\node [block, label={[anchor=east, align=center, xshift=-1em,
font=\small\linespread{0.8}\selectfont,
text=purple]right:
$x_1,\dotsc,x_n$:\\
features\\
variables}
] (init) {\underline{Machine}\\
$f(\vec{x}) = \theta_0 + \theta_1 x_1 + \dotsm + \theta_n x_n$\\[1ex]
$\DownArrow[30pt]$\\[1ex]
$y=\phi\bigl(f(\vec{x})\bigr)$
};
\node [cloud, left=of init] (data)
{\underline{Training data set}\\
dog, cat, pig, etc};
\node [cloud, above right=of init.east] (input)
{\underline{Input}\\
features data $\vec{x}$};
\node [cloud, below right=of init.east] (output)
{\underline{Output}\\
class: $y$};
% Draw edges
\draw[-Latex] (data) -- (init);
\draw[red,-Latex] (input) -- (init.east |- input);
\draw[red,-Latex] (init.east |- output) -- (output);
\end{tikzpicture}
\end{document}
Result is almost the same as befone: