I'm using TensorFlow decision forest to predict the suitable crop based on few parameters. How do i get the predict() method to return the label ?
Im using this dataset for training
My code
import tensorflow_decision_forests as tfdf
import tensorflow as tf
import pandas as pd
import numpy as np
df = pd.read_csv("Crop_recommendation.csv")
#TensorFlow dataset
train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(df,label="label")
# Train the model
model = tfdf.keras.RandomForestModel()
model.fit(train_ds)
print(model.summary())
pd_serving_dataset = pd.DataFrame({
"N": [83],
"P": [45],
"K" : [30],
"temperature" : [25],
"humidity" : [80.3],
"ph" : [6],
"rainfall" : [200.91],
})
tf_serving_dataset = tfdf.keras.pd_dataframe_to_tf_dataset(pd_serving_dataset)
prediction = model.predict(tf_serving_dataset)
print(prediction)
My Output
1/1 [==============================] - 0s 38ms/step
[[0. 0. 0. 0. 0.02333334 0.07666666
0.04666667 0. 0.08333332 0. 0. 0.
0. 0. 0. 0. 0. 0.
0. 0. 0.7699994 0. ]]
Expected Output rice