Skip to content

Instantly share code, notes, and snippets.

View nchelaru's full-sized avatar

Nancy Chelaru nchelaru

View GitHub Profile
@nchelaru
nchelaru / rule_mining.R
Last active November 13, 2019 03:53
Association rule mining in R
## Import libraries
library(arules)
library(arulesViz)
## Create rules
assn_rules <- apriori(tData, parameter = list(supp = 0.001, conf=0.9, minlen=3, maxlen=5))
## Filter rules by lift
filtered_rules <- subset(assn_rules, subset = lift > 1.5)
@nchelaru
nchelaru / data_prep_assn_rule.R
Last active November 12, 2019 15:28
Data preparation for association rule mining in R
## Import libraries
library(arulesCBA)
library(arules)
library(ggplot2)
## Discretize "MonthlyCharges" with respect to "Churn"/"No Churn"
df$Binned_MonthlyCharges <- discretizeDF.supervised(Churn ~ ., df[, c('MonthlyCharges', 'Churn')],
method='mdlp')$MonthlyCharges
## Discretize "Tenure" with respect to "Churn"/"No Churn"
@nchelaru
nchelaru / app.py
Created October 23, 2019 14:54
Dash app - deploy to Heroku
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.MINTY])
server = app.server
if __name__ == "__main__":
app.run_server(debug=False)
<br>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<link
rel="stylesheet"
href="https://cdn.rawgit.com/afeld/bootstrap-toc/v1.0.1/dist/bootstrap-toc.min.css"
/>
df['Binned_MonthlyCharges'] = pd.cut(x=df['MonthlyCharges'],
bins=[0, 30, 55, 70, 90, 110, 120],
labels=['$0-30', '$30-55', '$55-70', '$70-90', '$90-110', '$110-120'])
df['Binned_MonthlyCharges'] = df['Binned_MonthlyCharges'].astype('category')
df['Binned_MonthlyCharges'].cat.reorder_categories(['$0-30', '$30-55', '$55-70', '$70-90', '$90-110', '$110-120'],
inplace=True)
kill -9 $(lsof -i:5000 -t) 2> /dev/null
git rm -r --cached .
@nchelaru
nchelaru / PCA_rotation.R
Created June 14, 2019 16:35
PCA rotation in PCAmixdata
## Apply varimax rotation
res.pcarot <- PCArot(res.pcamix,
dim=4,
graph=FALSE)
## Plot components before and after rotation
plot(res.pcamix,
choice="sqload",
coloring.var=TRUE,
axes=c(1, 2),
@nchelaru
nchelaru / indiv_obs_PCAmixdata.R
Last active June 14, 2019 16:18
Plot individual observations in PCAmixdata PC map
## Taken from tutorial at https://cran.r-project.org/web/packages/PCAmixdata/vignettes/PCAmixdata.html
## Import library
library(PCAmixdata)
## Split qualitative and quantitative variables
split <- splitmix(gironde$housing)
X1 <- split$X.quanti
X2 <- split$X.quali