Skip to content

Instantly share code, notes, and snippets.

View sciencelee's full-sized avatar

Aaron Lee sciencelee

View GitHub Profile
import requests
post_data = [{
"0":5,
"1":8,
"2":15
}]
#url = 'https://square-flask-api.herokuapp.com/square/'
url = ' http://127.0.0.1:5000/square/'
from flask import Flask, jsonify, request
# create app
app = Flask(__name__, static_folder='static')
# routes
@app.route('/square/', methods=['POST'])
def square():
# get data
data = request.get_json()[0]
from flask import Flask, jsonify, request, make_response
import flask_cors
# create app
app = Flask(__name__, static_folder='static')
cors = flask_cors.CORS(app, resources={r"/api/*": {"origins": "*"}})
# routes
@app.route('/square/', methods=['POST', 'OPTIONS'])
@flask_cors.cross_origin()
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
# create my NN model
model = Sequential()
embedding_size = 128
model.add(Embedding(len(total_vocabulary), embedding_size))
model.add(LSTM(25, return_sequences=True))
from keras.preprocessing.sequence import pad_sequences
from keras.layers import Input, Dense, LSTM, Embedding
from keras.layers import Dropout, Activation, Bidirectional, GlobalMaxPool1D
from keras.models import Sequential
from keras import initializers, regularizers, constraints, optimizers, layers
from keras.preprocessing import text, sequence
# set the emotion/sentiment as our target
target = df['emotion']
import pandas as pd
from nltk import word_tokenize
df = pd.read_csv('judge-1377884607_tweet_product_company.csv')
df = df.rename(columns={"is_there_an_emotion_directed_at_a_brand_or_product": "emotion"})
df = df.dropna(subset=['emotion', 'tweet_text'])
data = df['tweet_text'].map(word_tokenize).values
total_vocabulary = set(word.lower() for tweet in data for word in tweet) # set created from nested comprehension
print('There are {} unique words in the dataset.'.format(len(total_vocabulary)))
print(location.raw)
print(location.address)
print((location.latitude, location.longitude))
import plotly.express as px
df['size'] = 1 # just add a size col to please the mapbox function. Sizes are relative. All 1 means all same size
fig = px.scatter_mapbox(df,
lat="lat",
lon="lon",
zoom=10,
size='size',
size_max=10, # manually set largest size
import pandas as pd
top5 = ['Walter Payton College Prep',
'northside college preparatory high school',
'Jones College Prep',
'Whitney Young High',
'Lane Tech High School',
]
df = pd.DataFrame(top5, columns=['school'])
import pandas as pd
top5 = ['Walter Payton College Prep',
'northside college preparatory high school',
'Jones College Prep',
'Whitney Young High',
'Lane Tech High School',
]
df = pd.DataFrame(top5, columns=['school'])