Python: How to make model predict in a generalized manner using ML Algorithm

I have a dataset for which I am trying to predict target variables.

Col1    Col2    Col3    Col4    Col5
1      2       23      11     1
2      22      12      14     1
22     11      43      38     3
14     22      25      19     3
12     42      11      14     1
22     11      43      38     3
1      2       23      11     4
2      22      12      14     2
22     11      43      38     3


I have provided a sample data, but mine has thousands of records distributed in a similar way. Here, Col1, Col2, Col3, Col4 are my features and Col5 is target variable. Hence prediction should be 1,2,3 or 4 as these are my values for target variable. I have tried using algorithms such as random forest, decision tree etc. for predictions. Here if you see, values 1 and 3 are occurring more times as compared to 2 and 4. Hence while predicting, my model is more biased towards 1 and 3 whereas I am getting only less number of predictions for 2 and 4 (Got only 1 predicted for policy4 out of thousands of records when I saw the confusion matrix). I am planning to do feature extractions and try to see how my model behaves, but is there any way to make my model predict in a generalized way where it can generalize some values 2 and 4? I just read of undersampling and oversampling concepts, but I am beginner here, is there any good approach I could try? Should I split the training dataset based on Col5? I am implementing this in python using pandas.

• Look up imbalanced multi-class classification. – Emre Apr 22 '16 at 20:00
• So basically your data set is biased towards 1 and 3 right? – krishna Prasad Apr 23 '16 at 14:26
• yes. It is predicting only one value for policy 4 and little above for 2. And we have high values for 1 and 3. Could you please suggest some option other?. In the mean time I am checking on imbalanced multi-class classification. – SRS Apr 23 '16 at 18:35