I have an error on an optimization code in XGBoost

Multi tool use
Multi tool use












1















I am just learning Python and finding the various examples online varying in quality.



In summary I have copied code for an XGBoost optimizer if I run the code for the XGBClassifier it works fine (if I make the label a 1 or -1 output) however, if I amend the code to XGBRegressor (for trying to predict a stock price) if falls over; any ideas what is causing this?



I also have a strange error for the final pyplot code at the bottom when I run it nothing happens, no error, just nothing!



I am using Jupyter notebook on Windows.



model = XGBRegressor()
n_estimators = [5, 10, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500]
print(max_depth)
param_grid = dict(max_depth=max_depth, n_estimators=n_estimators)
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=7)
grid_search = GridSearchCV(model, param_grid, scoring="neg_log_loss", n_jobs=-1, cv=kfold, verbose=1)
grid_result = grid_search.fit(X, label_encoded_y)

scores = numpy.array(means).reshape(len(max_depth), len(n_estimators))
for i, value in enumerate(max_depth):
pyplot.plot(n_estimators, scores[i], label='depth: ' + str(value))
pyplot.legend()
pyplot.xlabel('n_estimators')
pyplot.ylabel('Log Loss')
pyplot.savefig('n_estimators_vs_max_depth.png')


As I mentioned this works fine if I change to a XGBClassifier….apart from the pyplot code at the bottom which returns nothing, not even an error!










share|improve this question

























  • are you sure the model is fitting properly? You have set verbosity to 1 .. So what does it ouput when the fit is run?

    – HakunaMaData
    Jan 3 at 5:58











  • This is the output if I use XGBRegressor. ValueError: n_splits=10 cannot be greater than the number of members in each class. If I use XGBClassifier it works fine and fits various models giving me an output. The verbosity is how I found the code online!

    – Reece
    Jan 3 at 11:55
















1















I am just learning Python and finding the various examples online varying in quality.



In summary I have copied code for an XGBoost optimizer if I run the code for the XGBClassifier it works fine (if I make the label a 1 or -1 output) however, if I amend the code to XGBRegressor (for trying to predict a stock price) if falls over; any ideas what is causing this?



I also have a strange error for the final pyplot code at the bottom when I run it nothing happens, no error, just nothing!



I am using Jupyter notebook on Windows.



model = XGBRegressor()
n_estimators = [5, 10, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500]
print(max_depth)
param_grid = dict(max_depth=max_depth, n_estimators=n_estimators)
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=7)
grid_search = GridSearchCV(model, param_grid, scoring="neg_log_loss", n_jobs=-1, cv=kfold, verbose=1)
grid_result = grid_search.fit(X, label_encoded_y)

scores = numpy.array(means).reshape(len(max_depth), len(n_estimators))
for i, value in enumerate(max_depth):
pyplot.plot(n_estimators, scores[i], label='depth: ' + str(value))
pyplot.legend()
pyplot.xlabel('n_estimators')
pyplot.ylabel('Log Loss')
pyplot.savefig('n_estimators_vs_max_depth.png')


As I mentioned this works fine if I change to a XGBClassifier….apart from the pyplot code at the bottom which returns nothing, not even an error!










share|improve this question

























  • are you sure the model is fitting properly? You have set verbosity to 1 .. So what does it ouput when the fit is run?

    – HakunaMaData
    Jan 3 at 5:58











  • This is the output if I use XGBRegressor. ValueError: n_splits=10 cannot be greater than the number of members in each class. If I use XGBClassifier it works fine and fits various models giving me an output. The verbosity is how I found the code online!

    – Reece
    Jan 3 at 11:55














1












1








1








I am just learning Python and finding the various examples online varying in quality.



In summary I have copied code for an XGBoost optimizer if I run the code for the XGBClassifier it works fine (if I make the label a 1 or -1 output) however, if I amend the code to XGBRegressor (for trying to predict a stock price) if falls over; any ideas what is causing this?



I also have a strange error for the final pyplot code at the bottom when I run it nothing happens, no error, just nothing!



I am using Jupyter notebook on Windows.



model = XGBRegressor()
n_estimators = [5, 10, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500]
print(max_depth)
param_grid = dict(max_depth=max_depth, n_estimators=n_estimators)
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=7)
grid_search = GridSearchCV(model, param_grid, scoring="neg_log_loss", n_jobs=-1, cv=kfold, verbose=1)
grid_result = grid_search.fit(X, label_encoded_y)

scores = numpy.array(means).reshape(len(max_depth), len(n_estimators))
for i, value in enumerate(max_depth):
pyplot.plot(n_estimators, scores[i], label='depth: ' + str(value))
pyplot.legend()
pyplot.xlabel('n_estimators')
pyplot.ylabel('Log Loss')
pyplot.savefig('n_estimators_vs_max_depth.png')


As I mentioned this works fine if I change to a XGBClassifier….apart from the pyplot code at the bottom which returns nothing, not even an error!










share|improve this question
















I am just learning Python and finding the various examples online varying in quality.



In summary I have copied code for an XGBoost optimizer if I run the code for the XGBClassifier it works fine (if I make the label a 1 or -1 output) however, if I amend the code to XGBRegressor (for trying to predict a stock price) if falls over; any ideas what is causing this?



I also have a strange error for the final pyplot code at the bottom when I run it nothing happens, no error, just nothing!



I am using Jupyter notebook on Windows.



model = XGBRegressor()
n_estimators = [5, 10, 25, 50, 75, 100, 150, 200, 250, 300, 400, 500]
print(max_depth)
param_grid = dict(max_depth=max_depth, n_estimators=n_estimators)
kfold = StratifiedKFold(n_splits=10, shuffle=True, random_state=7)
grid_search = GridSearchCV(model, param_grid, scoring="neg_log_loss", n_jobs=-1, cv=kfold, verbose=1)
grid_result = grid_search.fit(X, label_encoded_y)

scores = numpy.array(means).reshape(len(max_depth), len(n_estimators))
for i, value in enumerate(max_depth):
pyplot.plot(n_estimators, scores[i], label='depth: ' + str(value))
pyplot.legend()
pyplot.xlabel('n_estimators')
pyplot.ylabel('Log Loss')
pyplot.savefig('n_estimators_vs_max_depth.png')


As I mentioned this works fine if I change to a XGBClassifier….apart from the pyplot code at the bottom which returns nothing, not even an error!







python jupyter-notebook






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 3 at 9:01









halfer

14.7k759116




14.7k759116










asked Jan 3 at 2:08









ReeceReece

61




61













  • are you sure the model is fitting properly? You have set verbosity to 1 .. So what does it ouput when the fit is run?

    – HakunaMaData
    Jan 3 at 5:58











  • This is the output if I use XGBRegressor. ValueError: n_splits=10 cannot be greater than the number of members in each class. If I use XGBClassifier it works fine and fits various models giving me an output. The verbosity is how I found the code online!

    – Reece
    Jan 3 at 11:55



















  • are you sure the model is fitting properly? You have set verbosity to 1 .. So what does it ouput when the fit is run?

    – HakunaMaData
    Jan 3 at 5:58











  • This is the output if I use XGBRegressor. ValueError: n_splits=10 cannot be greater than the number of members in each class. If I use XGBClassifier it works fine and fits various models giving me an output. The verbosity is how I found the code online!

    – Reece
    Jan 3 at 11:55

















are you sure the model is fitting properly? You have set verbosity to 1 .. So what does it ouput when the fit is run?

– HakunaMaData
Jan 3 at 5:58





are you sure the model is fitting properly? You have set verbosity to 1 .. So what does it ouput when the fit is run?

– HakunaMaData
Jan 3 at 5:58













This is the output if I use XGBRegressor. ValueError: n_splits=10 cannot be greater than the number of members in each class. If I use XGBClassifier it works fine and fits various models giving me an output. The verbosity is how I found the code online!

– Reece
Jan 3 at 11:55





This is the output if I use XGBRegressor. ValueError: n_splits=10 cannot be greater than the number of members in each class. If I use XGBClassifier it works fine and fits various models giving me an output. The verbosity is how I found the code online!

– Reece
Jan 3 at 11:55












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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015482%2fi-have-an-error-on-an-optimization-code-in-xgboost%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
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015482%2fi-have-an-error-on-an-optimization-code-in-xgboost%23new-answer', 'question_page');
}
);

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







sNKcMrLKdW g hrpMFhtcteJK6sXNI 4W52G,QVLi9S 1ik,THrZ,UwH,1HyobjhC5bs
dWiFKrAS2fi734 PncL,h3HGt,87r9HO0T,U,lQ6kGBl,3 68fwnEODWyLb8XCOW

Popular posts from this blog

Monofisismo

Angular Downloading a file using contenturl with Basic Authentication

Olmecas