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
Send hex code | |
⌥←Delete = 0x17 - delete word | |
^←Delete = 0x15 - delete line | |
Send escape sequence | |
⌥← = Esc + b = move to left | |
⌥→ = Esc + f = move to right |
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 matplotlib.pyplot as plt | |
import pandas as pd | |
def pie_by_first_n(df, label_col, size_col, other_name='others', n=5): | |
df_sum = df.groupby(label_col)[size_col].sum().reset_index() | |
df_sum = df_sum.sort_values(by=size_col, ascending=False) | |
df2 = df_sum[:n].copy() | |
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 pandas as pd | |
# display full columns | |
pd.set_option('display.max_columns', None) | |
# display full rows | |
pd.set_option('display.max_rows', None) | |
# non-truncated col values | |
pd.set_option('display.max_colwidth', -1) |
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
from oauth2client.service_account import ServiceAccountCredentials | |
import httplib2 | |
import os | |
SCOPE = 'API_SCOPE' | |
ACCOUNT = 'SERVICE_ACCOUNT' | |
KEY = 'KEY_PATH' | |
def initialize(): |
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
from nltk.corpus import stopwords | |
from stemming.porter2 import stem | |
import nltk | |
import re | |
import string | |
nltk.download('punkt') | |
nltk.download('stopwords') | |
default_stopwords = stopwords.words('english') |
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
from rfpimp import permutation_importances | |
from sklearn.base import clone | |
from sklearn.ensemble import RandomForestRegressor | |
from sklearn.metrics import r2_score | |
from sklearn.model_selection import train_test_split | |
import pandas as pd | |
def imp_df(column_names, importances): | |
data = { |
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
#!/usr/bin/env python | |
# encoding: utf-8 | |
import tweepy #https://github.com/tweepy/tweepy | |
import csv | |
#Twitter API credentials | |
consumer_key = "" | |
consumer_secret = "" | |
access_key = "" |
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
cleaned = df.copy() | |
columns = [ | |
'lead_time', | |
'stays_in_weekend_nights', | |
'stays_in_week_nights', | |
'adults', | |
'children', | |
'babies', | |
'adr', |
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
def select(X): | |
selects = [] | |
selector = SelectKBest(chi2, k='all').fit(X, y) | |
scores = selector.scores_ | |
q3 = np.quantile(scores, 0.75) | |
q1 = np.quantile(scores, 0.25) | |
iqr = q3 - q1 | |
threshold = q3 + 1.5 * iqr |
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
def compare(): | |
for is_le in [True, False]: | |
method = 'label encoder' | |
if is_le: | |
selected = df_le[selects_le + ['is_canceled']] | |
else: | |
selected = df_hot[selects_hot + ['is_canceled']] | |
method = 'dummy variables' | |
OlderNewer