0
$\begingroup$
import numpy as np
import tensorflow as tf
import pandas as pd


from sklearn.preprocessing import MinMaxScaler
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import OrdinalEncoder
from sklearn.model_selection import train_test_split



def import_data():
    pulstars = pd.read_csv("pulsar_stars.csv", index_col=0)
    x = pulstars[["Standard deviation of the integrated profile", "Excess kurtosis of the integrated profile","Skewness of the integrated profile","Mean of the DM-SNR curve","Standard deviation of the DM-SNR curve","Excess kurtosis of the DM-SNR curve","Skewness of the DM-SNR curve"]]
    y = pulstars[["target_class"]]

    return x,y

inp , out = import_data()

out = out.dropna()

#normalize data
scaler = MinMaxScaler()
inp = scaler.fit_transform(inp)
out = scaler.fit_transform(out)

classConverter = OneHotEncoder(sparse=False)
out = classConverter.fit_transform(out)

layer = {
    "input": 8,
    "hidden": 8,
    "output": 2
}

i_h = {
    "weight": tf.Variable(tf.random_normal( [ layer["input"] , layer["hidden"] ] )),
    "bias": tf.Variable(tf.random_normal([layer["hidden"]]))
}

# weight = {
#     "i_h":tf.Variable(tf.random_normal( [ layer["input"] ], [ layer["hidden"] ] )),
#     "h_o":tf.Variable(tf.random_normal([[layer["hidden"]],[layer["output"]]]))
# }

# bias = {
#     "i_h":tf.Variable(tf.random_normal([layer["hidden"]])),
#     "h_o":tf.Variable(tf.random_normal([layer["output"]]))
# }

h_o = {
    "weight": tf.Variable(tf.random_normal([layer["hidden"],layer["output"]])),
    "bias": tf.Variable(tf.random_normal([layer["output"]]))
}



inp_dataset = tf.placeholder(tf.float32, [None, layer["input"]] )
target = tf.placeholder(tf.float32, [None, layer["output"]])

def feed_forward(inp_dataset):
    x1 = tf.matmul(inp_dataset,i_h["weight"]) + i_h["bias"]
    y1 = tf.nn.sigmoid(x1)

    x2 = tf.matmul(y1,h_o["weight"]) + h_o["bias"]
    y2 = tf.nn.sigmoid(x2)

    return y2 #output

output = feed_forward(inp_dataset)

error = tf.reduce_mean(0.5 * (target - output) ** 2)

#back propagation (update weight & bias)
update = tf.train.GradientDescentOptimizer(0.2).minimize(error)


#split dataset
x_train, x_test, y_train, y_test = train_test_split(inp, out, test_size = 0.2)

and this happen

ValueError                                Traceback (most recent call last)
<ipython-input-12-48df591e9215> in <module>()
     79 
     80 #split dataset
---> 81 x_train, x_test, y_train, y_test = train_test_split(inp, out, test_size = 0.2)
     82 
     83 

2 frames
/usr/local/lib/python3.6/dist-packages/sklearn/utils/validation.py in check_consistent_length(*arrays)
    210     if len(uniques) > 1:
    211         raise ValueError("Found input variables with inconsistent numbers of"
--> 212                          " samples: %r" % [int(l) for l in lengths])
    213 
    214 

ValueError: Found input variables with inconsistent numbers of samples: [13366, 1735]
$\endgroup$

1 Answer 1

1
$\begingroup$

After you apply dropna on your out, some rows are removed but the same is not done for your input. Hence, they have different number of rows, leading to your error.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.