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

How do you interpolate outside the range of data?

Why is 1. d4 Nf6 2. c4 e6 3. Bg5 almost never played?

Non-visual Computers - thoughts?

How to know which loss function is suitable for image classification?

How do proponents of Sola Scriptura address the ministry of those Apostles who authored no parts of Scripture?

How much does Commander Data weigh?

Prevent use of CNAME Record for Untrusted Domain

Why is the UK so keen to remove the "backstop" when their leadership seems to think that no border will be needed in Northern Ireland?

What does zitch dog mean?

Disambiguation of "nobis vobis" and "nobis nobis"

Did the Cheela on Dragon's Egg have twelve-stranded "DNA"?

Duplicate instruments in unison in an orchestra

Are modern clipless shoes and pedals that much better than toe clips and straps?

Lost property on Portuguese trains

Why in most German places is the church the tallest building?

Is there any way to keep a player from killing an NPC?

How do I, an introvert, communicate to my friend and only colleague, an extrovert, that I want to spend my scheduled breaks without them?

Are the players on the same team as the DM?

What would make bones be of different colors?

The No-Free-Lunch Theorem and K-NN consistency

Do they have Supervillain(s)?

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

Handling Disruptive Student on the Autistic Spectrum

Prove your innocence



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


Obtaining consistent one-hot encoding of train / production dataWhy 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$














  • $begingroup$
    See datascience.stackexchange.com/q/54052/55122
    $endgroup$
    – Ben Reiniger
    yesterday


















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$














  • $begingroup$
    See datascience.stackexchange.com/q/54052/55122
    $endgroup$
    – Ben Reiniger
    yesterday














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 yesterday









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.

















  • $begingroup$
    See datascience.stackexchange.com/q/54052/55122
    $endgroup$
    – Ben Reiniger
    yesterday


















  • $begingroup$
    See datascience.stackexchange.com/q/54052/55122
    $endgroup$
    – Ben Reiniger
    yesterday
















$begingroup$
See datascience.stackexchange.com/q/54052/55122
$endgroup$
– Ben Reiniger
yesterday




$begingroup$
See datascience.stackexchange.com/q/54052/55122
$endgroup$
– Ben Reiniger
yesterday










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 yesterday









        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

            Taj Mahal Inhaltsverzeichnis Aufbau | Geschichte | 350-Jahr-Feier | Heutige Bedeutung | Siehe auch |...

            Baia Sprie Cuprins Etimologie | Istorie | Demografie | Politică și administrație | Arii naturale...

            Nicolae Petrescu-Găină Cuprins Biografie | Opera | In memoriam | Varia | Controverse, incertitudini...