How to predict new data with a classification tree in R? I have built a classification tree for factor variables with the rpart package and now I want to predict unseen data with it.


*

*How can I get a sense of whether the model is good at predicting unseen data or not ?

*Is it possible to represent graphically the data and the model in order to see the difference between them ?
 A: First you need to define your measure of "good." It is always an absolute must to have some sort of a baseline model in place. Your classification tree may predict on a held out set with 0.9 accuracy, but this is less than impressive if a majority baseline model (classify everything as the majority class from the training data) also does this well.
Once you have defined this and performed your parameter tuning (I am guessing in your case it is mostly likely things like splitting criteria, tree complexity, etc.) via cross validation on 90% of the data you have available to you, apply the model to your remaining 10% of the data. If your model performs better on this data than your baseline, you can justify that your tree is doing well.
As for the second part of your question, I'm not really sure what you are looking for in terms of comparing the data to the model, but you might consider examining the class distribution across the nodes. Since you are using rpart package, you can use the rattle package to generate some decent looking visualizations like this:

A: *

*In order to evaluate if the model or the prediction is "good" or not, you need to know the loss function. For example, if you are doing regression, you can use $f(y,\hat y)=(y-\hat y)^2$ as loss. For classification task, 0-1 loss (number of correct predictions) can be used.

*Depends on number of features and number of data point of your data, and the task you are doing (classification or regression) there are different ways to visualize. 
Classification tree visualization example is given. Here is an example of visualizing regression trees (figures extracted from Wei-yin Loh's slides).

