Reputation: 1
I have an array of type numpy.ndarray
and pandas DataFrame and need a way to compare each value to each other.
Below is one of the ways I've tried to do it. I've also used pd.get(labels)
to pull the values out and was returned None
. y_test
is a pandas DataFrame and preds
is a numpy array of predictions.
Tried converting both of them to lists as well as numpy arrays for comparison:
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='binary_crossentropy',
optimizer='adam',metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5, batch_size=2000)
preds = model.predict(x_test)
preds[preds>=0.5] = 1
preds[preds<0.5] = 0
print(type(preds))
print(y_test.get('labels'))
total = 0
for i in range(len(preds)):
if int(preds[i]) == y_test[i]:
total = total + 1
This is what I am getting - TypeError: 'NoneType' object is not callable - KeyError: 0
Upvotes: 0
Views: 2930
Reputation: 4264
I guess you wanted to find the performance of your model so just use .evaluate()
method, I am assuming that you are using a keras model here.
sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='binary_crossentropy',
optimizer='adam',metrics=['accuracy'])
model.fit(x_train, y_train, epochs=5, batch_size=2000)
score= model.evaluate(x_test,y_test)
Upvotes: 0
Reputation: 601
So if y_test is a dataframe, then you can just ask for the values like this to get a numpy array:
y_test_array = y_test["labels"].values
Then print this out to know how many items are equal:
sum(y_test_array == preds)# number of items with same value
sum(y_test_array == preds)/len(preds)# %
I hope is what you asked.
Upvotes: 1