Skip to content

Instantly share code, notes, and snippets.

View MemphisMeng's full-sized avatar
💯

Anzhe Meng MemphisMeng

💯
  • Pittsburgh, PA
  • 00:43 (UTC -04:00)
View GitHub Profile
def scatterit(week):
"""
Filters and plot the dataframe as a scatter plot of teams' defence performance
Args:
-----
* week (str): the period to filter on, or "Overall" to display the entire season
Returns:
--------
A matplotlib scatter plot
"""
def barit(week, measure):
"""
Filters and plot the dataframe as a bar plot of teams' defence performance
Args:
-----
* week (str): the period to filter on, or "Overall" to display the entire season
* measure (str): the option of measurement
Returns:
--------
A matplotlib bar plot
measure = widgets.Dropdown(
options=['playResult', 'offensePlayResult', 'epa'],
value='playResult',
description='Measure',
)
week = widgets.Dropdown(
options=['Overall', 'Week 1', 'Week 2', 'Week 3', 'Week 4', 'Week 5', 'Week 6', 'Week 7', 'Week 8',
'Week 9', 'Week 10', 'Week 11', 'Week 12', 'Week 13', 'Week 14', 'Week 15', 'Week 16', 'Week 17'],
value='Overall',
description='Period',
# data preparation
plays = pd.read_csv('../input/nfl-big-data-bowl-2021/plays.csv')
games = pd.read_csv('../input/nfl-big-data-bowl-2021/games.csv')
players = pd.read_csv('../input/nfl-big-data-bowl-2021/players.csv')
dataDir = "/kaggle/input/nfl-big-data-bowl-2021/"
weeks = pd.DataFrame(columns=['time', 'x', 'y', 's', 'a', 'dis', 'o', 'dir', 'event', 'nflId',
'displayName', 'jerseyNumber', 'position', 'frameId', 'team', 'gameId',
'playId', 'playDirection', 'route'])
for i in range(1,18):
weeks = pd.concat([weeks, pd.read_csv(dataDir+"week{}.csv".format(i))], ignore_index=True)
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import base64
import os
import re
import math
from matplotlib.offsetbox import OffsetImage, AnnotationBbox
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from ipywidgets import widgets, interactive, interact, interact_manual
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']
# 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']
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 != '':
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