The `$` sign does not seem to be interpreted for latex math rendering. You probably need to replace expressions such as:

```
$K$-nearest
```

by:

```
:math:`K`-nearest
```