Forum Discussion
Change column type change value from another column (Python script)
Hi.
I tried what you said but that also change the values.
Hi inm ,
Could you please consider sharing a sample file without any sesentive information or the sample python script query code for further discussion?
Best Regards,
Community Support Team _ Yingjie Li
- inm5 years agoHelper II
Python script:
import pandas as pd
import numpy as np
from keras.layers import Dense, LSTM
from keras.models import Sequential
from keras.preprocessing.sequence import TimeseriesGeneratordef get_prediction_dates(num_prediction, df):
last_date = df['date'].max()
date_test = pd.date_range(last_date, periods=num_prediction+1, freq='M').to_frame(index=False, name='date')
date_test = date_test['date'].apply(lambda x : x.replace(day=1))
return date_test
def predict(num_prediction, model):
prediction_list = arr[-look_back:]
for _ in range(num_prediction):
x = prediction_list[-look_back:]
x = x.reshape((1, look_back, 1))
out = model.predict(x)[0][0]
prediction_list = np.append(prediction_list, out)
prediction_list = prediction_list[look_back-1:]
return prediction_list
look_back = 12
batch_size = 4arr = dataset['quantity'].values
arr = arr.reshape((-1, 1))generator = TimeseriesGenerator(arr, arr, length=look_back, batch_size = batch_size)
model = Sequential()
model.add(
LSTM(128,
activation='linear',
input_shape=(look_back, 1),
name="LSTM")
)
model.add(Dense(1, activation='linear', name="Dense"))
model.compile(optimizer='adam', loss='mse', metrics=['mean_absolute_percentage_error'])model.fit(generator, epochs=70)
num_prediction = 6
forecast = predict(num_prediction, model)
forecast_dates = get_prediction_dates(num_prediction, dataset)dataset = pd.DataFrame(list(zip(forecast_dates, forecast)), columns=['date', 'prediction'])
dataset['date'] = pd.to_datetime(dataset['date'])
I placed a seed, but is there any other way to prevent this from happening?