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
# three quantiles to rfm values | |
df['r_val'] = pd.qcut(df['recency'], q=3, labels=range(3, 0, -1)) | |
df['f_val'] = pd.qcut(df['frequency'], q=3, labels=range(1, 4)) | |
df['m_val'] = pd.qcut(df['monetary'], q=3, labels=range(1, 4)) | |
# create the segment value | |
df['rfm_val'] = ( | |
df['r_val'].astype(str) + | |
df['f_val'].astype(str) + | |
df['m_val'].astype(str) |
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 py2neo import Graph | |
import pandas as pd | |
host = 'localhost' | |
port = 7687 | |
user = '' | |
password = '' | |
graph = Graph( | |
host=host, |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 Report: | |
def __init__(self, X_test, y_test): | |
self.X = X_test | |
self.y = y_test | |
def metrics(self, model): | |
y_pred = model.predict(self.X) | |
print('Accuracy score:\n') | |
print(accuracy_score(self.y, y_pred)) |
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' | |
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
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
#!/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
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
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') |
NewerOlder