本文整理汇总了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")
示例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)
示例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
示例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)
示例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
示例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
示例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')
示例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)
示例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
示例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
示例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
示例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
示例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)
示例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)
示例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)