@Override
	public void train(List<Instance> instances) {
		// TODO Auto-generated method stub
		
		HashMap<String, Integer> labelCounts = new HashMap<String, Integer>();
		int maxCount = 0;
		ArrayList<String> maxLabels = new ArrayList<String>(); 
		
		for(Instance instance : instances){
			Label l = instance.getLabel();
			if(l == null)
				continue;
			
			String label = l.toString();
			int labelCount = labelCounts.containsKey(label) ? labelCounts.get(label)+1 : 1;
			labelCounts.put(label, labelCount);
			
			if(labelCount > maxCount){
				maxLabels.clear();
				maxLabels.add(label);
				maxCount = labelCount;
			}
			else if (labelCount == maxCount && !maxLabels.contains(label)){
				maxLabels.add(label);
			}
		}
		
		// randomly pick a max label
		Random rand = new Random();
		int selectedIndex = rand.nextInt(maxLabels.size());
		int majorityLabel = Integer.parseInt(maxLabels.get(selectedIndex));
		this._majorityLabel = new ClassificationLabel(majorityLabel);
		
	}