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.ensemble import RandomForestClassifier | |
| from sklearn.pipeline import Pipeline | |
| steps = [ | |
| ("vectorizer", TfidfVectorizer(stop_words=my_stopwords)), | |
| ("rf", RandomForestClassifier()) | |
| ] | |
| # instatiating the pipeline |
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 rake_nltk import Rake | |
| import numpy as np | |
| from sklearn.metrics.pairwise import cosine_similarity | |
| from sklearn.feature_extraction.text import CountVectorizer | |
| df = pd.read_csv('https://query.data.world/s/uikepcpffyo2nhig52xxeevdialfl7') | |
| df = df[['Title','Genre','Director','Actors','Plot']] | |
| df.head() |
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
| # initializing the new column | |
| df['Key_words'] = "" | |
| for index, row in df.iterrows(): | |
| plot = row['Plot'] | |
| # instantiating Rake, by default it uses english stopwords from NLTK | |
| # and discards all puntuation characters as well | |
| r = Rake() |
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
| # instantiating and generating the count matrix | |
| count = CountVectorizer() | |
| count_matrix = count.fit_transform(df['bag_of_words']) | |
| # generating the cosine similarity matrix | |
| cosine_sim = cosine_similarity(count_matrix, count_matrix) |
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
| # creating a Series for the movie titles so they are associated to an ordered numerical | |
| # list I will use in the function to match the indexes | |
| indices = pd.Series(df.index) | |
| # defining the function that takes in movie title | |
| # as input and returns the top 10 recommended movies | |
| def recommendations(title, cosine_sim = cosine_sim): | |
| # initializing the empty list of recommended movies | |
| recommended_movies = [] |
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
| data = [] | |
| for event in event_types: | |
| event_data = dict( | |
| lat = df.loc[df['EVENT_TYPE'] == event,'BEGIN_LAT'], | |
| lon = df.loc[df['EVENT_TYPE'] == event,'BEGIN_LON'], | |
| name = event, | |
| marker = dict(size = 8, opacity = 0.5), | |
| type = 'scattermapbox' | |
| ) | |
| data.append(event_data) |
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
| annotations = [dict( | |
| # text I want to display. I used <br> to break it into two lines | |
| text = 'All US storm events that caused more than $50k of economic damage,<br> from 2000 until today', | |
| # font and border characteristics | |
| font = dict(color = '#FFFFFF', size = 14), borderpad = 10, | |
| # positional arguments | |
| x = 0.05, y = 0.05, xref = 'paper', yref = 'paper', align = 'left', |
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
| layout = dict( | |
| height = 800, | |
| # top, bottom, left and right margins | |
| margin = dict(t = 0, b = 0, l = 0, r = 0), | |
| font = dict(color = '#FFFFFF', size = 11), | |
| paper_bgcolor = '#000000', | |
| mapbox = dict( | |
| # here you need the token from Mapbox | |
| accesstoken = mapbox_access_token, | |
| bearing = 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
| updatemenus=list([ | |
| # drop-down 1: map styles menu | |
| # buttons containes as many dictionaries as many alternative map styles I want to offer | |
| dict( | |
| buttons=list([ | |
| dict( | |
| args=['mapbox.style', 'dark'], | |
| label='Dark', | |
| method='relayout' | |
| ), |