當前位置: 首頁>>代碼示例>>Python>>正文


Python joblib.Memory方法代碼示例

本文整理匯總了Python中sklearn.externals.joblib.Memory方法的典型用法代碼示例。如果您正苦於以下問題:Python joblib.Memory方法的具體用法?Python joblib.Memory怎麽用?Python joblib.Memory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.externals.joblib的用法示例。


在下文中一共展示了joblib.Memory方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fetch_asirra

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def fetch_asirra(image_count=1000):
    """

    Parameters
    ----------
    image_count : positive integer

    Returns
    -------
    data : Bunch
        Dictionary-like object with the following attributes :
        'images', the sample images, 'data', the flattened images,
        'target', the label for the image (0 for cat, 1 for dog),
        and 'DESCR' the full description of the dataset.
    """
    partial_path = check_fetch_asirra()
    m = Memory(cachedir=partial_path, compress=6, verbose=0)
    load_func = m.cache(_fetch_asirra)
    images, target = load_func(partial_path, image_count=image_count)
    return Bunch(data=images.reshape(len(images), -1),
                 images=images, target=target,
                 DESCR="Asirra cats and dogs dataset") 
開發者ID:sklearn-theano,項目名稱:sklearn-theano,代碼行數:24,代碼來源:asirra.py

示例2: transform

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def transform(self, X):
        """Extract features from the array X.

        Parameters
        ----------
        X : ndarray, shape (n_epochs, n_channels, n_times)

        Returns
        -------
        Xnew : ndarray, shape (n_epochs, n_features)
            Extracted features.
        """
        mem = joblib.Memory(location=self.memory)
        _extractor = mem.cache(extract_features)
        return _extractor(X, self.sfreq, self.selected_funcs,
                          funcs_params=self.params, n_jobs=self.n_jobs) 
開發者ID:mne-tools,項目名稱:mne-features,代碼行數:18,代碼來源:feature_extraction.py

示例3: __init__

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def __init__(self,
                 mask=None, smoothing_fwhm=None,
                 standardize=True, detrend=True,
                 low_pass=None, high_pass=None, t_r=None,
                 target_affine=None, target_shape=None,
                 mask_strategy='epi', mask_args=None,
                 memory=Memory(cachedir=None),
                 memory_level=2,
                 n_jobs=1, verbose=0, ):
        self.mask = mask
        self.smoothing_fwhm = smoothing_fwhm
        self.standardize = standardize
        self.detrend = detrend
        self.low_pass = low_pass
        self.high_pass = high_pass
        self.t_r = t_r
        self.target_affine = target_affine
        self.target_shape = target_shape
        self.mask_strategy = mask_strategy
        self.mask_args = mask_args
        self.memory = memory
        self.memory_level = memory_level
        self.n_jobs = n_jobs
        self.verbose = verbose 
開發者ID:arthurmensch,項目名稱:modl,代碼行數:26,代碼來源:base.py

示例4: __init__

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def __init__(self, mask_img=None, smoothing_fwhm=None,
                 standardize=False, detrend=False,
                 low_pass=None, high_pass=None, t_r=None,
                 target_affine=None, target_shape=None,
                 mask_strategy='background', mask_args=None,
                 memory=Memory(cachedir=None), memory_level=0,
                 n_jobs=1, verbose=0
                 ):
        # Mask is provided or computed
        MultiNiftiMasker.__init__(self, mask_img=mask_img, n_jobs=n_jobs,
                                  smoothing_fwhm=smoothing_fwhm,
                                  standardize=standardize, detrend=detrend,
                                  low_pass=low_pass,
                                  high_pass=high_pass, t_r=t_r,
                                  target_affine=target_affine,
                                  target_shape=target_shape,
                                  mask_strategy=mask_strategy,
                                  mask_args=mask_args,
                                  memory=memory,
                                  memory_level=memory_level,
                                  verbose=verbose) 
開發者ID:arthurmensch,項目名稱:modl,代碼行數:23,代碼來源:unmask.py

示例5: cluster_all_options

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def cluster_all_options(self,original_track_ys):
    total_clustering_start = time.time()
    num_outputs_already_saved = len(os.listdir(self.output_folder + "tree_cache/"))
    savedMemory = Memory(self.output_folder + "tree_cache/" + str(num_outputs_already_saved).zfill(4) + "/")
    num_outputs_already_saved = len(os.listdir(self.output_folder + "tests/"))
    self.test_output_file = self.output_folder + "tests/" + str(num_outputs_already_saved).zfill(3) + "/"

    for n_components in [8, 12, 16, 24, 32, 48, 64, 96, 128]:
      start_this_dimensions = time.time()
      pca = PCA(n_components=n_components)
      track_ys = pca.fit_transform(original_track_ys)
      for min_samples in range(6, 51, 2):
        start_this_run = time.time()
        for min_cluster_size in range(6, 51, 2):
          cluster_ids, _,_ = self.cluster_and_classify(track_ys, None, (n_components, min_cluster_size, min_samples), savedMemory)
          cluster_class_list, cluster_class_counts = self.create_cluster_class_lists(cluster_ids, track_classes)
          self.write_summary(cluster_ids, cluster_class_list, cluster_class_counts,
                             (n_components, min_cluster_size, min_samples))
        print("this run elapsed =", time.time() - start_this_run, file=log.v5)
      print("this dimensionality elapsed =", time.time() - start_this_dimensions, file=log.v5)
    print("total clustering elapsed =", time.time() - total_clustering_start, file=log.v5)

    return 
開發者ID:JonathonLuiten,項目名稱:PReMVOS,代碼行數:25,代碼來源:ClusteringForwarder_old.py

示例6: __init__

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def __init__(self, mask_img=None, smoothing_fwhm=None,
                 memory=Memory(None), memory_level=1, verbose=0,
                 n_jobs=1, minimize_memory=True):
        self.mask_img = mask_img
        self.smoothing_fwhm = smoothing_fwhm
        if isinstance(memory, _basestring):
            self.memory = Memory(memory)
        else:
            self.memory = memory
        self.memory_level = memory_level
        self.verbose = verbose
        self.n_jobs = n_jobs
        self.minimize_memory = minimize_memory
        self.second_level_input_ = None
        self.confounds_ = None 
開發者ID:nilearn,項目名稱:nistats,代碼行數:17,代碼來源:second_level_model.py

示例7: load_image

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def load_image(source,
               scale=1,
               gray=False,
               memory=Memory(cachedir=None)):
    data_dir = get_data_dirs()[0]
    if source == 'face':
        image = face(gray=gray)
        image = image.astype(np.float32) / 255
        if image.ndim == 2:
            image = image[..., np.newaxis]
        if scale != 1:
            image = memory.cache(rescale)(image, scale=scale)
        return image
    elif source == 'lisboa':
        image = imread(join(data_dir, 'images', 'lisboa.jpg'), as_grey=gray)
        image = image.astype(np.float32) / 255
        if image.ndim == 2:
            image = image[..., np.newaxis]
        if scale != 1:
            image = memory.cache(rescale)(image, scale=scale)
        return image
    elif source == 'aviris':
        from spectral import open_image

        image = open_image(
            join(data_dir,
                 'aviris',
                 'f100826t01p00r05rdn_b/'
                 'f100826t01p00r05rdn_b_sc01_ort_img.hdr'))
        image = np.array(image.open_memmap(), dtype=np.float32)
        good_bands = list(range(image.shape[2]))
        good_bands.remove(110)
        image = image[:, :, good_bands]
        indices = image == -50
        image[indices] = -1
        image[~indices] -= np.min(image[~indices])
        image[~indices] /= np.max(image[~indices])
        return image
    else:
        raise ValueError('Data source is not known') 
開發者ID:arthurmensch,項目名稱:modl,代碼行數:42,代碼來源:image.py

示例8: test_dict_fact

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def test_dict_fact(method, memory):
    if memory:
        memory = Memory(cachedir=get_cache_dirs()[0])
        memory_level = 2
    else:
        if method != 'masked':
            pytest.skip()
        memory = Memory(cachedir=None)
        memory_level = 0
    data, mask_img, components, init = _make_test_data(n_subjects=10)
    dict_fact = fMRIDictFact(n_components=4, random_state=0,
                             memory=memory,
                             memory_level=memory_level,
                             mask=mask_img,
                             dict_init=init,
                             method=method,
                             reduction=2,
                             smoothing_fwhm=None, n_epochs=2, alpha=1)
    dict_fact.fit(data)
    maps = np.rollaxis(dict_fact.components_img_.get_data(), 3, 0)
    components = np.rollaxis(components.get_data(), 3, 0)
    maps = maps.reshape((maps.shape[0], -1))
    components = components.reshape((components.shape[0], -1))

    S = np.sqrt(np.sum(components ** 2, axis=1))
    S[S == 0] = 1
    components /= S[:, np.newaxis]

    S = np.sqrt(np.sum(maps ** 2, axis=1))
    S[S == 0] = 1
    maps /= S[:, np.newaxis]

    G = np.abs(components.dot(maps.T))

    recovered_maps = np.sum(G > 0.95)
    assert (recovered_maps >= 4) 
開發者ID:arthurmensch,項目名稱:modl,代碼行數:38,代碼來源:test_fmri.py

示例9: __init__

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def __init__(self,
                 n_components=20,
                 alpha=0.1,
                 dict_init=None,
                 transform_batch_size=None,
                 mask=None, smoothing_fwhm=None,
                 standardize=True, detrend=True,
                 low_pass=None, high_pass=None, t_r=None,
                 target_affine=None, target_shape=None,
                 mask_strategy='background', mask_args=None,
                 memory=Memory(cachedir=None),
                 memory_level=2,
                 n_jobs=1, verbose=0, ):
        BaseNilearnEstimator.__init__(self,
                                      mask=mask,
                                      smoothing_fwhm=smoothing_fwhm,
                                      standardize=standardize,
                                      detrend=detrend,
                                      low_pass=low_pass,
                                      high_pass=high_pass,
                                      t_r=t_r,
                                      target_affine=target_affine,
                                      target_shape=target_shape,
                                      mask_strategy=mask_strategy,
                                      mask_args=mask_args,
                                      memory=memory,
                                      memory_level=memory_level,
                                      n_jobs=n_jobs,
                                      verbose=verbose)

        self.n_components = n_components
        self.transform_batch_size = transform_batch_size
        self.dict_init = dict_init
        self.alpha = alpha 
開發者ID:arthurmensch,項目名稱:modl,代碼行數:36,代碼來源:fmri.py

示例10: __init__

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def __init__(self, div_funcs=('kl',), Ks=(3,), do_sym=False, n_jobs=1,
                 clamp=True, min_dist=1e-3,
                 flann_algorithm='auto', flann_args=None, version='best',
                 memory=Memory(cachedir=None, verbose=0)):
        self.div_funcs = div_funcs
        self.Ks = Ks
        self.do_sym = do_sym
        self.n_jobs = n_jobs
        self.clamp = clamp
        self.min_dist = min_dist
        self.flann_algorithm = flann_algorithm
        self.flann_args = flann_args
        self.version = version
        self.memory = memory 
開發者ID:djsutherland,項目名稱:skl-groups,代碼行數:16,代碼來源:knn.py

示例11: get_memory

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def get_memory(memory):
    if isinstance(memory, string_types):
        return Memory(memory, verbose=0)
    return memory 
開發者ID:djsutherland,項目名稱:skl-groups,代碼行數:6,代碼來源:transform.py

示例12: __init__

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def __init__(self, min_eig=0, copy=True, negatives_likely=True,
                 memory=Memory(cachedir=None, verbose=0)):
        self.min_eig = min_eig
        self.copy = copy
        self.negatives_likely = negatives_likely
        self.memory = memory 
開發者ID:djsutherland,項目名稱:skl-groups,代碼行數:8,代碼來源:transform.py

示例13: test_pipeline_wrong_memory

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def test_pipeline_wrong_memory():
    # Test that an error is raised when memory is not a string or a Memory
    # instance
    iris = load_iris()
    X = iris.data
    y = iris.target
    # Define memory as an integer
    memory = 1
    cached_pipe = Pipeline([('transf', DummyTransf()), ('svc', SVC())],
                           memory=memory)
    assert_raises_regex(ValueError, "'memory' should be None, a string or"
                        " have the same interface as "
                        "sklearn.externals.joblib.Memory."
                        " Got memory='1' instead.", cached_pipe.fit, X, y) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:16,代碼來源:test_pipeline.py

示例14: test_pipeline_with_cache_attribute

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def test_pipeline_with_cache_attribute():
    X = np.array([[1, 2]])
    pipe = Pipeline([('transf', Transf()), ('clf', Mult())],
                    memory=DummyMemory())
    pipe.fit(X, y=None)
    dummy = WrongDummyMemory()
    pipe = Pipeline([('transf', Transf()), ('clf', Mult())],
                    memory=dummy)
    assert_raises_regex(ValueError, "'memory' should be None, a string or"
                        " have the same interface as "
                        "sklearn.externals.joblib.Memory."
                        " Got memory='{}' instead.".format(dummy), pipe.fit, X) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:14,代碼來源:test_pipeline.py

示例15: test_make_pipeline_memory

# 需要導入模塊: from sklearn.externals import joblib [as 別名]
# 或者: from sklearn.externals.joblib import Memory [as 別名]
def test_make_pipeline_memory():
    cachedir = mkdtemp()
    memory = Memory(cachedir=cachedir)
    pipeline = make_pipeline(DummyTransf(), SVC(), memory=memory)
    assert_true(pipeline.memory is memory)
    pipeline = make_pipeline(DummyTransf(), SVC())
    assert_true(pipeline.memory is None)

    shutil.rmtree(cachedir) 
開發者ID:alvarobartt,項目名稱:twitter-stock-recommendation,代碼行數:11,代碼來源:test_pipeline.py


注:本文中的sklearn.externals.joblib.Memory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。