# Path: citation_extractor/Utils/extra.py
# def avg(l):
#     if l is None:
#         return 0.0
#     return float(sum(l)) / max(len(l), 1)


import logging
import time
import numpy as np
from citation_extractor.Utils.extra import avg
from sklearn import model_selection, preprocessing, svm
from sklearn.feature_extraction import DictVectorizer
    from dask import delayed, compute
        Xp, yp = map(np.asanyarray, (Xp, yp))
        return Xp, yp

    def _select_best_C(self, X, y, groups, k=10, cache_size=10000):
        """ Use k-fold cross validation to select the best C parameter for SVM.

        :param X: the matrix describing the vectors
        :type X: numpy.ndarray
        :param y: the labels of the vectors
        :type y: numpy.ndarray
        :param groups: the labels of the groups
        :type groups: numpy.ndarray
        :param k: the number of folds to be used in cross validation
        :type k: int
        :param cache_size: the cache size used by SVM
        :type cache_size: int

        :return: The best C parameter for SVM
        :rtype: float
        """

        def _test_C_value(C, k, X, y, groups):
            gkf = model_selection.GroupKFold(n_splits=k)
            LOGGER.info("Testing C={} (k={})".format(C, k))
            tasks = [
                _do_split(C, train, test, X, y, groups)
                for train, test in gkf.split(X, y, groups)
            ]
            scores = compute(*tasks)
            LOGGER.info("Scores {}".format(scores))

# Path: citation_extractor/Utils/extra.py
# def avg(l):
#     if l is None:
#         return 0.0
#     return float(sum(l)) / max(len(l), 1)


# Path: citation_extractor/ned/ml.py
import logging
import time
import numpy as np
from citation_extractor.Utils.extra import avg
from sklearn import model_selection, preprocessing, svm
from sklearn.feature_extraction import DictVectorizer
    from dask import delayed, compute

        Xp, yp = map(np.asanyarray, (Xp, yp))
        return Xp, yp

    def _select_best_C(self, X, y, groups, k=10, cache_size=10000):
        """ Use k-fold cross validation to select the best C parameter for SVM.

        :param X: the matrix describing the vectors
        :type X: numpy.ndarray
        :param y: the labels of the vectors
        :type y: numpy.ndarray
        :param groups: the labels of the groups
        :type groups: numpy.ndarray
        :param k: the number of folds to be used in cross validation
        :type k: int
        :param cache_size: the cache size used by SVM
        :type cache_size: int

        :return: The best C parameter for SVM
        :rtype: float
        """

        def _test_C_value(C, k, X, y, groups):
            gkf = model_selection.GroupKFold(n_splits=k)
            LOGGER.info("Testing C={} (k={})".format(C, k))
            tasks = [
                _do_split(C, train, test, X, y, groups)
                for train, test in gkf.split(X, y, groups)
            ]
            scores = compute(*tasks)
            LOGGER.info("Scores {}".format(scores))

            avg_score = avg(scores)