Usecase clustering#90
Conversation
| An overview over all learners can be found [here](http://mlr-org.github.io/mlr-tutorial/devel/html/integrated_learners/index.html). You can also call the \texttt{listLearners} command for our specific task. | ||
|
|
||
|
|
||
| ```{r, warning=FALSE, eval = FALSE} |
There was a problem hiding this comment.
You can leave warning=FALSE out, because travis has all packages and no warning will be produced
schiffner
left a comment
There was a problem hiding this comment.
Hi, looks very good already.
I just skimmed over it very quickly and commented on some technical stuff.
| set.seed(1234) | ||
| ``` | ||
|
|
||
| This is a use case for clustering with the [%mlr] package. We consider the [agriculture](https://www.rdocumentation.org/packages/cluster/versions/1.10.0/topics/agriculture) dataset that contains observations about $n=12$ countries including |
There was a problem hiding this comment.
Please use [agriculture](&cluster::agriculture).
(The build script for the tutorial will expand this to the correct link.)
|
|
||
| ```{r, fig.width = 5} | ||
| library("cluster") | ||
| data(agriculture) |
There was a problem hiding this comment.
Please use data(agriculture, package "cluster")
|
|
||
| So let's have a look at the data first. | ||
|
|
||
| ```{r, fig.width = 5} |
There was a problem hiding this comment.
Please specify the aspect ratio (fig.asp) instead of the fig.width.
(This works better for the pdf version of the tutorial.)
|
|
||
| * define the learning task ([here](http://mlr-org.github.io/mlr-tutorial/devel/html/task/index.html)), | ||
| * select a learning method ([here](http://mlr-org.github.io/mlr-tutorial/devel/html/learner/index.html)), | ||
| * train the learner with data ([here](http://mlr-org.github.io/mlr-tutorial/devel/html/train/index.html)), |
There was a problem hiding this comment.
I think "train the learner" is sufficient.
| We now have to define a clustering task. Notice that a clustering task doesn't have a target variable. | ||
|
|
||
| ```{r message = FALSE} | ||
| library(mlr) |
There was a problem hiding this comment.
You don't need library(mlr) and then can also leave out the message = FALSE option.
|
|
||
| Tuning will address the question of choosing the best hyperparameters for our problem. | ||
|
|
||
| We first create a search space for the number of clusters $k$, e. g. $k \in \lbrace 2, 3, 4, 5 \rbrace$. Further we define an optimization algorithm and a [resampling strategy](http://mlr-org.github.io/mlr-tutorial/devel/html/resample/index.html). |
There was a problem hiding this comment.
As above you need to link to resample.md.
|
|
||
| We first create a search space for the number of clusters $k$, e. g. $k \in \lbrace 2, 3, 4, 5 \rbrace$. Further we define an optimization algorithm and a [resampling strategy](http://mlr-org.github.io/mlr-tutorial/devel/html/resample/index.html). | ||
|
|
||
| Finally, by combining all the previous pieces, we can tune the parameter $k$ by calling \texttt{tuneParams}. We will use discrete_ps with grid search and the silhouette coefficient as optimization criterion: |
There was a problem hiding this comment.
[&tuneParams]- I would also mention 3-fold cross-validation.
| discrete_ps = makeParamSet(makeDiscreteParam("centers", values = c(2, 3, 4, 5))) | ||
| ctrl = makeTuneControlGrid() | ||
| res = tuneParams(cluster.lrn, agri.task, measures = silhouette, resampling = cv3, | ||
| par.set = discrete_ps, control = ctrl) |
There was a problem hiding this comment.
Could you please indent code by 2 spaces?
|
|
||
| This is our final clustering for our problem. | ||
|
|
||
| ```{r, fig.width= 5} |
| This is our final clustering for our problem. | ||
|
|
||
| ```{r, fig.width= 5} | ||
| plot(y ~ x, col = tuned.pred$data$response, data = agriculture) |
There was a problem hiding this comment.
Could you please use the getter function (I think getPredictionResponse should work here)?
| head(data) | ||
| ``` | ||
|
|
||
| Our aim - as mentioned before - is to predict which kind of people would have survided. |
|
|
||
| #### Preprocessing | ||
|
|
||
| The data set is corrected regarding their data types. |
There was a problem hiding this comment.
I would do str(data) to show the different types, then mention how and why they need corrected
|
@juliambr Do you still have motivation to finish this up here? Would be great! 🎉 |
wrote a usecase for clustering - please review it :)