Assume we have a train dataset with 5 classes a,b,c,d,e but the test dataset have only d and e with extra class f not present in train set. If i want to do machine learning with this datset in weka or python what should I do with this dataset? should I transform them and how should I do it? Should I remove classes form train set which are not in test set? (it's a multi-class classification, and the letters a-f are the target classes)
Well, what you should do depends highly on what your goal here is.
Do you - for whatever reason - have to use the given test and training sets as such?
If not, a valid approach would be to shuffle the available data and determine a new test and training set, so that they each contain all classes.
Do you want a classifier only for d and e, and have to use the given test and training sets?
Then nothing really speaks against just training on the training set with all classes and testing only the ones you are interested in/ have test data for. Of course, then you can not make statements about the accuracy for other classes. You could also try removing the other classes from the training set, if they won't appear in your application, which may or may not make the classifier perform better on the test data.
Essentially, it's not easy to provide a ceratin answer without having more context about why you have this kind of data, and what your goal is. It would be great if you can provide a few more details, so we can work on a more fitting answer.