├── LICENSE ├── README.md └── clickstream_analysis.R /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Blendo.co 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ClickstreamAnalysis 2 | This R code is an example of analyzing Clickstream Data using Markov Chains and data mining SPADE algorithm. 3 | 4 | You can find the whole analysis here: https://www.blendo.co/blog/clickstream-data-mining-techniques-introduction/ 5 | 6 | ## Usage 7 | 8 | I have used R version 3.3.3 (2017-03-06) -- "Another Canoe" 9 | 10 | All packages needed are mentioned in the code. 11 | 12 | You just need to import the data as a .csv file, install the required packages and run the code! 13 | 14 | ## License 15 | 16 | The [MIT](https://opensource.org/licenses/MIT) License 17 | -------------------------------------------------------------------------------- /clickstream_analysis.R: -------------------------------------------------------------------------------- 1 | library("clickstream") 2 | library("arulesSequences") 3 | 4 | ## Load Data 5 | cls <- readClickstreams(file = "path_to_file", sep = ",", header = F) 6 | cls 7 | summary(cls) 8 | 9 | ## Fitting Markov Chain 10 | mc <- fitMarkovChain(clickstreamList = cls, order = 3) 11 | options(digits = 2) 12 | 13 | ##compute transition probabilities 14 | mc 15 | options(digits = 7) 16 | summary(mc) 17 | 18 | ##plot transition diagram and heatmap 19 | plot(mc) 20 | hmPlot(mc) 21 | 22 | ##clustering 23 | set.seed(42) 24 | clusters <- clusterClickstreams(clickstreamList = cls, order = 1, centers = 2) 25 | clusters 26 | #To produce the clustering plot of the post in the code of function clusterClickstreams 27 | #add tthe following in line 17: 28 | # ggplot(transitionData, aes(StatesChanged,id, colour=fit$cluster))+geom_point() 29 | summary(clusters) 30 | 31 | #Predict clicks 32 | pattern <- new("Pattern", sequence = c("Action14", "Action4")) 33 | resultPattern <- predict(mc, startPattern = pattern, dist = 1) # set dist = n to predict n steps ahead 34 | resultPattern 35 | 36 | ##cSPACE data mining 37 | frequencyDF <- frequencies(cls) 38 | frequencyDF 39 | trans <- as.transactions(cls) 40 | sequences <- as(cspade(trans, parameter = list(support = 0)), "data.frame") 41 | sequences 42 | --------------------------------------------------------------------------------