本文整理汇总了Python中sklearn.externals.joblib.load方法的典型用法代码示例。如果您正苦于以下问题:Python joblib.load方法的具体用法?Python joblib.load怎么用?Python joblib.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.externals.joblib
的用法示例。
在下文中一共展示了joblib.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_mood
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def get_mood(sentence, key_word, model_name):
feature = _get_feature(sentence, key_word)
gnb = joblib.load(model_name)
pre_y = gnb.predict([feature])
result = {
"positive": 0,
"negative": 0,
"neutral": 0
}
try:
if pre_y[0] == POSITIVE:
result["positive"] = 1
elif pre_y[0] == NEGATIVE:
result["negative"] = 1
elif pre_y[0] == NEUTRAL:
result["neutral"] = 1
except:
pass
return result
示例2: try_resume
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def try_resume(filename):
""" Return True/False if dataset has already been classified
Args:
filename (str): filename of the result to be checked
Returns:
bool: If the `npz` file exists and contains a file 'class', this test
will return True, else False.
"""
try:
z = np.load(filename)
except:
return False
if not z['record'].dtype or 'class' not in z['record'].dtype.names:
return False
return True
示例3: load_model
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load_model(net_func, device, output_path, start_epoch):
if start_epoch == 0:
list_of_models = [net_func().to(device) for _ in range(bundle_size)]
models = MyNet.NetList(list_of_models)
fn = '%s/epoch%02d_bundled_models%02d.dat' % (output_path, 0, 0)
models.load_state_dict(torch.load(fn))
model = models.models[0]
optimizer = torch.optim.SGD(model.parameters(), lr=lr, momentum=momentum)
else:
fn = '%s/epoch%02d_final_model.dat' % (output_path, start_epoch-1)
model = net_func().to(device)
model.load_state_dict(torch.load(fn))
fn = '%s/epoch%02d_final_optimizer.dat' % (output_path, start_epoch-1)
optimizer = torch.optim.SGD(model.parameters(), lr=lr, momentum=momentum)
optimizer.load_state_dict(torch.load(fn))
return model, optimizer
示例4: get_mood
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def get_mood(sentence, key_word, model_name):
feature = _get_feature(sentence, key_word)
gnb = joblib.load(model_name)
pre_y = gnb.predict([feature])
result = {
"positive":0,
"negative":0,
"neutral":0
}
try:
if pre_y[0] == POSITIVE:
result["positive"] = 1
elif pre_y[0] == NEGATIVE:
result["negative"] = 1
elif pre_y[0] == NEUTRAL:
result["neutral"] = 1
except:
pass
return result
示例5: load
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load(self):
"""
Loads the SVM model from the disk.
Returns
-------
ret: bool
Indication on if the loading was succeeded or not.
"""
try:
clf = joblib.load(self._modelFile)
except:
return False
self._clf = clf
return True
#---------------------------------------------
示例6: load_from_disk
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load_from_disk(filename):
"""Load a dataset from file."""
name = filename
if os.path.splitext(name)[1] == ".gz":
name = os.path.splitext(name)[0]
if os.path.splitext(name)[1] == ".pkl":
return load_pickle_from_disk(filename)
elif os.path.splitext(name)[1] == ".joblib":
try:
return joblib.load(filename)
except KeyError:
# Try older joblib version for legacy files.
return old_joblib.load(filename)
except ValueError:
return old_joblib.load(filename)
elif os.path.splitext(name)[1] == ".csv":
# First line of user-specified CSV *must* be header.
df = pd.read_csv(filename, header=0)
df = df.replace(np.nan, str(""), regex=True)
return df
else:
raise ValueError("Unrecognized filetype for %s" % filename)
示例7: load_cv_dataset_from_disk
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load_cv_dataset_from_disk(save_dir, fold_num):
assert fold_num > 1
loaded = False
train_data = []
valid_data = []
for i in range(fold_num):
fold_dir = os.path.join(save_dir, "fold" + str(i + 1))
train_dir = os.path.join(fold_dir, "train_dir")
valid_dir = os.path.join(fold_dir, "valid_dir")
if not os.path.exists(train_dir) or not os.path.exists(valid_dir):
return False, None, list()
train = dcCustom.data.DiskDataset(train_dir)
valid = dcCustom.data.DiskDataset(valid_dir)
train_data.append(train)
valid_data.append(valid)
loaded = True
with open(os.path.join(save_dir, "transformers.pkl"), 'rb') as f:
transformers = pickle.load(f)
return loaded, list(zip(train_data, valid_data)), transformers
示例8: __init__
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def __init__(self, acc_model, don_model, features_path=None):
self.don_model = joblib.load(don_model)
self.acc_model = joblib.load(acc_model)
if features_path is None:
features_path = os.path.join(this_dir, "../features.json")
self.features_metadata = read_json(features_path)
# acceptor and donor site indexes are unified across SOI
# NB! This indexes are pos=1 of the region, and index-1 is already pos=-1, not 0!
self.don_i = 3
self.acc_i = -21
self.labranchor = kipoi.get_model("labranchor", with_dataloader=False)
# add current dir to python path for multiprocessing
sys.path.append(this_dir)
示例9: __init__
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def __init__(self, acc_model, don_model, features_path=None):
self.don_model = joblib.load(don_model)
self.acc_model = joblib.load(acc_model)
if features_path is None:
features_path = os.path.join(this_dir, "../features.json")
self.features_metadata = read_json(features_path)
# acceptor and donor site indexes are unified across SOI
# NB! This indexes are pos=1 of the region, and index-1 is already pos=-1, not 0!
self.don_i = 3
self.acc_i = -21
# add current dir to python path for multiprocessing
sys.path.append(this_dir)
示例10: load
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load(self, model_fname):
"""
Load the model from the file.
Args:
model_fname (str): Filename of the model.
"""
self.model = joblib.load(model_fname)
示例11: load
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load(self, filepath):
self.embedding_matrix = joblib.load(filepath)
return self
示例12: load
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load(self, filepath):
object_pickle = joblib.load(filepath)
self.char_level = object_pickle['char_level']
self.maxlen = object_pickle['maxlen']
self.num_words = object_pickle['num_words']
self.tokenizer = object_pickle['tokenizer']
return self
示例13: load
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load(self, filepath):
return ClassPredictor()
示例14: load
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load(self, filepath):
self.estimator = joblib.load(filepath)
return self
示例15: load
# 需要导入模块: from sklearn.externals import joblib [as 别名]
# 或者: from sklearn.externals.joblib import load [as 别名]
def load(self, filepath):
return self