Cost sensitive classification with individual cost Unicorn Meta Zoo #1: Why another podcast? Announcing the arrival of Valued Associate #679: Cesar Manara 2019 Moderator Election Q&A - Questionnaire 2019 Community Moderator Election ResultsWhy real-world output of my classifier has similar label ratio to training data?Using the Datumbox Machine Learning Framework for website classification - guidelines?minimization with a negative cost function: works in MATLAB, not in PythonNeural networks: which cost function to use?Multiclass classification with large number of classes but for each user the set of target classes is knownHow do I train a contextual bandit policy?Cost function for Ordinal Regression using neural networksNeural network approach to the cocktail party effectBinary classification based on pairwise relationshipsClassification on time series items - choose not constant thresholdTuning neural network loss function for space physics

Raising a bilingual kid. When should we introduce the majority language?

Why doesn't the university give past final exams' answers?

Is a self contained air-bullet cartridge feasible?

How to dissolve shared line segments together in QGIS?

/bin/ls sorts differently than just ls

My admission is revoked after accepting the admission offer

Philosophers who were composers?

What to do with someone that cheated their way though university and a PhD program?

Are `mathfont` and `mathspec` intended for same purpose?

Writing a T-SQL stored procedure to receive 4 numbers and insert them into a table

Errors in solving coupled pdes

Is it OK if I do not take the receipt in Germany?

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?

What's parked in Mil Moscow helicopter plant?

Bright yellow or light yellow?

What's the difference between using dependency injection with a container and using a service locator?

Where to find documentation for `whois` command options?

Married in secret, can marital status in passport be changed at a later date?

How did Elite on the NES work?

What were wait-states, and why was it only an issue for PCs?

What is /etc/mtab in Linux?

Protagonist's race is hidden - should I reveal it?

How to check if string is entirely made of same substring?



Cost sensitive classification with individual cost



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar Manara
2019 Moderator Election Q&A - Questionnaire
2019 Community Moderator Election ResultsWhy real-world output of my classifier has similar label ratio to training data?Using the Datumbox Machine Learning Framework for website classification - guidelines?minimization with a negative cost function: works in MATLAB, not in PythonNeural networks: which cost function to use?Multiclass classification with large number of classes but for each user the set of target classes is knownHow do I train a contextual bandit policy?Cost function for Ordinal Regression using neural networksNeural network approach to the cocktail party effectBinary classification based on pairwise relationshipsClassification on time series items - choose not constant thresholdTuning neural network loss function for space physics










2












$begingroup$


I'm currently sitting on a problem, where i'm uncertain if there is not a much simpler solution.



I'm trying to train a DNN with a dataset for a classification task that should be cost sensitive. Classic literature on this kind of task use a cost weight that is constant for any kind of misclassification. My problem needs to use one of the dimensions of the input as the cost of misclassification for that single classification.



My solution would be to use TensorFlow and add the parameter i later need to a collection and then write a custom loss function where i grab the values from the collection for my cost sensitive loss.



So my question would be, does anybody know of any simpler solution, open source implementation etc.?










share|improve this question









$endgroup$
















    2












    $begingroup$


    I'm currently sitting on a problem, where i'm uncertain if there is not a much simpler solution.



    I'm trying to train a DNN with a dataset for a classification task that should be cost sensitive. Classic literature on this kind of task use a cost weight that is constant for any kind of misclassification. My problem needs to use one of the dimensions of the input as the cost of misclassification for that single classification.



    My solution would be to use TensorFlow and add the parameter i later need to a collection and then write a custom loss function where i grab the values from the collection for my cost sensitive loss.



    So my question would be, does anybody know of any simpler solution, open source implementation etc.?










    share|improve this question









    $endgroup$














      2












      2








      2





      $begingroup$


      I'm currently sitting on a problem, where i'm uncertain if there is not a much simpler solution.



      I'm trying to train a DNN with a dataset for a classification task that should be cost sensitive. Classic literature on this kind of task use a cost weight that is constant for any kind of misclassification. My problem needs to use one of the dimensions of the input as the cost of misclassification for that single classification.



      My solution would be to use TensorFlow and add the parameter i later need to a collection and then write a custom loss function where i grab the values from the collection for my cost sensitive loss.



      So my question would be, does anybody know of any simpler solution, open source implementation etc.?










      share|improve this question









      $endgroup$




      I'm currently sitting on a problem, where i'm uncertain if there is not a much simpler solution.



      I'm trying to train a DNN with a dataset for a classification task that should be cost sensitive. Classic literature on this kind of task use a cost weight that is constant for any kind of misclassification. My problem needs to use one of the dimensions of the input as the cost of misclassification for that single classification.



      My solution would be to use TensorFlow and add the parameter i later need to a collection and then write a custom loss function where i grab the values from the collection for my cost sensitive loss.



      So my question would be, does anybody know of any simpler solution, open source implementation etc.?







      machine-learning neural-network classification cost-function






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 5 at 8:03









      T.TosT.Tos

      112




      112




















          1 Answer
          1






          active

          oldest

          votes


















          2












          $begingroup$

          There are two types of classification costs: per class, and per instance.



          In keras, for instance cost, we assign a cost to each training sample by feeding sample_weight to .fit. For example, if we have four training samples in rows 1, 2, 3, and 4, with misclassification costs 2.5, 1.5, 1.0, and 1.0, we feed sample_weight=[2.5, 1.5, 1.0, 1.0].



          For class cost, if there are three classes 0, 1, and 2, with misclassification costs 1.0, 3.0, 1.0, we feed class_weight=[1.0, 3.0, 1.0].



          Here is a step-by-step classification example in Keras.



          You should feed your weights in this line:



          model.fit(train_images, train_labels, epochs=5)





          share|improve this answer









          $endgroup$








          • 1




            $begingroup$
            Thank you for your answer! Sadly i need a class and instance specific weight. So a combination of both types. Sadly could also not find such a thing in pytorch but will try out how the keras training is going to help me out.
            $endgroup$
            – T.Tos
            Apr 5 at 16:07











          Your Answer








          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "557"
          ;
          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: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          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%2fdatascience.stackexchange.com%2fquestions%2f48672%2fcost-sensitive-classification-with-individual-cost%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









          2












          $begingroup$

          There are two types of classification costs: per class, and per instance.



          In keras, for instance cost, we assign a cost to each training sample by feeding sample_weight to .fit. For example, if we have four training samples in rows 1, 2, 3, and 4, with misclassification costs 2.5, 1.5, 1.0, and 1.0, we feed sample_weight=[2.5, 1.5, 1.0, 1.0].



          For class cost, if there are three classes 0, 1, and 2, with misclassification costs 1.0, 3.0, 1.0, we feed class_weight=[1.0, 3.0, 1.0].



          Here is a step-by-step classification example in Keras.



          You should feed your weights in this line:



          model.fit(train_images, train_labels, epochs=5)





          share|improve this answer









          $endgroup$








          • 1




            $begingroup$
            Thank you for your answer! Sadly i need a class and instance specific weight. So a combination of both types. Sadly could also not find such a thing in pytorch but will try out how the keras training is going to help me out.
            $endgroup$
            – T.Tos
            Apr 5 at 16:07















          2












          $begingroup$

          There are two types of classification costs: per class, and per instance.



          In keras, for instance cost, we assign a cost to each training sample by feeding sample_weight to .fit. For example, if we have four training samples in rows 1, 2, 3, and 4, with misclassification costs 2.5, 1.5, 1.0, and 1.0, we feed sample_weight=[2.5, 1.5, 1.0, 1.0].



          For class cost, if there are three classes 0, 1, and 2, with misclassification costs 1.0, 3.0, 1.0, we feed class_weight=[1.0, 3.0, 1.0].



          Here is a step-by-step classification example in Keras.



          You should feed your weights in this line:



          model.fit(train_images, train_labels, epochs=5)





          share|improve this answer









          $endgroup$








          • 1




            $begingroup$
            Thank you for your answer! Sadly i need a class and instance specific weight. So a combination of both types. Sadly could also not find such a thing in pytorch but will try out how the keras training is going to help me out.
            $endgroup$
            – T.Tos
            Apr 5 at 16:07













          2












          2








          2





          $begingroup$

          There are two types of classification costs: per class, and per instance.



          In keras, for instance cost, we assign a cost to each training sample by feeding sample_weight to .fit. For example, if we have four training samples in rows 1, 2, 3, and 4, with misclassification costs 2.5, 1.5, 1.0, and 1.0, we feed sample_weight=[2.5, 1.5, 1.0, 1.0].



          For class cost, if there are three classes 0, 1, and 2, with misclassification costs 1.0, 3.0, 1.0, we feed class_weight=[1.0, 3.0, 1.0].



          Here is a step-by-step classification example in Keras.



          You should feed your weights in this line:



          model.fit(train_images, train_labels, epochs=5)





          share|improve this answer









          $endgroup$



          There are two types of classification costs: per class, and per instance.



          In keras, for instance cost, we assign a cost to each training sample by feeding sample_weight to .fit. For example, if we have four training samples in rows 1, 2, 3, and 4, with misclassification costs 2.5, 1.5, 1.0, and 1.0, we feed sample_weight=[2.5, 1.5, 1.0, 1.0].



          For class cost, if there are three classes 0, 1, and 2, with misclassification costs 1.0, 3.0, 1.0, we feed class_weight=[1.0, 3.0, 1.0].



          Here is a step-by-step classification example in Keras.



          You should feed your weights in this line:



          model.fit(train_images, train_labels, epochs=5)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 5 at 11:00









          EsmailianEsmailian

          3,736420




          3,736420







          • 1




            $begingroup$
            Thank you for your answer! Sadly i need a class and instance specific weight. So a combination of both types. Sadly could also not find such a thing in pytorch but will try out how the keras training is going to help me out.
            $endgroup$
            – T.Tos
            Apr 5 at 16:07












          • 1




            $begingroup$
            Thank you for your answer! Sadly i need a class and instance specific weight. So a combination of both types. Sadly could also not find such a thing in pytorch but will try out how the keras training is going to help me out.
            $endgroup$
            – T.Tos
            Apr 5 at 16:07







          1




          1




          $begingroup$
          Thank you for your answer! Sadly i need a class and instance specific weight. So a combination of both types. Sadly could also not find such a thing in pytorch but will try out how the keras training is going to help me out.
          $endgroup$
          – T.Tos
          Apr 5 at 16:07




          $begingroup$
          Thank you for your answer! Sadly i need a class and instance specific weight. So a combination of both types. Sadly could also not find such a thing in pytorch but will try out how the keras training is going to help me out.
          $endgroup$
          – T.Tos
          Apr 5 at 16:07

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Data Science Stack Exchange!


          • 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.

          Use MathJax to format equations. MathJax reference.


          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%2fdatascience.stackexchange.com%2fquestions%2f48672%2fcost-sensitive-classification-with-individual-cost%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

          Adding axes to figuresAdding axes labels to LaTeX figuresLaTeX equivalent of ConTeXt buffersRotate a node but not its content: the case of the ellipse decorationHow to define the default vertical distance between nodes?TikZ scaling graphic and adjust node position and keep font sizeNumerical conditional within tikz keys?adding axes to shapesAlign axes across subfiguresAdding figures with a certain orderLine up nested tikz enviroments or how to get rid of themAdding axes labels to LaTeX figures

          Luettelo Yhdysvaltain laivaston lentotukialuksista Lähteet | Navigointivalikko

          Gary (muusikko) Sisällysluettelo Historia | Rockin' High | Lähteet | Aiheesta muualla | NavigointivalikkoInfobox OKTuomas "Gary" Keskinen Ancaran kitaristiksiProjekti Rockin' High