How to use LSTM layers in CSV

Viewed 393

I am try to make a project in which farming advice are generated based on weather condition on a specific district. I have a sample dataset for now, as shown below.

state district month rainfall max_temp min_temp max_rh min_rh wind_speed advice
Orissa Kendrapada february 0.0 34.6 19.4 88.2 29.6 12.0 chances of foot rot disease in paddy crop; apply urea at 3 weeks after transplanting at active tillering stage for paddy;......
Jharkhand Saraikela Kharsawan february 0 35.2 16.6 29.4 11.2 3.6 provide straw mulch and go for intercultural operations to avoid moisture losses from soil; chance of leaf blight disease in potato crop; .......

I want to use this dataset to generate advice for farmers based on weather conditions.

I have tokenized the advice columns and also converted them to tensor. I am unsure about which keras layers to use for model. The shape of each tensors in advice columns is TensorShape([150]). I need to train it so that it could generate texts. I know I should use Bidirectional LSTM, but how?

Please tell me which layers should I use and how to arrange them.

1 Answers

Use Keras Sequential model to implement the above problem. Firstly, encode your input data Read csv file into dataframe, apply the labelencoder to get x_train, y_train and x_test, y_test. Follow the sample code, change according to your feature selection and requirement,

import tensorflow as tf
import pandas as pd
from sklearn.preprocessing import LabelEncoder
df_train = pd.read_csv("sampledata.csv")
df_train['wind_speed'] = LabelEncoder.fit_transform(df_train['wind_speed'])
x_train = df_train.values

model = Sequential()
model.add(Dense(128, input_dim = 4, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(128, activation='relu'))
model.add(Dense(1, activation='relu'))
model.compile(loss='mean_absolute_error', optimizer='nadam')

Experiment with Dense layer and Bilstm layer. Make sure input data shape is proper

model.fit(x_train, y_train, epochs=25, batch_size=25)

pred = model.predict(x_test)
Related