1
$\begingroup$

i use this model

 model = Sequential([
        Dense(units=10, input_shape=(1,), activation='relu'),
        Dense(units=32, activation='relu'),
        Dense(units=10, activation='softmax')
    ])
   
    model.compile(optimizer=Adam(learning_rate=0.0001), loss='sparse_categorical_crossentropy', metrics=['accuracy']) 
    
    model.fit(x_train, y_train, batch_size=10, epochs=30)

but model.fit always return this error

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float).

however i converted my data as following

 x_train = np.array(x_train)
 y_train = np.array(y_train)
 x_test= np.array(x_test)
 y_test = np.array(y_test)
 y_train, x_train = shuffle(y_train, x_train)
 y_test, x_test = shuffle(y_test, x_test)

this is my model summary

enter image description here

and this is the shape of my data x_train as 1D of array for each input sample, and y_train is a label for each sample and values from (1 to 10).

enter image description here

can any one helps me Regards in advance !

and i define my data as following

from google.colab import files
uploaded = files.upload()

import io
dset = pd.read_csv(io.BytesIO(uploaded['1-210.csv']))

y= dset.Readername
x=dset.drop('Readername',axis=1)

x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2)
$\endgroup$

1 Answer 1

0
$\begingroup$

It looks like the model is expecting float input. Try converting to float using astype:

X = np.asarray(X).astype(np.float32)

$\endgroup$
5
  • $\begingroup$ many thanks for your response i tried it, but i get this error "could not convert string to float: '9 0.559884'" $\endgroup$
    – Beba.S
    Aug 23, 2021 at 10:02
  • $\begingroup$ Can you post your variable where you define the data? $\endgroup$
    – diyImma
    Aug 23, 2021 at 11:00
  • $\begingroup$ OK i updated my question and defined my data over there really many thanks for your help $\endgroup$
    – Beba.S
    Aug 23, 2021 at 15:11
  • $\begingroup$ is your "y" a name? I'm not sure how you can train a model to learn from "x" data to arrive at a particular string. Maybe you should start a new thread explaining the problem you are trying to solve and get help in planning your model. $\endgroup$
    – diyImma
    Aug 24, 2021 at 6:01
  • $\begingroup$ many thanks diylmma i used your answer and fixed the parameters of input_shape(), and finally it worked.but i have another problem i will make a new thread for it. Once again thank you very much ! $\endgroup$
    – Beba.S
    Aug 25, 2021 at 15:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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