Python – Churn prediction with Graphlab


Churn prediction is the task of identifying whether users are likely to stop using a service, product, or website. With Graphlab toolkit, you can start with raw (or processed) usage metrics and accurately forecast the probability that a given customer will churn.

Introduction

A churn predictor model learns historical user behavior patterns to make an accurate forecast for the probability of no activity in the future (defined as churn).

How is churn defined?

Customer churn can be defined in many ways. In this toolkit, churn is defined to be no activity for a fixed period of time (called the churn_period). Using this definition, a user is said to have churned if there is no activity for a duration of time known as the churn_period (by default, this is set to 30 days). The following figure better illustrates this concept.

Input Data

In the dataset, let us assume that the last timestamp was October 1,

+---------------------+------------+----------+
|     InvoiceDate     | CustomerID | Quantity |
+---------------------+------------+----------+
| 2010-12-01 08:26:00 |   17850    |    6     |
| 2010-12-01 08:26:00 |   17850    |    6     |
| 2010-12-01 08:26:00 |   17850    |    8     |
| 2010-12-01 08:26:00 |   17850    |    6     |
| 2010-12-01 08:26:00 |   17850    |    6     |
| 2010-12-01 08:26:00 |   17850    |    2     |
| 2010-12-01 08:26:00 |   17850    |    6     |
| 2010-12-01 08:28:00 |   17850    |    6     |
| 2010-12-01 08:28:00 |   17850    |    6     |
| 2010-12-01 08:34:00 |   13047    |    32    |
| 2010-12-01 08:34:00 |   13047    |    6     |
| 2010-12-01 08:34:00 |   13047    |    6     |
| 2010-12-01 08:34:00 |   13047    |    8     |
| 2010-12-01 08:34:00 |   13047    |    6     |
| 2010-12-01 08:34:00 |   13047    |    6     |
| 2010-12-01 08:34:00 |   13047    |    3     |
| 2010-12-01 08:34:00 |   13047    |    2     |
| 2010-12-01 08:34:00 |   13047    |    3     |
| 2010-12-01 08:34:00 |   13047    |    3     |
| 2010-12-01 08:34:00 |   13047    |    4     |
+---------------------+------------+----------+
[532618 rows x 5 columns]

If the churn_period is set to 1 month, a churn forecast predicts the probability that a user will have no activity for a 1 month period after October 1, 2011.

https://gist.github.com/duyetdev/034938444f10f466cc02013dd27100fd.js

Source from http://blog.duyet.net/2017/03/python-churn-prediction-with-graphlab.html

Notibar.js


Notibar.js – Lightweight notification bar, no dependency.

https://duyetdev.github.io/notibar.js/notibar.js

    notiBar('notibar.js by duyetdev  :))');

See example: https://duyetdev.github.io/notibar.js/example.html

More custom

notiBar({
    message: '<strong>notibar.js</strong> by <a href="http://duyetdev.com">duyetdev</a>  :))',
    closeButton: true,
    font: 'sans-serif',
    fontSize: '13px',
    minHeight: '41px',
    color: '#2895F1',
    bgColor: '#f0f9ff',
    borderBottomColor: '#96c4ea',
});

Github: https://github.com/duyetdev/notibar.js

Source from http://blog.duyetdev.com/2017/03/notibarjs.html

[Khảo sát]


Cảm ơn mọi người đã theo dõi từ trước đến giờ, nhiều bạn đã email và inbox.

Bây giờ không có nhiều thời gian nhưng có nhiều topic muốn viết, mình muốn ưu tiên chủ đề mọi người quan tâm nhiều hơn. Do đó mình làm 1 khảo sát đơn giản sau, để quyết định chủ đề tiếp theo sẽ viết là gì?

function resizeIframe(obj) {
obj.style.height = obj.contentWindow.document.body.scrollHeight + ‘px’;
}

function getDocHeight(doc) {
doc = doc || document;
// stackoverflow.com/questions/1145850/
var body = doc.body, html = doc.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight,
html.clientHeight, html.scrollHeight, html.offsetHeight );
return height;
}

function setIframeHeight(id) {
var ifrm = document.getElementById(id);
var doc = ifrm.contentDocument? ifrm.contentDocument:
ifrm.contentWindow.document;
ifrm.style.visibility = ‘hidden’;
ifrm.style.height = “10px”; // reset to minimal height …
// IE opt. for bing/msn needs a bit added or scrollbar appears
ifrm.style.height = getDocHeight( doc ) + 4 + “px”;
ifrm.style.visibility = ‘visible’;
}

document.getElementById(‘survey_iframe’).onload = function() { // Adjust the Id accordingly
setIframeHeight(this.id);
}

https://docs.google.com/forms/d/e/1FAIpQLScCh49f5LR6dCyp5kXRQ6b9aX-8dlbhTgcojamIK7ZSVJJPMQ/viewform?embedded=true

Source from http://blog.duyetdev.com/2017/02/khao-sat.html

Learning R cheatsheet


Getting help:

help(x) or ?x # help on function `x`
example(x)  # print an example of using `x`
??x     # search help for instances of string x
apropos('x') # list all objects with `x` in the name

Types/objects:

mode(x)  # type of an object (storage mode)
str(x)          # display the structure of an object
ls()  # list the objects in the current workspace
rm(x)  # delete the object from curren workspace

File management:

getwd()  # list working directory
setwd('dir')    # set working directory
dir()           # list directories
dir.create(...) # create a directory

Workspace:

save(...)       # save objects to a file
save.image()    # save entire image to a file
load('file')    # load objects written by save

history()        # display last few commands
savehistory('f') # save history to a file
loadhistory('f') # load history from a file

options()       # list available options (globals)
options(x=3)    # set an option
q()             # quit session

Stream management:

source('f') # run commands from file `f`
sink('f', split=TRUE) # Tee output into a file

Package management:

.libPaths()    # dir where are packages saved
installed.packages() # see details/versions/etc.

install.packages() # installation of packages
update.packages()  # updating to latest

library()          # list of installed packages
library(x)    # load package

help(package='x')  # get help on a package

Basic stats/math:

data()          # list available datasets

runif(x) # generate x uniformly distributed numbers
rnorm(x) # generate x normally distributed numbers
summary(x) # print summary info for statistical objects

lm(x~y[, data=z]) # linear regression

integrate(f, i, j) # integrate `f` in range

Plotting basics:

dev.new()       # create new plotting device and set active
def.off()       # delete the last plotting device
png/pdf('x')    # write graphics to a file

hist(x)        # compute a histogram object (and plot by default)
plot(x, y)            # plot `x` against `y`
plot(x~y)             # plot `x` against `y`
plot(x~y, data=z)     # plot `x` against `y` from dataframe
abline(...)           # add a line to plot

curve(dnorm, -4, 4)  # plot a function

Vectors:

x<-c(1, 2, 3)     # constructor
x[1]              # 1-based indexes
x[5]<-5           # expansion
x[c(1,2)]         # get multiple indexes
1:5               # range (inclusive)

Factors:

# efficient storage of low cardinality
factor(c('x', 'y', 'z', 'x'))

Data frames:

data.frame(v1, v2)    # populate a two-column data frame
names(x)<-c('a', 'b') # name the columns

x[2]                  # get a column
x['b']                # get a column
x$b                   # get a column

x[2:3]                # get multiple columns
x[,2:3]               # get multiple columns

with(x, { a })        # refer to a column, save typing

x[2:3,]               # get multiple rows

Source from http://blog.duyetdev.com/2017/02/learning-r-cheatsheet.html

Teleconsole – Chia sẻ remote console


Teleconsole là dịch vụ miễn phí dùng để chia sẻ terminal session với người khác, giống như Teamviewer cho Terminal.

Cài đặt

curl https://www.teleconsole.com/get.sh | sh

Sử dụng

Ở máy A, bật teleconsole

duyetdev@duyetdev:~$ teleconsole 
Starting local SSH server on localhost...
Requesting a disposable SSH proxy on as.teleconsole.com for duyetdev...
Checking status of the SSH tunnel...

Ở máy B, join vào session của máy A

teleconsole join as3b9434bd56d094530a9c002e9b9562c1******

Hoặc mở giao diện Web mà Teleconsole cung cấp

Source from http://blog.duyetdev.com/2017/01/teleconsole.html