Dataframe subsets retain information from parent dataframe
I assume this is used as a feature in data.frame() but it has presented a lot of problems for evaluating training and test sets for some packages. For example if you utilize h2o for machine learning, import a dataset, and subset the dataframe based on some random sample of the data, the h2o model builder will have access to the FULL original dataframe with all factor levels and all data. As such, if you try something like h2o.predict(model,newdata=dataset[test,]) your prediction will simply copy the response in the dataset over (tested for a deep learning model). You can see the factor retention below:
y = as.factor(c("1","0","0","1"))
X = c(5,4,3,4)
data = data.frame(y,X)
train = data[c(1,4),]
test = data[c(2,3),]
trainingData = data[train,]
trainingData
levels(trainingData[,1])
[1] "0" "1"
Now, I've been able to solve the factor information retention, but I'm not sure how to remove information from the parent dataframe in the new subset. Anyone have any ideas?
EDIT: For anyone who has had the factor problem, it's as simple as applying function droplevels().
r
migrated from stats.stackexchange.com Nov 23 '18 at 18:15
This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.
add a comment |
I assume this is used as a feature in data.frame() but it has presented a lot of problems for evaluating training and test sets for some packages. For example if you utilize h2o for machine learning, import a dataset, and subset the dataframe based on some random sample of the data, the h2o model builder will have access to the FULL original dataframe with all factor levels and all data. As such, if you try something like h2o.predict(model,newdata=dataset[test,]) your prediction will simply copy the response in the dataset over (tested for a deep learning model). You can see the factor retention below:
y = as.factor(c("1","0","0","1"))
X = c(5,4,3,4)
data = data.frame(y,X)
train = data[c(1,4),]
test = data[c(2,3),]
trainingData = data[train,]
trainingData
levels(trainingData[,1])
[1] "0" "1"
Now, I've been able to solve the factor information retention, but I'm not sure how to remove information from the parent dataframe in the new subset. Anyone have any ideas?
EDIT: For anyone who has had the factor problem, it's as simple as applying function droplevels().
r
migrated from stats.stackexchange.com Nov 23 '18 at 18:15
This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.
Standby but I may have come up with a solution. It appears to be an issue arising from coercing an object of type h2o to an object of type vector. However, if you coerce the h2o object back to a dataframe you'll get a dataframe with all information and the predictions which you can extract as always via data[,1]
– Nicklovn
Nov 23 '18 at 18:40
The retention of factor levels is normal, not sure about the h2o specifics.
– Axeman
Nov 23 '18 at 18:45
Yes I know that. I had some trouble some time ago with this but I had solved it then. I mainly used that as an example. Maybe I should've shown the full h2o process to show how h2o will predict for all observations in the original dataframe.
– Nicklovn
Nov 23 '18 at 18:48
OK, I'm voting to close as "no longer reproducible", hope that's ok!
– Axeman
Nov 23 '18 at 18:49
add a comment |
I assume this is used as a feature in data.frame() but it has presented a lot of problems for evaluating training and test sets for some packages. For example if you utilize h2o for machine learning, import a dataset, and subset the dataframe based on some random sample of the data, the h2o model builder will have access to the FULL original dataframe with all factor levels and all data. As such, if you try something like h2o.predict(model,newdata=dataset[test,]) your prediction will simply copy the response in the dataset over (tested for a deep learning model). You can see the factor retention below:
y = as.factor(c("1","0","0","1"))
X = c(5,4,3,4)
data = data.frame(y,X)
train = data[c(1,4),]
test = data[c(2,3),]
trainingData = data[train,]
trainingData
levels(trainingData[,1])
[1] "0" "1"
Now, I've been able to solve the factor information retention, but I'm not sure how to remove information from the parent dataframe in the new subset. Anyone have any ideas?
EDIT: For anyone who has had the factor problem, it's as simple as applying function droplevels().
r
I assume this is used as a feature in data.frame() but it has presented a lot of problems for evaluating training and test sets for some packages. For example if you utilize h2o for machine learning, import a dataset, and subset the dataframe based on some random sample of the data, the h2o model builder will have access to the FULL original dataframe with all factor levels and all data. As such, if you try something like h2o.predict(model,newdata=dataset[test,]) your prediction will simply copy the response in the dataset over (tested for a deep learning model). You can see the factor retention below:
y = as.factor(c("1","0","0","1"))
X = c(5,4,3,4)
data = data.frame(y,X)
train = data[c(1,4),]
test = data[c(2,3),]
trainingData = data[train,]
trainingData
levels(trainingData[,1])
[1] "0" "1"
Now, I've been able to solve the factor information retention, but I'm not sure how to remove information from the parent dataframe in the new subset. Anyone have any ideas?
EDIT: For anyone who has had the factor problem, it's as simple as applying function droplevels().
r
r
edited Nov 23 '18 at 18:20
Nicklovn
asked Nov 23 '18 at 18:12
NicklovnNicklovn
1137
1137
migrated from stats.stackexchange.com Nov 23 '18 at 18:15
This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.
migrated from stats.stackexchange.com Nov 23 '18 at 18:15
This question came from our site for people interested in statistics, machine learning, data analysis, data mining, and data visualization.
Standby but I may have come up with a solution. It appears to be an issue arising from coercing an object of type h2o to an object of type vector. However, if you coerce the h2o object back to a dataframe you'll get a dataframe with all information and the predictions which you can extract as always via data[,1]
– Nicklovn
Nov 23 '18 at 18:40
The retention of factor levels is normal, not sure about the h2o specifics.
– Axeman
Nov 23 '18 at 18:45
Yes I know that. I had some trouble some time ago with this but I had solved it then. I mainly used that as an example. Maybe I should've shown the full h2o process to show how h2o will predict for all observations in the original dataframe.
– Nicklovn
Nov 23 '18 at 18:48
OK, I'm voting to close as "no longer reproducible", hope that's ok!
– Axeman
Nov 23 '18 at 18:49
add a comment |
Standby but I may have come up with a solution. It appears to be an issue arising from coercing an object of type h2o to an object of type vector. However, if you coerce the h2o object back to a dataframe you'll get a dataframe with all information and the predictions which you can extract as always via data[,1]
– Nicklovn
Nov 23 '18 at 18:40
The retention of factor levels is normal, not sure about the h2o specifics.
– Axeman
Nov 23 '18 at 18:45
Yes I know that. I had some trouble some time ago with this but I had solved it then. I mainly used that as an example. Maybe I should've shown the full h2o process to show how h2o will predict for all observations in the original dataframe.
– Nicklovn
Nov 23 '18 at 18:48
OK, I'm voting to close as "no longer reproducible", hope that's ok!
– Axeman
Nov 23 '18 at 18:49
Standby but I may have come up with a solution. It appears to be an issue arising from coercing an object of type h2o to an object of type vector. However, if you coerce the h2o object back to a dataframe you'll get a dataframe with all information and the predictions which you can extract as always via data[,1]
– Nicklovn
Nov 23 '18 at 18:40
Standby but I may have come up with a solution. It appears to be an issue arising from coercing an object of type h2o to an object of type vector. However, if you coerce the h2o object back to a dataframe you'll get a dataframe with all information and the predictions which you can extract as always via data[,1]
– Nicklovn
Nov 23 '18 at 18:40
The retention of factor levels is normal, not sure about the h2o specifics.
– Axeman
Nov 23 '18 at 18:45
The retention of factor levels is normal, not sure about the h2o specifics.
– Axeman
Nov 23 '18 at 18:45
Yes I know that. I had some trouble some time ago with this but I had solved it then. I mainly used that as an example. Maybe I should've shown the full h2o process to show how h2o will predict for all observations in the original dataframe.
– Nicklovn
Nov 23 '18 at 18:48
Yes I know that. I had some trouble some time ago with this but I had solved it then. I mainly used that as an example. Maybe I should've shown the full h2o process to show how h2o will predict for all observations in the original dataframe.
– Nicklovn
Nov 23 '18 at 18:48
OK, I'm voting to close as "no longer reproducible", hope that's ok!
– Axeman
Nov 23 '18 at 18:49
OK, I'm voting to close as "no longer reproducible", hope that's ok!
– Axeman
Nov 23 '18 at 18:49
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%2f53451351%2fdataframe-subsets-retain-information-from-parent-dataframe%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%2f53451351%2fdataframe-subsets-retain-information-from-parent-dataframe%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
Standby but I may have come up with a solution. It appears to be an issue arising from coercing an object of type h2o to an object of type vector. However, if you coerce the h2o object back to a dataframe you'll get a dataframe with all information and the predictions which you can extract as always via data[,1]
– Nicklovn
Nov 23 '18 at 18:40
The retention of factor levels is normal, not sure about the h2o specifics.
– Axeman
Nov 23 '18 at 18:45
Yes I know that. I had some trouble some time ago with this but I had solved it then. I mainly used that as an example. Maybe I should've shown the full h2o process to show how h2o will predict for all observations in the original dataframe.
– Nicklovn
Nov 23 '18 at 18:48
OK, I'm voting to close as "no longer reproducible", hope that's ok!
– Axeman
Nov 23 '18 at 18:49