This file contains hidden or 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 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/' | 
  
    
      This file contains hidden or 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 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] | 
  
    
      This file contains hidden or 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 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() | 
  
    
      This file contains hidden or 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.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)) | 
  
    
      This file contains hidden or 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 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'] | 
  
    
      This file contains hidden or 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 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))) | 
  
    
      This file contains hidden or 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
    
  
  
    
  | print(location.raw) | |
| print(location.address) | |
| print((location.latitude, location.longitude)) | 
  
    
      This file contains hidden or 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 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 | 
  
    
      This file contains hidden or 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 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']) | 
  
    
      This file contains hidden or 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 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']) | 
NewerOlder