0

I am trying to build a simple Keras model but am getting an AttributeError for some unkown reason. All of the datatypes I am feeding to the model are float64. Code is as follows:

Defining features and target:

X = rated_df[["content_found", "domain_found","title_found", "url_found", "CPC","Competition","number_of_results","search_vol"]]

y = "Position"

Model as follows:

from keras.models import Sequential from keras.layers import Dense

model = Sequential() model.add(Dense(12, input_dim=8, activation='relu')) model.add(Dense(8, activation='relu')) model.add(Dense(1, activation='sigmoid'))

model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

Then the fitting of the model which causes the error:

model.fit(X, y, epochs=150, batch_size=10)

and error is

AttributeError: 'str' object has no attribute 'ndim'

A picture of the data is below and as mentioned contains all float64 datatypes:

enter image description here

If anyone has any advice it would be much appreciated, thanks!

1
  • 1
    That pretty much always means something is not of the type expected. check what args the various model methods are expecting and make sure you're passing the right types. Commented Dec 16, 2019 at 17:48

1 Answer 1

2

The problem is that you are defining y to be a string.

You likely want

y = df["Position"]
Sign up to request clarification or add additional context in comments.

1 Comment

Indeed, can't believe I missed something so small! Thanks!

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.