Do we need to define model everytime we need to train data in LSTM?

Do we need to define model everytime we need to train data in LSTM?

Manage alerts

Loading saved threads...

Stupid_Intern · External communityPost link
External question — Data Science Stack Exchange Author: Stupid_Intern Original post: https://datascience.stackexchange.com/questions/108849 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Suppose if I have two datasets where 1st dataset is AAPL stock price and 2nd dataset is GOOGL stock price. Now if I define the model as model =Sequential() model.add(LSTM(100, activation='relu', input_shape=(n_input,n_features))) model.add(Dense(1)) model.compile(optimizer='adam', loss='mse') model.summary() and then train and fit it on first dataset df = pd.read_csv('data\\AAPL.csv', index_col = 0) train = df[['close']].iloc[:int(len(df)*0.8)] scaler = MinMaxScaler() scaler.fit(train) scaled_train = scaler.transform(train) #------------------------------------------------------ generator = TimeseriesGenerator(scaled_train,scaled_train,length=n_input, batch_size=1) #----------------------------------------------------- #fit model model.fit(generator,epochs=10) then if I have to fit the model on second dataset do I need to define it again? if not then why does the output of model.fit differs when I define the model again before fitting it on second dataset?
Quote
Report
Uday · External communityPost link
External answer — Data Science Stack Exchange Author: Uday Original post: https://datascience.stackexchange.com/a/108871 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. In your code, you trained on AAPL data (model.fit). That means, our weights got adjusted based on the AAPL data i.e.let initial weights are W_init, we got W_aapl now. If you want to train the model from this w_aapl on the googl data, you don't need to intilize the model again. You can use trained model on aapl data. If you need another new model only for googl data, initilize the model and then train for googl data. If you want to get best model that works on both datasets, get the combined data(aapl+googl) and shuffle data and then train the model.
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Data Science Stack Exchange Author: Stupid_Intern Source score (net votes, not local likes): 0 Original post: https://datascience.stackexchange.com/questions/108849 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Suppose if I have two datasets where 1st dataset is AAPL stock price and 2nd dataset is GOOGL stock price. Now if I define the model as model =Sequential() model.add(LSTM(100, activation='relu', input_shape=(n_input,n_features))) model.add(Dense(1)) model.compile(optimizer='adam', loss='mse') model.summary() and then train and fit it on first dataset df = pd.read_csv('data\\AAPL.csv', index_col = 0) train = df[['close']].iloc[:int(len(df)*0.8)] scaler = MinMaxScaler() scaler.fit(train) scaled_train = scaler.transform(train) #------------------------------------------------------ generator = TimeseriesGenerator(scaled_train,scaled_train,length=n_input, batch_size=1) #----------------------------------------------------- #fit model model.fit(generator,epochs=10) then if I have to fit the model on second dataset do I need to define it again? if not then why does the output of model.fit differs when I define the model again before fitting it on second dataset?

Cancel quote

Checking account access…