R arulessequence - Preparing data for cspade mining
I am trying to mine sequences in R via the arulessequence implementation of cspade.
My data frame looks like this:
items sequenceId eventId size
A 1 1 1
B 2 1 1
C 2 2 1
A 3 1 1
This data frame was created from an existing data set via the following code (removing unnecessary columns and creating the sequences):
data %>%
select(seqId, sequence, items) %>%
group_by(seqId) %>%
mutate(basketSize = 1, sequence = rank(sequence)) %>%
ungroup() %>%
mutate(seqId = ordered(seqId), sequence = ordered(sequence)) %>%
write.table("data.txt", sep=" ", row.names = FALSE, col.names = FALSE, quote = FALSE)
data <- read_baskets("data.txt", info = c("sequenceID", "eventID", "size"))
as(data, "data.frame") #shows the data frame above!
So far so good!
However when I try:
s1 <- cspade(data, parameter = list(support = 0.4), control = list(verbose = TRUE))
I get the following error:
Error in makebin(data, file) : 'eid' invalid (strict order)
I have read elsewhere that this is because cspade needs the event and sequence id to be ordered. But how do I specify this? Clearly ordering the factors before exporting them to ".txt" does not work.
Edit:
Some further details
Just to explain the code to create the data input for cspade a bit more. Originally the sequence-variable had some missing steps (e.g. 1,3,4 for some sequences) because I had filtered some events. Therefore I ran a rank-function on it to reindex the events per sequence. The size-column is totally unecessary (it is constant) but was included in the sample code in the documentation for arulessequence, which is why I included it too.
r sequence arules market-basket-analysis
add a comment |
I am trying to mine sequences in R via the arulessequence implementation of cspade.
My data frame looks like this:
items sequenceId eventId size
A 1 1 1
B 2 1 1
C 2 2 1
A 3 1 1
This data frame was created from an existing data set via the following code (removing unnecessary columns and creating the sequences):
data %>%
select(seqId, sequence, items) %>%
group_by(seqId) %>%
mutate(basketSize = 1, sequence = rank(sequence)) %>%
ungroup() %>%
mutate(seqId = ordered(seqId), sequence = ordered(sequence)) %>%
write.table("data.txt", sep=" ", row.names = FALSE, col.names = FALSE, quote = FALSE)
data <- read_baskets("data.txt", info = c("sequenceID", "eventID", "size"))
as(data, "data.frame") #shows the data frame above!
So far so good!
However when I try:
s1 <- cspade(data, parameter = list(support = 0.4), control = list(verbose = TRUE))
I get the following error:
Error in makebin(data, file) : 'eid' invalid (strict order)
I have read elsewhere that this is because cspade needs the event and sequence id to be ordered. But how do I specify this? Clearly ordering the factors before exporting them to ".txt" does not work.
Edit:
Some further details
Just to explain the code to create the data input for cspade a bit more. Originally the sequence-variable had some missing steps (e.g. 1,3,4 for some sequences) because I had filtered some events. Therefore I ran a rank-function on it to reindex the events per sequence. The size-column is totally unecessary (it is constant) but was included in the sample code in the documentation for arulessequence, which is why I included it too.
r sequence arules market-basket-analysis
add a comment |
I am trying to mine sequences in R via the arulessequence implementation of cspade.
My data frame looks like this:
items sequenceId eventId size
A 1 1 1
B 2 1 1
C 2 2 1
A 3 1 1
This data frame was created from an existing data set via the following code (removing unnecessary columns and creating the sequences):
data %>%
select(seqId, sequence, items) %>%
group_by(seqId) %>%
mutate(basketSize = 1, sequence = rank(sequence)) %>%
ungroup() %>%
mutate(seqId = ordered(seqId), sequence = ordered(sequence)) %>%
write.table("data.txt", sep=" ", row.names = FALSE, col.names = FALSE, quote = FALSE)
data <- read_baskets("data.txt", info = c("sequenceID", "eventID", "size"))
as(data, "data.frame") #shows the data frame above!
So far so good!
However when I try:
s1 <- cspade(data, parameter = list(support = 0.4), control = list(verbose = TRUE))
I get the following error:
Error in makebin(data, file) : 'eid' invalid (strict order)
I have read elsewhere that this is because cspade needs the event and sequence id to be ordered. But how do I specify this? Clearly ordering the factors before exporting them to ".txt" does not work.
Edit:
Some further details
Just to explain the code to create the data input for cspade a bit more. Originally the sequence-variable had some missing steps (e.g. 1,3,4 for some sequences) because I had filtered some events. Therefore I ran a rank-function on it to reindex the events per sequence. The size-column is totally unecessary (it is constant) but was included in the sample code in the documentation for arulessequence, which is why I included it too.
r sequence arules market-basket-analysis
I am trying to mine sequences in R via the arulessequence implementation of cspade.
My data frame looks like this:
items sequenceId eventId size
A 1 1 1
B 2 1 1
C 2 2 1
A 3 1 1
This data frame was created from an existing data set via the following code (removing unnecessary columns and creating the sequences):
data %>%
select(seqId, sequence, items) %>%
group_by(seqId) %>%
mutate(basketSize = 1, sequence = rank(sequence)) %>%
ungroup() %>%
mutate(seqId = ordered(seqId), sequence = ordered(sequence)) %>%
write.table("data.txt", sep=" ", row.names = FALSE, col.names = FALSE, quote = FALSE)
data <- read_baskets("data.txt", info = c("sequenceID", "eventID", "size"))
as(data, "data.frame") #shows the data frame above!
So far so good!
However when I try:
s1 <- cspade(data, parameter = list(support = 0.4), control = list(verbose = TRUE))
I get the following error:
Error in makebin(data, file) : 'eid' invalid (strict order)
I have read elsewhere that this is because cspade needs the event and sequence id to be ordered. But how do I specify this? Clearly ordering the factors before exporting them to ".txt" does not work.
Edit:
Some further details
Just to explain the code to create the data input for cspade a bit more. Originally the sequence-variable had some missing steps (e.g. 1,3,4 for some sequences) because I had filtered some events. Therefore I ran a rank-function on it to reindex the events per sequence. The size-column is totally unecessary (it is constant) but was included in the sample code in the documentation for arulessequence, which is why I included it too.
r sequence arules market-basket-analysis
r sequence arules market-basket-analysis
asked Nov 15 '18 at 17:39
ZeiramZeiram
104
104
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325107%2fr-arulessequence-preparing-data-for-cspade-mining%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53325107%2fr-arulessequence-preparing-data-for-cspade-mining%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown