Reduce weights for wrongly predicted class





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







1















I'm currently working on a simple prediction system, where the user is asked a series of yes/no questions and based on their responses, a pre-trained model (MLPClassifier) predicted a class and asks the user whether or not the prediction was right. I'm not sure if this is possible, but I was hoping to then alter the weights of the pre-trained model (in sort of an online-learning fashion) so that the network (in that session) doesn't predict the same class later. Currently, I'm just adding the bad responses to a dictionary and if the network predicts the class already in the black-listed set of classes it is ignored however I feel there must be a better approach than this! My code for the classifier is:



mlp = MLPClassifier(hidden_layer_sizes=(128,), max_iter=500, alpha=1e-4,
solver='sgd', verbose=10, tol=1e-4, random_state=1,
learning_rate_init=.1, )
x_train, x_test, y_train, y_test = train_test_split(df.values[:, 0:8], df.label_idx, test_size=0.33,
random_state=42)


And the code for the predictions is:



def receive_input():
responses =
bad_guesses =
print("Answer questions (Yes/No) or enter END to make prediction")
count = 0
while count < len(questions):
print(questions[count])
response = input().lower().strip()
if response == 'end':
break
elif response == 'yes':
responses.append(1)
elif response == 'no':
responses.append(0)
else:
print('Invalid Input')
continue
count += 1

padded_responses = np.pad(np.array(responses), (0, 8 - len(responses)), 'constant', constant_values=(0, -1))
prob_pred = mlp.predict_proba(padded_responses.reshape(1, -1)).flatten()
index = np.argmax(prob_pred)
best_score = prob_pred[index]
guess = labels[index]
if best_score > 0.8 and guess not in bad_guesses:
print('Early guess is: ' + labels[index] + ' is this right ? (Yes/No)')
correct = input()
if correct == 'Yes':
break
elif correct == 'No':
bad_guesses.append(labels[index])

pred = mlp.predict(np.array(responses).reshape(1, -1))
print('Prediction is: ' + labels[pred[0]])









share|improve this question























  • Awesome, that looks to work, thank you

    – Henry Hargreaves
    Nov 17 '18 at 12:57











  • Yeah sounds good

    – Henry Hargreaves
    Nov 17 '18 at 12:59


















1















I'm currently working on a simple prediction system, where the user is asked a series of yes/no questions and based on their responses, a pre-trained model (MLPClassifier) predicted a class and asks the user whether or not the prediction was right. I'm not sure if this is possible, but I was hoping to then alter the weights of the pre-trained model (in sort of an online-learning fashion) so that the network (in that session) doesn't predict the same class later. Currently, I'm just adding the bad responses to a dictionary and if the network predicts the class already in the black-listed set of classes it is ignored however I feel there must be a better approach than this! My code for the classifier is:



mlp = MLPClassifier(hidden_layer_sizes=(128,), max_iter=500, alpha=1e-4,
solver='sgd', verbose=10, tol=1e-4, random_state=1,
learning_rate_init=.1, )
x_train, x_test, y_train, y_test = train_test_split(df.values[:, 0:8], df.label_idx, test_size=0.33,
random_state=42)


And the code for the predictions is:



def receive_input():
responses =
bad_guesses =
print("Answer questions (Yes/No) or enter END to make prediction")
count = 0
while count < len(questions):
print(questions[count])
response = input().lower().strip()
if response == 'end':
break
elif response == 'yes':
responses.append(1)
elif response == 'no':
responses.append(0)
else:
print('Invalid Input')
continue
count += 1

padded_responses = np.pad(np.array(responses), (0, 8 - len(responses)), 'constant', constant_values=(0, -1))
prob_pred = mlp.predict_proba(padded_responses.reshape(1, -1)).flatten()
index = np.argmax(prob_pred)
best_score = prob_pred[index]
guess = labels[index]
if best_score > 0.8 and guess not in bad_guesses:
print('Early guess is: ' + labels[index] + ' is this right ? (Yes/No)')
correct = input()
if correct == 'Yes':
break
elif correct == 'No':
bad_guesses.append(labels[index])

pred = mlp.predict(np.array(responses).reshape(1, -1))
print('Prediction is: ' + labels[pred[0]])









share|improve this question























  • Awesome, that looks to work, thank you

    – Henry Hargreaves
    Nov 17 '18 at 12:57











  • Yeah sounds good

    – Henry Hargreaves
    Nov 17 '18 at 12:59














1












1








1








I'm currently working on a simple prediction system, where the user is asked a series of yes/no questions and based on their responses, a pre-trained model (MLPClassifier) predicted a class and asks the user whether or not the prediction was right. I'm not sure if this is possible, but I was hoping to then alter the weights of the pre-trained model (in sort of an online-learning fashion) so that the network (in that session) doesn't predict the same class later. Currently, I'm just adding the bad responses to a dictionary and if the network predicts the class already in the black-listed set of classes it is ignored however I feel there must be a better approach than this! My code for the classifier is:



mlp = MLPClassifier(hidden_layer_sizes=(128,), max_iter=500, alpha=1e-4,
solver='sgd', verbose=10, tol=1e-4, random_state=1,
learning_rate_init=.1, )
x_train, x_test, y_train, y_test = train_test_split(df.values[:, 0:8], df.label_idx, test_size=0.33,
random_state=42)


And the code for the predictions is:



def receive_input():
responses =
bad_guesses =
print("Answer questions (Yes/No) or enter END to make prediction")
count = 0
while count < len(questions):
print(questions[count])
response = input().lower().strip()
if response == 'end':
break
elif response == 'yes':
responses.append(1)
elif response == 'no':
responses.append(0)
else:
print('Invalid Input')
continue
count += 1

padded_responses = np.pad(np.array(responses), (0, 8 - len(responses)), 'constant', constant_values=(0, -1))
prob_pred = mlp.predict_proba(padded_responses.reshape(1, -1)).flatten()
index = np.argmax(prob_pred)
best_score = prob_pred[index]
guess = labels[index]
if best_score > 0.8 and guess not in bad_guesses:
print('Early guess is: ' + labels[index] + ' is this right ? (Yes/No)')
correct = input()
if correct == 'Yes':
break
elif correct == 'No':
bad_guesses.append(labels[index])

pred = mlp.predict(np.array(responses).reshape(1, -1))
print('Prediction is: ' + labels[pred[0]])









share|improve this question














I'm currently working on a simple prediction system, where the user is asked a series of yes/no questions and based on their responses, a pre-trained model (MLPClassifier) predicted a class and asks the user whether or not the prediction was right. I'm not sure if this is possible, but I was hoping to then alter the weights of the pre-trained model (in sort of an online-learning fashion) so that the network (in that session) doesn't predict the same class later. Currently, I'm just adding the bad responses to a dictionary and if the network predicts the class already in the black-listed set of classes it is ignored however I feel there must be a better approach than this! My code for the classifier is:



mlp = MLPClassifier(hidden_layer_sizes=(128,), max_iter=500, alpha=1e-4,
solver='sgd', verbose=10, tol=1e-4, random_state=1,
learning_rate_init=.1, )
x_train, x_test, y_train, y_test = train_test_split(df.values[:, 0:8], df.label_idx, test_size=0.33,
random_state=42)


And the code for the predictions is:



def receive_input():
responses =
bad_guesses =
print("Answer questions (Yes/No) or enter END to make prediction")
count = 0
while count < len(questions):
print(questions[count])
response = input().lower().strip()
if response == 'end':
break
elif response == 'yes':
responses.append(1)
elif response == 'no':
responses.append(0)
else:
print('Invalid Input')
continue
count += 1

padded_responses = np.pad(np.array(responses), (0, 8 - len(responses)), 'constant', constant_values=(0, -1))
prob_pred = mlp.predict_proba(padded_responses.reshape(1, -1)).flatten()
index = np.argmax(prob_pred)
best_score = prob_pred[index]
guess = labels[index]
if best_score > 0.8 and guess not in bad_guesses:
print('Early guess is: ' + labels[index] + ' is this right ? (Yes/No)')
correct = input()
if correct == 'Yes':
break
elif correct == 'No':
bad_guesses.append(labels[index])

pred = mlp.predict(np.array(responses).reshape(1, -1))
print('Prediction is: ' + labels[pred[0]])






machine-learning scikit-learn neural-network






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 22:00









Henry HargreavesHenry Hargreaves

348




348













  • Awesome, that looks to work, thank you

    – Henry Hargreaves
    Nov 17 '18 at 12:57











  • Yeah sounds good

    – Henry Hargreaves
    Nov 17 '18 at 12:59



















  • Awesome, that looks to work, thank you

    – Henry Hargreaves
    Nov 17 '18 at 12:57











  • Yeah sounds good

    – Henry Hargreaves
    Nov 17 '18 at 12:59

















Awesome, that looks to work, thank you

– Henry Hargreaves
Nov 17 '18 at 12:57





Awesome, that looks to work, thank you

– Henry Hargreaves
Nov 17 '18 at 12:57













Yeah sounds good

– Henry Hargreaves
Nov 17 '18 at 12:59





Yeah sounds good

– Henry Hargreaves
Nov 17 '18 at 12:59












1 Answer
1






active

oldest

votes


















1














mlp.coefs_ gives you a list, in which the ith element represents the weight matrix corresponding to layer i.



Moreover, mlp.intercepts_ gives you a list, in which the ith element represents the bias vector corresponding to layer i + 1.



So you can try and see if these attributes are alterable.






share|improve this answer
























    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%2f53346010%2freduce-weights-for-wrongly-predicted-class%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    mlp.coefs_ gives you a list, in which the ith element represents the weight matrix corresponding to layer i.



    Moreover, mlp.intercepts_ gives you a list, in which the ith element represents the bias vector corresponding to layer i + 1.



    So you can try and see if these attributes are alterable.






    share|improve this answer




























      1














      mlp.coefs_ gives you a list, in which the ith element represents the weight matrix corresponding to layer i.



      Moreover, mlp.intercepts_ gives you a list, in which the ith element represents the bias vector corresponding to layer i + 1.



      So you can try and see if these attributes are alterable.






      share|improve this answer


























        1












        1








        1







        mlp.coefs_ gives you a list, in which the ith element represents the weight matrix corresponding to layer i.



        Moreover, mlp.intercepts_ gives you a list, in which the ith element represents the bias vector corresponding to layer i + 1.



        So you can try and see if these attributes are alterable.






        share|improve this answer













        mlp.coefs_ gives you a list, in which the ith element represents the weight matrix corresponding to layer i.



        Moreover, mlp.intercepts_ gives you a list, in which the ith element represents the bias vector corresponding to layer i + 1.



        So you can try and see if these attributes are alterable.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 17 '18 at 13:00









        YahyaYahya

        3,91421131




        3,91421131
































            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%2f53346010%2freduce-weights-for-wrongly-predicted-class%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







            Popular posts from this blog

            Bressuire

            Vorschmack

            Quarantine