本文整理匯總了Python中recommender.Recommender.predict方法的典型用法代碼示例。如果您正苦於以下問題:Python Recommender.predict方法的具體用法?Python Recommender.predict怎麽用?Python Recommender.predict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類recommender.Recommender
的用法示例。
在下文中一共展示了Recommender.predict方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: predict
# 需要導入模塊: from recommender import Recommender [as 別名]
# 或者: from recommender.Recommender import predict [as 別名]
def predict():
if request.method == 'GET':
return redirect(url_for('hello'))
# get data from request form, the key is the name you set in your form
url = request.form['url']
if not url:
return render_template("error.html")
url = str(url)
extensions = ['jpg','png','jpeg']
image = False
for ext in extensions:
if ext in url.split('.')[-1].lower():
image = True
if not image:
return render_template("error.html")
r = requests.get(url, headers = {'User-agent': 'Mozilla/5.0'})
if r.status_code != 200:
return render_template("error.html")
img_features = extract_all_features(url, scaler)
text = request.form['title']
max_price = float(request.form['max_price'])
weight = float(request.form['weight'])/100
if text:
label = clf.predict_one(text)
else:
label = -1
if max_price:
price = int(max_price)
else:
price = 1000
features = ['color_pca', 'top_scaled']
weights = [1- weight, weight]
new_image_data = image_data[image_data['price']<=max_price]
if label >= 0:
new_image_data = new_image_data[new_image_data['cluster']==label]
rec = Recommender(new_image_data)
valid = rec.predict(img_features, features, weights)
if not valid:
return render_template("error.html")
rec.top_unique(k=3)
rec_url = rec.similar_img_files
rec_dress = rec.similar_dress_urls
rec_title = rec.similar_titles
rec_price = [format(price,'.2f') for price in rec.similar_price]
similar = zip(rec_url, rec_title, rec_dress, rec_price)
return render_template("predict.html", org_url = url, similar = similar)