def _calculate(self, X, y, categorical, metafeatures, helpers):
import sklearn.tree
if len(y.shape) == 1 or y.shape[1] == 1:
kf = cross_validation.StratifiedKFold(y, n_folds=10)
else:
kf = cross_validation.KFold(y.shape[0], n_folds=10)
accuracy = 0.
for train, test in kf:
random_state = check_random_state(42)
node = sklearn.tree.DecisionTreeClassifier(
criterion="entropy", max_depth=1, random_state=random_state,
min_samples_split=1, min_samples_leaf=1, max_features=None)
if len(y.shape) == 1 or y.shape[1] == 1:
node.fit(X[train], y[train])
else:
node = OneVsRestClassifier(node)
node.fit(X[train], y[train])
predictions = node.predict(X[test])
accuracy += sklearn.metrics.accuracy_score(predictions, y[test])
return accuracy / 10
评论列表
文章目录