My question is I generated a function to store the 10-fold cross-validation scores for each of the stepwise models within each classifier. For example, for Naive Bayes, I have two models, one only use one variable but others use two. The similar to decision tree model. The function is something like
def crossV(clf):
cvOutcome=pd.DataFrame()
index=pd.DataFrame()
classifier=pd.DataFrame()
for i in range(4)[2:]:
tt=array(tuple(x[1:i] for x in modelDataFullnew))
qq=array(tuple(x[0] for x in modelDataFullnew))
scores=cross_validation.cross_val_score(clf, tt, qq, cv=10)*100
index_i=list(np.repeat(i-1,10))
classifier_i=list(np.repeat(str(clf)[:-2],10))
scores=list(scores)
cvOutcome=cvOutcome.append(scores)
index=index.append(index_i)
classifier=classifier.append(classifier_i)
merge=pd.concat([index,cvOutcome,classifier],axis=1)
merge.columns=['model','rate','classifier']
return(merge)
from sklearn.naive_bayes import GaussianNB as gnb
clf_nb=gnb()
from sklearn import tree
clf_dt=tree.DecisionTreeClassifier()
If I do crossV(clf_nb)
it will give me the result as
model rate classifier
1 92.558679 GaussianNB
1 92.558381 GaussianNB
1 92.558381 GaussianNB
1 92.558381 GaussianNB
1 92.558381 GaussianNB
My question is how can I apply this function to several classifiers and append their result as a long data frame like
model rate classifier
1 92.558679 GaussianNB
1 92.558381 GaussianNB
1 92.558381 GaussianNB
1 92.558381 GaussianNB
1 92.558381 GaussianNB
1 93.25 DecisionTree
1 93.25 DecisionTree
i tried this code but it does not work:
hhh=[clf_nb,clf_dt]
g=pd.DataFrame()
while i in hhh:
g=g.append(crossV(i))
I also tried map function in array like
map(crossV,(clf_nb,clf_dt))
It works but just give me a larger list and I don't know how to transform it to data frame.