This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "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')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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__: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 != '': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ipywidgets import widgets, interactive, interact, interact_manual |
OlderNewer