当前位置: 首页>>代码示例>>Python>>正文


Python six.string_types方法代码示例

本文整理汇总了Python中sklearn.externals.six.string_types方法的典型用法代码示例。如果您正苦于以下问题:Python six.string_types方法的具体用法?Python six.string_types怎么用?Python six.string_types使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sklearn.externals.six的用法示例。


在下文中一共展示了six.string_types方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: is_iterable

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def is_iterable(x):
    """Python 3.x adds the ``__iter__`` attribute
    to strings. Thus, our previous tests for iterable
    will fail when using ``hasattr``.

    Parameters
    ----------

    x : object
        The object or primitive to test whether
        or not is an iterable.


    Returns
    -------

    bool
        True if ``x`` is an iterable
    """
    if isinstance(x, six.string_types):
        return False
    return hasattr(x, '__iter__') 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:24,代码来源:fixes.py

示例2: _val_cols

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _val_cols(cols):
    # if it's None, return immediately
    if cols is None:
        return cols

    # try to make cols a list
    if not is_iterable(cols):
        if isinstance(cols, six.string_types):
            return [cols]
        else:
            raise ValueError('cols must be an iterable sequence')

    # if it is an index or a np.ndarray, it will have a built-in
    # (potentially more efficient tolist() method)
    if hasattr(cols, 'tolist') and hasattr(cols.tolist, '__call__'):
        return cols.tolist()

    # make it a list implicitly, make no guarantees about elements
    return [c for c in cols] 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:21,代码来源:util.py

示例3: validate_x

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def validate_x(x):
    """Given an iterable or None, ``x``, validate that if
    it is an iterable, it only contains string types.

    Parameters
    ----------

    x : None or iterable, shape=(n_features,)
        The feature names


    Returns
    -------

    x : None or iterable, shape=(n_features,)
        The feature names
    """
    if x is not None:
        # validate feature_names
        if not (is_iterable(x) and all([isinstance(i, six.string_types) for i in x])):
            raise TypeError('x must be an iterable of strings. '
                            'Got %s' % str(x))

    return x 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:26,代码来源:base.py

示例4: _val_values

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _val_values(vals):
    """Validate that all values in the iterable
    are either numeric, or in ('mode', 'median', 'mean').
    If not, will raise a TypeError

    Raises
    ------

    ``TypeError`` if not all values are numeric or
    in valid values.
    """
    if not all([
                   (is_numeric(i) or (isinstance(i, six.string_types)) and i in ('mode', 'mean', 'median'))
                   for i in vals
               ]):
        raise TypeError('All values in self.fill must be numeric or in ("mode", "mean", "median"). '
                        'Got: %s' % ', '.join(vals)) 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:19,代码来源:impute.py

示例5: _to_absolute_max_features

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _to_absolute_max_features(max_features, n_features, is_classification=False):
    if max_features is None:
        return n_features
    elif isinstance(max_features, string_types):
        if max_features == "auto":
            return max(1, int(np.sqrt(n_features))) if is_classification else n_features
        elif max_features == 'sqrt':
            return max(1, int(np.sqrt(n_features)))
        elif max_features == "log2":
            return max(1, int(np.log2(n_features)))
        else:
            raise ValueError(
                'Invalid value for max_features. Allowed string '
                'values are "auto", "sqrt" or "log2".')
    elif isinstance(max_features, (numbers.Integral, np.integer)):
        return max_features
    else: # float
        if max_features > 0.0:
            return max(1, int(max_features * n_features))
        else:
            return 0 
开发者ID:IntelPython,项目名称:daal4py,代码行数:23,代码来源:decision_forest.py

示例6: is_iterable

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def is_iterable(x):
    """Determine whether an item is iterable.

    Python 3 introduced the ``__iter__`` functionality to
    strings, making them falsely behave like iterables. This
    function determines whether an object is an iterable given
    the presence of the ``__iter__`` method and that the object
    is *not* a string.

    Parameters
    ----------
    x : int, object, str, iterable, None
        The object in question. Could feasibly be any type.
    """
    if isinstance(x, six.string_types):
        return False
    return hasattr(x, "__iter__") 
开发者ID:PacktPublishing,项目名称:Hands-on-Supervised-Machine-Learning-with-Python,代码行数:19,代码来源:validation.py

示例7: _val_exp_loss_prem

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _val_exp_loss_prem(x, y, z):
    """Takes three strings (or unicode) and cleans them
    for indexing an H2OFrame.

    Parameters
    ----------

    x : str
        exp name

    y : str
        loss name

    z : str
        premium name

    Returns
    -------

    out : tuple
        exp : str
            The name of the exp feature (``x``) 

        loss : str
            The name of the loss feature (``y``)

        prem : str or None
            The name of the prem feature (``z``)
    """
    if not all([isinstance(i, six.string_types) for i in (x, y)]):
        raise TypeError('exposure and loss must be strings or unicode')

    if z is not None:
        if not isinstance(z, six.string_types):
            raise TypeError('premium must be None or string or unicode')

    out = (str(x), str(y), str(z) if z is not None else z)
    return out 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:40,代码来源:grid_search.py

示例8: _kv_str

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _kv_str(k, v):
    k = str(k)  # h2o likes unicode...
    # likewise, if the v is unicode, let's make it a string.
    v = v if not isinstance(v, six.string_types) else str(v)
    return k, v 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:7,代码来源:grid_search.py

示例9: _val_y

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _val_y(y):
    if isinstance(y, six.string_types):
        return str(y)
    elif y is None:
        return y
    raise TypeError('y must be a string. Got %s' % y) 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:8,代码来源:split.py

示例10: _validate_target

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _validate_target(y):
    if (not y) or (not isinstance(y, six.string_types)):
        raise ValueError('y must be a column name')
    return str(y)  # force string 
开发者ID:tgsmith61591,项目名称:skutil,代码行数:6,代码来源:balance.py

示例11: _check_stop_list

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _check_stop_list(stop):
    if stop == "english":
        return ENGLISH_STOP_WORDS
    elif isinstance(stop, six.string_types):
        raise ValueError("not a built-in stop list: %s" % stop)
    elif stop is None:
        return None
    else:  # assume it's a collection
        return frozenset(stop) 
开发者ID:prozhuchen,项目名称:2016CCF-sougou,代码行数:11,代码来源:STFIWF.py

示例12: __getitem__

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def __getitem__(self, key):
        if (isinstance(key, string_types) or
                (isinstance(key, (tuple, list)) and
                 any(isinstance(x, string_types) for x in key))):
            msg = "Features indexing only subsets rows, but got {!r}"
            raise TypeError(msg.format(key))

        if np.isscalar(key):
            return self.features[key]
        else:
            return type(self)(self.features[key], copy=False, stack=False,
                              **{k: v[key] for k, v in iteritems(self.meta)}) 
开发者ID:djsutherland,项目名称:skl-groups,代码行数:14,代码来源:features.py

示例13: get_memory

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def get_memory(memory):
    if isinstance(memory, string_types):
        return Memory(memory, verbose=0)
    return memory 
开发者ID:djsutherland,项目名称:skl-groups,代码行数:6,代码来源:transform.py

示例14: _daal4py_compute_starting_centroids

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _daal4py_compute_starting_centroids(X, X_fptype, nClusters, cluster_centers_0, random_state):

    def is_string(s, target_str):
        return isinstance(s, string_types) and s == target_str

    deterministic = False
    if is_string(cluster_centers_0, 'k-means++'):
        _seed = random_state.randint(np.iinfo('i').max)
        daal_engine = daal4py.engines_mt19937(fptype=X_fptype, method='defaultDense', seed=_seed)
        _n_local_trials = 2 + int(np.log(nClusters))
        kmeans_init = daal4py.kmeans_init(nClusters, fptype=X_fptype,
                                          nTrials=_n_local_trials, method='plusPlusDense', engine=daal_engine)
        kmeans_init_res = kmeans_init.compute(X)
        centroids_ = kmeans_init_res.centroids
    elif is_string(cluster_centers_0, 'random'):
        _seed = random_state.randint(np.iinfo('i').max)
        daal_engine = daal4py.engines_mt19937(seed=_seed, fptype=X_fptype, method='defaultDense')
        kmeans_init = daal4py.kmeans_init(nClusters, fptype=X_fptype, method='randomDense', engine=daal_engine)
        kmeans_init_res = kmeans_init.compute(X)
        centroids_ = kmeans_init_res.centroids
    elif hasattr(cluster_centers_0, '__array__'):
        deterministic = True
        cc_arr = np.ascontiguousarray(cluster_centers_0, dtype=X.dtype)
        _validate_center_shape(X, nClusters, cc_arr)
        centroids_ = cc_arr
    elif callable(cluster_centers_0):
        cc_arr = cluster_centers_0(X, nClusters, random_state)
        cc_arr = np.ascontiguousarray(cc_arr, dtype=X.dtype)
        _validate_center_shape(X, nClusters, cc_arr)
        centroids_ = cc_arr
    elif is_string(cluster_centers_0, 'deterministic'):
        deterministic = True
        kmeans_init = daal4py.kmeans_init(nClusters, fptype=X_fptype, method='defaultDense')
        kmeans_init_res = kmeans_init.compute(X)
        centroids_ = kmeans_init_res.centroids
    else:
        raise ValueError("Cluster centers should either be 'k-means++', 'random', 'deterministic' or an array")
    return deterministic, centroids_ 
开发者ID:IntelPython,项目名称:daal4py,代码行数:40,代码来源:_k_means_0_21.py

示例15: _validate_activation_optimization

# 需要导入模块: from sklearn.externals import six [as 别名]
# 或者: from sklearn.externals.six import string_types [as 别名]
def _validate_activation_optimization(activation_function, learning_function):
    """Given the keys for the activation function and the learning function
    get the appropriate TF callable. The reason we store and pass around strings
    is so the models can be more easily pickled (and don't attempt to pickle a
    non-instance method)

    Parameters
    ----------
    activation_function : str
        The key for the activation function

    learning_function : str
        The key for the learning function.

    Returns
    -------
    activation : callable
        The activation function

    learning : callable
        The learning function.
    """
    if isinstance(activation_function, six.string_types):
        activation = PERMITTED_ACTIVATIONS.get(activation_function, None)
        if activation is None:
            raise ValueError('Permitted activation functions: %r' % list(PERMITTED_ACTIVATIONS.keys()))
    else:
        raise TypeError('Activation function must be a string')

    # validation optimization function:
    if isinstance(learning_function, six.string_types):
        learning = PERMITTED_OPTIMIZERS.get(learning_function, None)
        if learning is None:
            raise ValueError('Permitted learning functions: %r' % list(PERMITTED_OPTIMIZERS.keys()))
    else:
        raise TypeError('Learning function must be a string')

    return activation, learning 
开发者ID:tgsmith61591,项目名称:smrt,代码行数:40,代码来源:autoencoder.py


注:本文中的sklearn.externals.six.string_types方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。