本文整理汇总了Python中sklearn.externals.joblib.load函数的典型用法代码示例。如果您正苦于以下问题:Python load函数的具体用法?Python load怎么用?Python load使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: predict
def predict(self, img_path):
img, positions, pix_data, captcha_type = self.read_img(img_path)
print positions, captcha_type
if positions is None:
print('图像切分错误!')
return None
x = np.array(self.get_pix_list(pix_data, positions, captcha_type))
if captcha_type == 'number':
if self.model is None or os.path.isfile(self.number_model_file):
self.model = joblib.load(self.number_model_file)
else:
raise IOError
elif self.model is None or os.path.isfile(self.symbol_model_file):
self.model = joblib.load(self.symbol_model_file)
else:
raise IOError
predict_label = list()
for i in range(x.shape[0]):
input = x[i, :]
predict_y = self.model.predict(input)[0]
if int(predict_y) >= len(self.number_label_list) or int(predict_y) < 0:
return "", ""
if captcha_type == 'number':
predict_label.append(self.number_label_list[predict_y])
else:
predict_label.append(self.symbol_label_list[predict_y])
return u"".join(predict_label), self.__caculate(predict_label, captcha_type)
开发者ID:xcctbys,项目名称:Captchacrack,代码行数:28,代码来源:captcha_jiangxi.py
示例2: selectFeatures
def selectFeatures(X,t=0):
if(t==0):
selector=joblib.load('selector.pkl')
else:
selector=joblib.load('SelectKBest.pkl')
X_new=selector.transform(X)
return X_new
开发者ID:Zerowxm,项目名称:kdd-cup2009,代码行数:7,代码来源:utils.py
示例3: load_model
def load_model(self, path):
self.clf = joblib.load(os.path.join(path, 'model.pkl'))
with open(os.path.join(path, 'labels.json'), 'r') as fo:
self.labels = Alphabet.from_dict(json.load(fo))
with open(os.path.join(path, 'model_info.json'), 'r') as fo:
self.model_info = json.load(fo)
self.features = joblib.load(os.path.join(path, 'featvec.pkl'))
开发者ID:aclevine,项目名称:ISO-space,代码行数:7,代码来源:sk_classifier.py
示例4: train_classifier
def train_classifier():
pos_feat_path = positive_features_path
neg_feat_path = negative_features_path
model_path = classifier_model_path
feature_vectors = []
labels = []
for feat_path in glob.glob(os.path.join(pos_feat_path, "*.feat")):
fd = joblib.load(feat_path)
print len(fd)
if len(fd):
fd = fd.astype(numpy.object)
feature_vectors.append(fd)
labels.append(1)
for feat_path in glob.glob(os.path.join(neg_feat_path, "*.feat")):
fd = joblib.load(feat_path)
print len(fd)
if len(fd):
fd = fd.astype(numpy.object)
feature_vectors.append(fd)
labels.append(0)
classifier = LinearSVC()
print "Training classifier"
classifier.fit(feature_vectors, labels)
print "Classifier successfully trained"
if not os.path.isdir(os.path.split(model_path)[0]):
os.makedirs(os.path.split(model_path)[0])
joblib.dump(classifier, model_path)
开发者ID:ranveeraggarwal,项目名称:traffic-light-detection,代码行数:32,代码来源:train_classifier.py
示例5: train_pipeline
def train_pipeline(kind, cut, vectorizer, model_trainer, do_cut=False, do_vectorizer=False, record_num=None):
print('reading...')
alltext, accu_label, law_label, time_label = data.read_trainData("./data/data_train.json", record_num)
if do_cut:
print('cutting...')
train_text = cut.cut(alltext)
joblib.dump(train_text, './data/{}_cut_train.txt'.format(cut.name))
print('cleaning...')
cleaner = Cleaner()
cleaned_train_text = cleaner.clean(train_text)
joblib.dump(cleaned_train_text, './data/{}_cut_train_cleaned.txt'.format(cut.name))
else:
print('load existing cut file {}...'.format('./data/{}_cut_train_cleaned.txt'.format(cut.name)))
cleaned_train_text = joblib.load('./data/{}_cut_train_cleaned.txt'.format(cut.name))
vectorizer_name = '{}_{}'.format(cut.name, vectorizer.name)
if do_vectorizer:
print('{} training...'.format(vectorizer_name))
vectorizer = vectorizer.train(cleaned_train_text)
joblib.dump(vectorizer,
'./model/{}/predictor/model/{}_vectorizer.model'.format(model_trainer.name, vectorizer_name))
print('{} vectorizing...'.format(vectorizer))
vec = vectorizer.transform(cleaned_train_text)
joblib.dump(vec, './data/vec_{}.txt'.format(vectorizer_name))
else:
print('load existing vec file {}...'.format('./data/vec_{}.txt'.format(vectorizer_name)))
vec = joblib.load('./data/vec_{}.txt'.format(vectorizer_name))
print('{} training...'.format(kind))
model = model_trainer.train(vec, accu_label)
joblib.dump(model, './model/{}/predictor/model/{}_{}.model'.format(model_trainer.name, vectorizer_name, kind))
开发者ID:ppapaya,项目名称:cail-2018,代码行数:33,代码来源:main.py
示例6: event2semsim
def event2semsim(event):
import os
from sklearn.externals import joblib
if isinstance(event, str):
etype = event
else:
etype = event.type
if etype == "accident":
return joblib.load(os.path.join(
os.getenv("TREC_DATA"),
"semsim", "accidents.norm-stem.lam20.000.pkl"))
elif etype== "earthquake" or etype == "storm" or etype == "impact event":
return joblib.load(
os.path.join(
os.getenv("TREC_DATA"),
"semsim", "natural-disasters.norm-stem.lam20.000.pkl"))
elif etype == "protest" or etype == "riot":
return joblib.load(
os.path.join(
os.getenv("TREC_DATA"),
"semsim", "social-unrest.norm-stem.lam1.000.pkl"))
elif etype == "shooting" or etype == "bombing" or etype == "conflict" or \
etype == "hostage":
return joblib.load(os.path.join(
os.getenv("TREC_DATA"),
"semsim", "terrorism.norm-stem.lam10.000.pkl"))
开发者ID:kedz,项目名称:cuttsum,代码行数:26,代码来源:misc.py
示例7: trainModel
def trainModel():
# 数据预处理
data_train = joblib.load('data/data_train.pkl')
label_train = joblib.load('data/label_train.pkl')
print data_train.shape
clf = svm.SVC(C=1.0, cache_size=200, class_weight=None, coef0=0.1, degree=0.1, gamma=1.0,
kernel='rbf', max_iter=-1, probability=False, random_state=None,
shrinking=True, tol=0.001, verbose=True)
#clf.set_params(kernel='rbf')
print clf
print data_train.shape
print label_train.shape
print 'begin training....'
clf.fit(data_train,label_train)
print 'finish training....'
print clf
joblib.dump(clf, 'model/svm.pkl')
return None
开发者ID:BLKStone,项目名称:EasyPyPR,代码行数:26,代码来源:SVMtrain.py
示例8: train_and_single_label
def train_and_single_label(train_filename, test_filename, clf, pickled):
""" Only return one example ID for each q_id
"""
if pickled:
train_data = joblib.load(train_filename)
test_data = joblib.load(test_filename)
else:
train_data = extract_ibm_data(train_filename)
test_data = extract_ibm_data(test_filename, test_file=True)
X = train_data["data"]
y = train_data["target"]
clf.fit(X, y)
labels = clf.predict(test_data["data"])
# now manipulate the results using test_data['q_id'] to filter the labels
##NEW CODE:
used_qids = []
results = []
for i in range(len(labels)):
if labels[i] == "true":
if not test_data["q_id"][i] in used_qids:
results.append(test_data["id"][i])
used_qids.append(test_data["q_id"][i])
return results
开发者ID:fightentropy01,项目名称:WatsonGMC,代码行数:25,代码来源:contest.py
示例9: getClassifiers
def getClassifiers(self):
if not os.path.exists(self.outDir):
os.mkdir(self.outDir)
outDir = self.outDir + os.sep + "classPickle"
if not os.path.exists(outDir):
os.mkdir(outDir)
class1Save = outDir + os.sep + "classifier1.pkl"
class2Save = outDir + os.sep + "classifier2.pkl"
class1Exists = os.path.exists(class1Save)
class2Exists = os.path.exists(class2Save)
if not (class1Exists and class2Exists):
self._setupTempDir()
self.fitsFiles = [f[:-5] for f in os.listdir(self.fitsFolder) if ".fits" in f]
self.fitsFilesLoc = [os.path.abspath(self.fitsFolder + os.sep + f) for f in os.listdir(self.fitsFolder) if ".fits" in f]
for f in self.fitsFiles:
self.mainCatalog[f] = self.getCatalog(self.fitsFolder + os.sep + f + ".fits", ishape=True)
self.candidateMask[f] = self._getCandidateMask(self.mainCatalog[f], np.loadtxt(self.fitsFolder + os.sep + f + ".txt"))
self.mainCatalog[f] = append_fields(self.mainCatalog[f], 'WEIGHT', self.candidateMask[f] * 1.0, usemask=False)
self.mainCatalog[f] = append_fields(self.mainCatalog[f], 'EXTENDED', self.candidateMask[f], usemask=False)
self.mainCatalog[f] = append_fields(self.mainCatalog[f], 'HLR', np.zeros(self.mainCatalog[f].shape), usemask=False)
self.mainCatalog[f] = append_fields(self.mainCatalog[f], 'MAG', np.zeros(self.mainCatalog[f].shape), usemask=False)
self._trainClassifier()
joblib.dump(self.sc, class1Save)
joblib.dump(self.sc2, class2Save)
else:
self.sc = joblib.load(class1Save)
self.sc2 = joblib.load(class2Save)
#self._testClassifier(catalog, candidateMask)
#self._cleanTempDir()
self._debug("Classifier generated. Now you can invoke .clasify(catalog)")
开发者ID:Samreay,项目名称:GeminiMaffei1,代码行数:35,代码来源:classifier.py
示例10: loadModule
def loadModule(mode):
global movieReviewer
try:
movieReviewer = joblib.load("./SVM/movieReviewer%s.svm" % mode)
except:
import SVMTrain
movieReviewer = joblib.load("./SVM/movieReviewer%s.svm" % mode)
开发者ID:alex-wyc,项目名称:cstuy-ship-projects,代码行数:7,代码来源:SVM.py
示例11: __init__
def __init__(self):
if ("model.pkl" in os.listdir()) and ("enc.pkl" in os.listdir()):
self.model = joblib.load("model.pkl")
self.enc = joblib.load("enc.pkl")
else:
self.refit_from_scratch()
开发者ID:Payback80,项目名称:porn_sieve,代码行数:7,代码来源:predict.py
示例12: load_models
def load_models(path="models",models={}):
x = os.listdir(path)
models = models
for i in x:
try:
if not i.startswith('.') and not i.startswith('_') and os.path.isdir(os.path.join(path, i)):
way = os.path.join(path, i)
clf = glob.glob(os.path.join(way,"clf_*.pkl"))
vec = glob.glob(os.path.join(way,"vectorizer_*.pkl"))
print(". %s"%(way))
if len(clf)!=1 or len(vec)!=1:
print("└── No model found in '%s'. Skipped."%(i))
continue
t0=time()
sys.stdout.flush()
print("├── Loading classifier '%s'..."%(i))
sys.stdout.flush()
if "clf_%s"%(i) not in models:
models["clf_%s"%(i)] = joblib.load(clf[0])
print("├── Done. [%.02fs]"%(time()-t0))
sys.stdout.flush()
t0=time()
print("├── Loading vectorizer '%s'..."%(i))
sys.stdout.flush()
if "vectorizer_%s"%(i) not in models:
models["vectorizer_%s"%(i)] = joblib.load(vec[0])
print("└── Done. [%.02fs]"%(time()-t0))
sys.stdout.flush()
t0=time()
except:
print(">> Error on '%s', skipped."%(i))
return models
开发者ID:m3at,项目名称:Labelizer,代码行数:32,代码来源:tools.py
示例13: roc_precision_final
def roc_precision_final(db, fac=1):
if (os.path.exists(MAT_PATH) == False):
os.mkdir(MAT_PATH)
random_state = check_random_state(0)
print("Loading {}...".format(db))
clf = joblib.load("clfs/" + db)
classes = clf.classes_
print("Loading test set...")
loaded = joblib.load("testSet/" + db)
y_true = loaded[:, -1]
print("Predict proba...")
y_score = clf.predict_proba(loaded[:, 0:-1])
loaded = 0
clf = 0
y_score = y_score[:, classes == 1] * fac
print("ROC...")
if (fac != 1):
db = db + str(fac)
fpr, tpr, thresholds = roc_curve(y_true, y_score)
sio.savemat(MAT_PATH + 'final.roc.' + db + '.mat', {'fpr':fpr, 'tpr':tpr, 'thresholds':thresholds})
print("Precision/Recall...")
precision, recall, thresholds = precision_recall_curve(y_true, y_score)
sio.savemat(MAT_PATH + 'final.precall.' + db + '.mat', {'precision':precision, 'recall':recall, 'thresholds':thresholds})
开发者ID:dtaralla,项目名称:hearthstone,代码行数:31,代码来源:hearthstone_utils.py
示例14: _train
def _train(self, train_data, resources):
sample_length = len(train_data)
dict_status_path = os.path.join(root_dic,
'dict_vectorizer_{}.status'.
format(sample_length))
if os.path.isfile(dict_status_path):
dictVectorizer = joblib.load(dict_status_path)
else:
dictVectorizer = DictVectorizer()
dictVectorizer.fit(train_data[self.features].
fillna(0).
to_dict('record'))
joblib.dump(dictVectorizer, dict_status_path)
tfidf_status_path = os.path.join(root_dic,
'tfidf_vectorizer_{}.status'.
format(sample_length))
if os.path.isfile(tfidf_status_path):
tfidf = joblib.load(tfidf_status_path)
else:
tfidf = TfidfVectorizer(min_df=40, max_features=300)
tfidf.fit(train_data.essay)
joblib.dump(tfidf, tfidf_status_path)
resources['dictVectorizer'] = dictVectorizer
resources['tfidf'] = tfidf
print 'Head Processing Completed'
return train_data, resources
开发者ID:yelite,项目名称:KDD2014,代码行数:28,代码来源:decomposition.py
示例15: cheapskateItems
def cheapskateItems(df):
nonlocal state
print("Making: cheapskateItems")
if state == 1 and os.path.exists('pickleFiles/voucherToArticle.pkl'):
voucherDic = joblib.load('pickleFiles/voucherToArticle.pkl')
elif state == 0 and os.path.exists('pickleFiles/voucherToArticle_test.pkl'):
voucherDic = joblib.load('pickleFiles/voucherToArticle_test.pkl')
else:
voucherDic = {}
vouchers = df.groupby('voucherID')
for idx,voucher in vouchers:
if idx not in voucherDic:
voucherDic[idx] = Counter(voucher['articleID']).most_common()[0][0]
if state == 1:
joblib.dump(voucherDic,'pickleFiles/voucherToArticle.pkl')
else:
joblib.dump(voucherDic,'pickleFiles/voucherToArticle_test.pkl')
articleSet = set(voucherDic.values())
cheapArticle = pd.Series(name='cheapArticle',index=df.index)
for i in df.index:
article = df['articleID'][i]
isCheap = 1 if article in articleSet else 0
cheapArticle.set_value(i,isCheap)
df['cheapArticle'] = cheapArticle
return df
开发者ID:Waffleboy,项目名称:DMC2016,代码行数:26,代码来源:DMC2016.py
示例16: put
def put(self):
startgeocode_json = (request.form['startgeocode'])
endgeocode_json = (request.form['endgeocode'])
tripdistance_json = (request.form['tripdistance'])
import json
startgeocode = json.loads(startgeocode_json)
endgeocode = json.loads(endgeocode_json)
startlat = float(startgeocode['lat'])
startlng = float(startgeocode['lng'])
endlat = float(endgeocode['lat'])
endlng = float(endgeocode['lng'])
tripdist = float(tripdistance_json.split(" ")[0])
hour = int(request.form['hour'])
dayofweek = int(request.form['dayofweek'])
lowspeedclf = joblib.load(os.path.join(APP_STATIC, 'costtime.pkl'))
lowspeedx = [startlat,startlng,endlat,endlng,hour,dayofweek,tripdist]
lowspeedy = int(lowspeedclf.predict(lowspeedx)[0])
tripdurationclf = joblib.load(os.path.join(APP_STATIC, 'trip_duration.pkl'))
tripduration_x = lowspeedx
trip_duration_y = tripdurationclf.predict(tripduration_x)[0]
duration_list = []
lowspeed_list = []
for i in range(24):
x = [startlat,startlng,endlat,endlng,i,dayofweek,tripdist]
duration_list.append([i,int(tripdurationclf.predict(x)[0])])
lowspeed_list.append([i,int(lowspeedclf.predict(x)[0])])
return {"lowspeedtime":lowspeedy, "tripduration":trip_duration_y, "duration_list":duration_list, "lowspeed_list":lowspeed_list}
开发者ID:wstcpyt,项目名称:flask-travel,代码行数:29,代码来源:app.py
示例17: varianceInProductGroups
def varianceInProductGroups(df):
nonlocal state
print("Making: varianceInProductGroups")
if state == 1 and os.path.exists('pickleFiles/colorStd.pkl') and os.path.exists('pickleFiles/sizeStd.pkl'):
sizeStd = joblib.load('pickleFiles/sizeStd.pkl')
colorStd = joblib.load('pickleFiles/colorStd.pkl')
elif state == 0 and os.path.exists('pickleFiles/colorStd_test.pkl') and os.path.exists('pickleFiles/sizeStd_test.pkl'):
sizeStd = joblib.load('pickleFiles/sizeStd_test.pkl')
colorStd = joblib.load('pickleFiles/colorStd_test.pkl')
else:
products = df.groupby('productGroup')
sizeStd, colorStd = {},{}
for idx,product in products:
if idx not in sizeStd or idx not in colorStd:
size = np.std(list(Counter(product['sizeCode']).values()))
color = np.std(list(Counter(product['colorCode']).values()))
sizeStd[idx] = size
colorStd[idx] = color
if state == 1:
joblib.dump(sizeStd,'pickleFiles/sizeStd.pkl')
joblib.dump(colorStd,'pickleFiles/colorStd.pkl')
else:
joblib.dump(sizeStd,'pickleFiles/sizeStd_test.pkl')
joblib.dump(colorStd,'pickleFiles/colorStd_test.pkl')
df['sizeStd'] = df['productGroup'].map(sizeStd)
df['colorStd'] = df['productGroup'].map(colorStd)
return df
开发者ID:Waffleboy,项目名称:DMC2016,代码行数:27,代码来源:DMC2016.py
示例18: load_model
def load_model(model_path):
gen_params_values = joblib.load(model_path+'_gen_params.jl')
for p, v in izip(gen_params, gen_params_values):
p.set_value(v)
discrim_params_values = joblib.load(model_path+'_discrim_params.jl')
for p, v in izip(discrim_params, discrim_params_values):
p.set_value(v)
开发者ID:aaajiao,项目名称:typeface,代码行数:7,代码来源:generate.py
示例19: init_api
def init_api(app, es_util):
# 加载.pkl
model = joblib.load(r'app\rules\modelspkl\knowledge_cart.pkl')
tf_transformer = joblib.load(r'app\rules\modelspkl\knowledge_tf_transformer.pkl')
le = joblib.load(r'app\rules\modelspkl\knowledge_labelencoder.pkl')
@app.route('/ml_error_predict_batch', methods=['POST'])
def error_predict():
parmStr = request.get_data()
paramDict = json.loads(parmStr)
testline = paramDict['index']
"""
获取用户信息
:return: json
"""
auth = Auth()
result = auth.identify(request)
if (result['status']):
test_datas = readDataLine(testline)
if test_datas != None:
test_feature_datas = tf_transformer.transform(test_datas)
# 进行预测
pred = model.predict(test_feature_datas)
result = le.inverse_transform(pred)
print ('预测结果:%s,预测内容:%s' % (result[0], testline))
#logging.debug('预测结果:%s,预测内容:%s' % (result[0], testline))
return result[0]
return "this is None"
else:
return jsonify(result)
开发者ID:jiluhu,项目名称:flask_ml,代码行数:34,代码来源:nlp_error_predict_batch.py
示例20: callback
def callback(ch, method, properties, body):
print(" [x] Received %r" % (body,))
answer = dict()
message = str(body)
features = calculate_features(message[2:-2])
features = np.array(features).reshape(1, -1)
#scaler = StandardScaler()
#features = scaler.fit_transform(features)
file = 'Resources/AGE_model.pkl'
age_model = joblib.load(file)
file = 'Resources/GENDER_model.pkl'
sex_model = joblib.load(file)
answer['age'] = [age_model.predict(features)]
age = answer['age'][0][0:1][0]
age = str(age).replace("\r", "")
age = str(age).replace("\n", "")
answer['gender'] = [sex_model.predict(features)]
gender = answer['gender'][0][0:1][0]
print('Age: ' + str(age) + ', gender: ' + str(gender))
print(" [x] Done")
ch.basic_ack(delivery_tag=method.delivery_tag)
开发者ID:kburaya,项目名称:Gender-and-Age-Estimator,代码行数:26,代码来源:server.py
注:本文中的sklearn.externals.joblib.load函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论