我正在尝试使用 sklearn 对我的朴素贝叶斯分类器进行 k 折验证
train = csv_io.read_data("../Data/train.csv")
target = np.array( [x[0] for x in train] )
train = np.array( [x[1:] for x in train] )
#In this case we'll use a random forest, but this could be any classifier
cfr = RandomForestClassifier(n_estimators=100)
#Simple K-Fold cross validation. 10 folds.
cv = cross_validation.KFold(len(train), k=10, indices=False)
#iterate through the training and test cross validation segments and
#run the classifier on each one, aggregating the results into a list
results = []
for traincv, testcv in cv:
probas = cfr.fit(train[traincv], target[traincv]).predict_proba(train[testcv])
results.append( myEvaluationFunc(target[testcv], [x[1] for x in probas]) )
#print out the mean of the cross-validated results
print "Results: " + str( np.array(results).mean() )
我从这个网站找到了一个代码,https://www.kaggle.com/wiki/GettingStartedWithPythonForDataScience/history/969。在示例中,分类器是 RandomForestClassifier,我想使用自己的朴素贝叶斯分类器,但我不太确定 fit 方法在这一行 probas = cfr.fit(train[traincv], target[traincv]).predict_proba 的作用(训练[testcv])