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
class MyStreamListener(tweepy.StreamListener): | |
def __init__(self, time_limit=300): | |
self.start_time = time.time() | |
self.limit = time_limit | |
super(MyStreamListener, self).__init__() | |
def on_connect(self): | |
print("Connected to Twitter API.") | |
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
# confusion matrix in sklearn | |
from sklearn.metrics import confusion_matrix | |
from sklearn.metrics import classification_report | |
# actual values | |
actual = [1,0,0,1,0,0,1,0,0,1] | |
# predicted values | |
predicted = [1,0,0,1,0,0,0,1,0,0] | |
# confusion matrix |
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 spacy | |
import spacy | |
# load english language model | |
nlp = spacy.load('en_core_web_sm',disable=['ner','textcat']) | |
text = "This is a sample sentence." | |
# create spacy | |
doc = nlp(text) |
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
# data standardization with sklearn | |
from sklearn.preprocessing import StandardScaler | |
# copy of datasets | |
X_train_stand = X_train.copy() | |
X_test_stand = X_test.copy() | |
# numerical features | |
num_cols = ['Item_Weight','Item_Visibility','Item_MRP','Outlet_Establishment_Year'] |
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
# Query stats | |
pprint(db.restaurants.find({'cuisine':'French','grades.score':{'$gt':5}}).explain()['executionStats']) |
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
# Query stats | |
pprint(db.restaurants.find({'cuisine':'American'}).explain()['executionStats']) |
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
pprint(db.restaurants.find().explain()) |
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
# Multiple token search | |
db.restaurants.find_one({"$text": {"$search": "Chinese -Restaurant"}}) |
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
# Multiple token search | |
db.restaurants.find_one({"$text": {"$search": "Chinese Kitchen"}}) |
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
# Find restaurants with Kitchen in their name | |
db.restaurants.find_one({"$text": {"$search": "Kitchen"}}) |