Tensorflow - logistic regrssion -oneHot Encoder - Transformed array of differt size for both train and testWhy does logistic regression in Spark and R return different models for the same data?Question about train example code for TensorFlowTensorflow oscillating Test and Train Accuracy?Improve test accuracy for TensorFlow CNNHow to properly rotate image and labels for semantic segmentation data augmentation in Tensorflow?Train, test and submission files - what am I supposed to do with all of them?Logistic Regression doesn't predict for the entire test set

Couple of slangs I've heard when watching anime

LeetCode: Group Anagrams C#

Are there any elected officials in the U.S. who are not legislators, judges, or constitutional officers?

Justifying the use of directed energy weapons

How to make Ubuntu support single display 5120x1440 resolution?

Why do all fields in a QFT transform like *irreducible* representations of some group?

How to respectfully refuse to assist co-workers with IT issues?

antonym of "billable"

Did a flight controller ever answer Flight with a no-go?

Is using a hyperlink to close a modal a poor design decision?

Why is there so little discussion / research on the philosophy of precision?

How do I get a decreased-by-one x in a foreach loop?

What would be the challenges to taking off and landing a typical passenger jet at FL300?

what mathematical functions can we use to generate patterns for rhythm (meter and notes)?

Result of pgmathsetmacro is lost in loop iterations

What do these triangles above and below the staff mean?

Heyacrazy: Careening

Prove your innocence

“T” in subscript in formulas

How is the idea of "two people having a heated argument" idiomatically expressed in German?

Architectural feasibility of a tiered circular stone keep

How can I unambiguously ask for a new user's "Display Name"?

Why did Khan ask Admiral James T. Kirk about Project Genesis?

Is gzip atomic?



Tensorflow - logistic regrssion -oneHot Encoder - Transformed array of differt size for both train and test


Why does logistic regression in Spark and R return different models for the same data?Question about train example code for TensorFlowTensorflow oscillating Test and Train Accuracy?Improve test accuracy for TensorFlow CNNHow to properly rotate image and labels for semantic segmentation data augmentation in Tensorflow?Train, test and submission files - what am I supposed to do with all of them?Logistic Regression doesn't predict for the entire test set






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








6












$begingroup$


 x_train = tr1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
#x_train.shape - (120 x 4)

y_train = tr1.loc[:, ['Species']]
#shape - 120 x 3

x_test = test1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
#shape 30 x 4
y_test = test1.loc[:, ['Species']]
# shape 30 x 3

oneHot = OneHotEncoder()
oneHot.fit(x_train)
# transform
x_train = oneHot.transform(x_train).toarray()
# fit our y to oneHot encoder
oneHot.fit(y_train)
# transform
y_train = oneHot.transform(y_train).toarray()

oneHot.fit(x_test)
# transform
x_test = oneHot.transform(x_test).toarray()
# fit our y to oneHot encoder
oneHot.fit(y_test)
# transform
y_test = oneHot.transform(y_test).toarray()

print("Our features X_test1 in one-hot format")
print(x_test)


Shape of x_train: (120, 15)
Shape of y_train: (120, 3)
Shape of x_test: (30, 14)
Shape of y_test: (30, 3)



a) After conversion why is the size x_test = 30 x 14 I assume it has to be 30 x 15 ?



# hyperparameters
learning_rate = 0.0001
num_epochs = 100
display_step = 1

# for visualize purpose in tensorboard we use tf.name_scope
with tf.name_scope("Declaring_placeholder"):
# X is placeholdre for iris features. We will feed data later on
x = tf.placeholder(tf.float32, shape=[None, 15])
# y is placeholder for iris labels. We will feed data later on
y = tf.placeholder(tf.float32, shape=[None, 3])


with tf.name_scope("Declaring_variables"):
# W is our weights. This will update during training time
W = tf.Variable(tf.zeros([15, 3]))
# b is our bias. This will also update during training time
b = tf.Variable(tf.zeros([3]))



with tf.name_scope("Declaring_functions"):
# our prediction function
y_ = tf.nn.softmax(tf.add(tf.matmul(x, W), b))


b) did I define x, y, W, b correctly because when I run the accuracy I get this error "ValueError: Cannot feed value of shape (30, 14) for Tensor 'Declaring_placeholder_10/Placeholder:0', which has shape '(?, 15)'
"










share|improve this question







New contributor



user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






$endgroup$




















    6












    $begingroup$


     x_train = tr1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
    #x_train.shape - (120 x 4)

    y_train = tr1.loc[:, ['Species']]
    #shape - 120 x 3

    x_test = test1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
    #shape 30 x 4
    y_test = test1.loc[:, ['Species']]
    # shape 30 x 3

    oneHot = OneHotEncoder()
    oneHot.fit(x_train)
    # transform
    x_train = oneHot.transform(x_train).toarray()
    # fit our y to oneHot encoder
    oneHot.fit(y_train)
    # transform
    y_train = oneHot.transform(y_train).toarray()

    oneHot.fit(x_test)
    # transform
    x_test = oneHot.transform(x_test).toarray()
    # fit our y to oneHot encoder
    oneHot.fit(y_test)
    # transform
    y_test = oneHot.transform(y_test).toarray()

    print("Our features X_test1 in one-hot format")
    print(x_test)


    Shape of x_train: (120, 15)
    Shape of y_train: (120, 3)
    Shape of x_test: (30, 14)
    Shape of y_test: (30, 3)



    a) After conversion why is the size x_test = 30 x 14 I assume it has to be 30 x 15 ?



    # hyperparameters
    learning_rate = 0.0001
    num_epochs = 100
    display_step = 1

    # for visualize purpose in tensorboard we use tf.name_scope
    with tf.name_scope("Declaring_placeholder"):
    # X is placeholdre for iris features. We will feed data later on
    x = tf.placeholder(tf.float32, shape=[None, 15])
    # y is placeholder for iris labels. We will feed data later on
    y = tf.placeholder(tf.float32, shape=[None, 3])


    with tf.name_scope("Declaring_variables"):
    # W is our weights. This will update during training time
    W = tf.Variable(tf.zeros([15, 3]))
    # b is our bias. This will also update during training time
    b = tf.Variable(tf.zeros([3]))



    with tf.name_scope("Declaring_functions"):
    # our prediction function
    y_ = tf.nn.softmax(tf.add(tf.matmul(x, W), b))


    b) did I define x, y, W, b correctly because when I run the accuracy I get this error "ValueError: Cannot feed value of shape (30, 14) for Tensor 'Declaring_placeholder_10/Placeholder:0', which has shape '(?, 15)'
    "










    share|improve this question







    New contributor



    user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    $endgroup$
















      6












      6








      6





      $begingroup$


       x_train = tr1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
      #x_train.shape - (120 x 4)

      y_train = tr1.loc[:, ['Species']]
      #shape - 120 x 3

      x_test = test1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
      #shape 30 x 4
      y_test = test1.loc[:, ['Species']]
      # shape 30 x 3

      oneHot = OneHotEncoder()
      oneHot.fit(x_train)
      # transform
      x_train = oneHot.transform(x_train).toarray()
      # fit our y to oneHot encoder
      oneHot.fit(y_train)
      # transform
      y_train = oneHot.transform(y_train).toarray()

      oneHot.fit(x_test)
      # transform
      x_test = oneHot.transform(x_test).toarray()
      # fit our y to oneHot encoder
      oneHot.fit(y_test)
      # transform
      y_test = oneHot.transform(y_test).toarray()

      print("Our features X_test1 in one-hot format")
      print(x_test)


      Shape of x_train: (120, 15)
      Shape of y_train: (120, 3)
      Shape of x_test: (30, 14)
      Shape of y_test: (30, 3)



      a) After conversion why is the size x_test = 30 x 14 I assume it has to be 30 x 15 ?



      # hyperparameters
      learning_rate = 0.0001
      num_epochs = 100
      display_step = 1

      # for visualize purpose in tensorboard we use tf.name_scope
      with tf.name_scope("Declaring_placeholder"):
      # X is placeholdre for iris features. We will feed data later on
      x = tf.placeholder(tf.float32, shape=[None, 15])
      # y is placeholder for iris labels. We will feed data later on
      y = tf.placeholder(tf.float32, shape=[None, 3])


      with tf.name_scope("Declaring_variables"):
      # W is our weights. This will update during training time
      W = tf.Variable(tf.zeros([15, 3]))
      # b is our bias. This will also update during training time
      b = tf.Variable(tf.zeros([3]))



      with tf.name_scope("Declaring_functions"):
      # our prediction function
      y_ = tf.nn.softmax(tf.add(tf.matmul(x, W), b))


      b) did I define x, y, W, b correctly because when I run the accuracy I get this error "ValueError: Cannot feed value of shape (30, 14) for Tensor 'Declaring_placeholder_10/Placeholder:0', which has shape '(?, 15)'
      "










      share|improve this question







      New contributor



      user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      $endgroup$




       x_train = tr1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
      #x_train.shape - (120 x 4)

      y_train = tr1.loc[:, ['Species']]
      #shape - 120 x 3

      x_test = test1.loc[:, ['Sepal Length', 'Sepal Width', 'Petal Length', 'Petal Width']]
      #shape 30 x 4
      y_test = test1.loc[:, ['Species']]
      # shape 30 x 3

      oneHot = OneHotEncoder()
      oneHot.fit(x_train)
      # transform
      x_train = oneHot.transform(x_train).toarray()
      # fit our y to oneHot encoder
      oneHot.fit(y_train)
      # transform
      y_train = oneHot.transform(y_train).toarray()

      oneHot.fit(x_test)
      # transform
      x_test = oneHot.transform(x_test).toarray()
      # fit our y to oneHot encoder
      oneHot.fit(y_test)
      # transform
      y_test = oneHot.transform(y_test).toarray()

      print("Our features X_test1 in one-hot format")
      print(x_test)


      Shape of x_train: (120, 15)
      Shape of y_train: (120, 3)
      Shape of x_test: (30, 14)
      Shape of y_test: (30, 3)



      a) After conversion why is the size x_test = 30 x 14 I assume it has to be 30 x 15 ?



      # hyperparameters
      learning_rate = 0.0001
      num_epochs = 100
      display_step = 1

      # for visualize purpose in tensorboard we use tf.name_scope
      with tf.name_scope("Declaring_placeholder"):
      # X is placeholdre for iris features. We will feed data later on
      x = tf.placeholder(tf.float32, shape=[None, 15])
      # y is placeholder for iris labels. We will feed data later on
      y = tf.placeholder(tf.float32, shape=[None, 3])


      with tf.name_scope("Declaring_variables"):
      # W is our weights. This will update during training time
      W = tf.Variable(tf.zeros([15, 3]))
      # b is our bias. This will also update during training time
      b = tf.Variable(tf.zeros([3]))



      with tf.name_scope("Declaring_functions"):
      # our prediction function
      y_ = tf.nn.softmax(tf.add(tf.matmul(x, W), b))


      b) did I define x, y, W, b correctly because when I run the accuracy I get this error "ValueError: Cannot feed value of shape (30, 14) for Tensor 'Declaring_placeholder_10/Placeholder:0', which has shape '(?, 15)'
      "







      tensorflow logistic-regression






      share|improve this question







      New contributor



      user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.










      share|improve this question







      New contributor



      user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      share|improve this question




      share|improve this question






      New contributor



      user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.








      asked 9 hours ago









      user80034user80034

      311 bronze badge




      311 bronze badge




      New contributor



      user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.




      New contributor




      user80034 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.

























          1 Answer
          1






          active

          oldest

          votes


















          6













          $begingroup$

          Your shape is (30, 14) and not (30, 15) because there are only 14 unique values in your test (one is missing). In any case you shouldn't fit the encoder on the test set, just on the training set. Then just transform on the test set and you'll get the correct dimensions.



          Also as far as I can see W and b are declared correctly. I'd ask however you take a minute to format your question a bit better next time.






          share|improve this answer









          $endgroup$

















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



            );






            user80034 is a new contributor. Be nice, and check out our Code of Conduct.









            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdatascience.stackexchange.com%2fquestions%2f58088%2ftensorflow-logistic-regrssion-onehot-encoder-transformed-array-of-differt-s%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









            6













            $begingroup$

            Your shape is (30, 14) and not (30, 15) because there are only 14 unique values in your test (one is missing). In any case you shouldn't fit the encoder on the test set, just on the training set. Then just transform on the test set and you'll get the correct dimensions.



            Also as far as I can see W and b are declared correctly. I'd ask however you take a minute to format your question a bit better next time.






            share|improve this answer









            $endgroup$



















              6













              $begingroup$

              Your shape is (30, 14) and not (30, 15) because there are only 14 unique values in your test (one is missing). In any case you shouldn't fit the encoder on the test set, just on the training set. Then just transform on the test set and you'll get the correct dimensions.



              Also as far as I can see W and b are declared correctly. I'd ask however you take a minute to format your question a bit better next time.






              share|improve this answer









              $endgroup$

















                6














                6










                6







                $begingroup$

                Your shape is (30, 14) and not (30, 15) because there are only 14 unique values in your test (one is missing). In any case you shouldn't fit the encoder on the test set, just on the training set. Then just transform on the test set and you'll get the correct dimensions.



                Also as far as I can see W and b are declared correctly. I'd ask however you take a minute to format your question a bit better next time.






                share|improve this answer









                $endgroup$



                Your shape is (30, 14) and not (30, 15) because there are only 14 unique values in your test (one is missing). In any case you shouldn't fit the encoder on the test set, just on the training set. Then just transform on the test set and you'll get the correct dimensions.



                Also as far as I can see W and b are declared correctly. I'd ask however you take a minute to format your question a bit better next time.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 2 hours ago









                JcartJcart

                3006 bronze badges




                3006 bronze badges























                    user80034 is a new contributor. Be nice, and check out our Code of Conduct.









                    draft saved

                    draft discarded


















                    user80034 is a new contributor. Be nice, and check out our Code of Conduct.












                    user80034 is a new contributor. Be nice, and check out our Code of Conduct.











                    user80034 is a new contributor. Be nice, and check out our Code of Conduct.














                    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%2f58088%2ftensorflow-logistic-regrssion-onehot-encoder-transformed-array-of-differt-s%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

                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                    François Viète Contents Biography Work and thought Bibliography See also Notes Further reading External links Navigation menup. 21Google Bookspp. 75–77Google BooksDe thou (from University of Saint Andrews)ArchivedGoogle BooksGoogle BooksGoogle BooksGoogle booksGoogle Bookscc-parthenay.frL'histoire universelle (fr)Universal History (en)ArchivedAdsabs.harvard.eduPagesperso-orange.frArchive.orgChikara Sasaki. Descartes' mathematical thought p.259Google BooksGoogle BooksGoogle Bookspp. 152 and onwardGoogle BooksGoogle BooksScribd.comGoogle Books1257-7979Google BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGoogle BooksGallica.bnf.frGoogle BooksGoogle Books"François Viète"Francois Viète: Father of Modern Algebraic NotationThe Lawyer and the GamblerAbout TarporleySite de Jean-Paul GuichardL'algèbre nouvelle"About the Harmonicon"cb120511976(data)1188044800000 0001 0913 5903n82164680ola2013766880073431702w6vt1sb70287374827140948071409480