我正在使用scikit-learn在随机森林中进行实验,并且获得了很好的训练结果,但是相对而言,我的测试结果却很差...
这是我要解决的问题(灵感来自扑克):给定玩家A的底牌,玩家B的底牌和翻牌(3张牌),哪位玩家的手牌最好?从数学上讲,这是14个输入(7张卡-一张等级,每张一套)和一个输出(0或1)。
到目前为止,这是我的一些结果:
Training set size: 600k, test set size: 120k, number of trees: 25
Success rate in training set: 99.975%
Success rate in testing set: 90.05%
Training set size: 400k, test set size: 80k, number of trees: 100
Success rate in training set: 100%
Success rate in testing set: 89.7%
Training set size: 600k, test set size: 120k, number of trees: 5
Success rate in training set: 98.685%
Success rate in testing set: 85.69%
这是使用的相关代码:
from sklearn.ensemble import RandomForestClassifier
Forest = RandomForestClassifier(n_estimators = 25) #n_estimator varies
Forest = Forest.fit(inputs[:trainingSetSize],outputs[:trainingSetSize])
trainingOutputs = Forest.predict(inputs[:trainingSetSize])
testOutputs = Forest.predict(inputs[trainingSetSize:])
似乎无论使用多少树,尽管训练集相对较大且特征数量较少,但训练集的性能要比测试集好得多。