Replies: 6 comments 2 replies
-
Maybe you can first convert the type of the input to string type instead of float type? |
Beta Was this translation helpful? Give feedback.
-
I took a look at the data, it seems like for now, you can resolve this by doing
afaik
|
Beta Was this translation helpful? Give feedback.
-
Here's one solution that will work to fix your encoding issues, but requires a label encoder from sklearn. However, import tensorflow as tf
from tensorflow.keras.models import load_model
import autokeras as ak
import numpy as np
import pandas as pd
from sklearn.preprocessing import LabelEncoder
TRAIN_DATA_URL = "https://storage.googleapis.com/tf-datasets/titanic/train.csv"
TEST_DATA_URL = "https://storage.googleapis.com/tf-datasets/titanic/eval.csv"
train_file_path = tf.keras.utils.get_file("train.csv", TRAIN_DATA_URL)
test_file_path = tf.keras.utils.get_file("eval.csv", TEST_DATA_URL)
x_train = pd.read_csv(train_file_path)
y_train = x_train.pop("survived")
# Preparing testing data.
x_test = pd.read_csv(test_file_path)
y_test = x_test.pop("survived")
for df in [x_train, x_test]:
for col in df.columns:
if df[col].dtypes == 'object':
le = preprocessing.LabelEncoder()
df[col] = le.fit_transform(df[col])
clf = ak.StructuredDataClassifier(overwrite=True, max_trials=3)
clf.fit(x_train, y_train, epochs=10)
model = clf.export_model()
model.save('model_autokeras', save_format='tf')
loaded_model = load_model('model_autokeras', custom_objects=ak.CUSTOM_OBJECTS)
predicted_y = loaded_model.predict(x_test)
print(predicted_y) |
Beta Was this translation helpful? Give feedback.
-
Thanks all, |
Beta Was this translation helpful? Give feedback.
-
I had the same problem. I used Tensorflow's So simply convert the test data to string (no need to encode beforehand) and it should work: predicted_y = loaded_model.predict(x_test.astype('str')) |
Beta Was this translation helpful? Give feedback.
-
Hi, I had the same issue, I solved it by serializing the entire import pickle
with open("autokeras_model.pkl", "wb") as f:
pickle.dump(clf, f)
with open("autokeras_model.pkl", "rb") as f:
model = pickle.load(f)
model.predict(holdout_data) The output was: 24/24 [==============================] - 0s 3ms/step
array([['no'],
['no'],
['no'],
['no'],
['no'],
['no'],
['no'],
['no'],
['no'],
['yes'],
['yes'],
['no'],
['no'],
...
... |
Beta Was this translation helpful? Give feedback.
-
Hi,
I am trying to save and load an automodel using the test script below.
and get the following error;
ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type float).
I understand that the loaded model is just the underlying keras model and when looking at automodel.predict method, the pipeline is being used before passing the processed data to the underlying keras model predict method.
How do you export/import the entire automodel?
Beta Was this translation helpful? Give feedback.
All reactions