Skip to content

Instantly share code, notes, and snippets.

View MemphisMeng's full-sized avatar
💯

Anzhe Meng MemphisMeng

💯
  • Pittsburgh, PA
  • 05:32 (UTC -04:00)
View GitHub Profile
@MemphisMeng
MemphisMeng / merge.py
Last active August 3, 2020 19:27
medium descrption
# "fixtures" is the fixture table containing all the matches that have taken place
# "aggregate" is the set of selected features
fixtures = fixtures.merge(aggregate, left_on='Home', right_on='Squad')
fixtures = fixtures.merge(aggregate, left_on='Away', right_on='Squad', suffixes=('_Home', '_Away'))
from sklearn import preprocessing
from imblearn.over_sampling import RandomOverSampler
le = preprocessing.LabelEncoder()
fixtures['Score'] = le.fit_transform(fixtures['Score'].astype(str))
ros = RandomOverSampler(random_state=42)
fixtures, Score_ = ros.fit_resample(fixtures.drop(columns=['Score']), fixtures['Score'])
fixtures['Score'] = le.inverse_transform(Score_)
proba = {'Manchester City': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Bayern Munich': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Paris Saint-Germain': {'qtr': 300, 'semi': 0, 'final': 0, 'champion': 0},
'Real Madrid': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Juventus': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Lyon': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Barcelona': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Napoli': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Chelsea': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Atalanta': {'qtr': 300, 'semi': 0, 'final': 0, 'champion': 0},
algo = SVD()
trainset = data.build_full_trainset()
algo.fit(trainset)
# Than predict ratings for all pairs (u, i) that are NOT in the training set.
testset = trainset.build_anti_testset()
predictions = algo.test(testset)
# movie profile
movie_profile = movies[['id', 'title', 'genres']]
movie_profile.rename(columns={'id': 'movieId'}, inplace=True)
genres = [item.strip() for l in all_genres for item in l ]
unique_genres = set(genres)
for genre in unique_genres:
movie_profile[genre] = 0
for i in range(len(movie_profile)):
if type(movie_profile['genres'].iloc[i]) != None.__class__:
from collections import Counter
import en_core_web_sm
# preprocessing
nlp = en_core_web_sm.load()
tweet_article = nlp('|'.join(tweets.tweets))
# make sure the entities we need are persons
items = [x.text for x in tweet_article.ents if x.label_ == 'PERSON']
# exclude the obvious misclassified entities
items = [celebrity[0] for celebrity in Counter(items).most_common(20) if
response, similarity = transformer.match_query(message['message'].get('text'))
# no acceptable answers found in the pool
if similarity < 0.5:
response = "Please wait! Our representative is on the way to help you!"
bot.send_text_message(recipient_id, response)
else:
responses = response.split('|')
for r in responses:
if r != '':
# if the request was not get, it must be POST and we can just proceed with sending a message back to user
else:
# get whatever message a user sent the bot
output = request.get_json()
for event in output['entry']:
messaging = event['messaging']
for message in messaging:
if message.get('message'):
# Facebook Messenger ID for user so we know where to send response back to
recipient_id = message['sender']['id']
import os
from pymongo import MongoClient
# define on heroku settings tab
MONGODB_URI = os.environ['MONGODB_URI']
cluster = MongoClient(MONGODB_URI)
db = cluster['QnA']
collection = db['QnA']
from ipywidgets import widgets, interactive, interact, interact_manual