image_output_1.png
from keras.layers import Dense, LSTM

from keras.models import Sequential

from sklearn.preprocessing import MinMaxScaler

import math

import matplotlib.pyplot as plt

import matplotlib.pyplot as plt

import numpy as np

import numpy as np

import numpy as np # linear algebra

import pandas as pd

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import warnings

import warnings

submission = pd.read_csv('/kaggle/input/gdz22-datathon/submission.csv')
df = pd.read_csv('/kaggle/input/gdz22-datathon/train.csv')
trafo = pd.read_csv('/kaggle/input/gdz22-datathon/trafo.csv')
bulutluluk_orani = pd.read_csv('/kaggle/input/gdz22-datathon/Hava Durumu/Bulutluluk Oranı.csv')
bagil_nem = pd.read_csv('/kaggle/input/gdz22-datathon/Hava Durumu/Bağıl Nem.csv')
radyasyon = pd.read_csv('/kaggle/input/gdz22-datathon/Hava Durumu/Radyasyon.csv')
sicaklik = pd.read_csv('/kaggle/input/gdz22-datathon/Hava Durumu/Sıcaklık.csv')
ruzgar_yonu = pd.read_csv('/kaggle/input/gdz22-datathon/Hava Durumu/Rüzgar Yönü.csv')
yagis = pd.read_csv('/kaggle/input/gdz22-datathon/Hava Durumu/Yağış.csv')
ruzgar_hizi = pd.read_csv('/kaggle/input/gdz22-datathon/Hava Durumu/Rüzgar Hızı.csv')

df['BAŞLAMA_TARİHİ_VE_ZAMANI'] = pd.to_datetime(df['BAŞLAMA_TARİHİ_VE_ZAMANI'])

df = df.sort_values(by='BAŞLAMA_TARİHİ_VE_ZAMANI')
df

df = pd.merge(df, trafo, on='ŞEBEKE_UNSURU_KODU', how='left')

df.columns

df.groupby(['trafo_id']).sum()['KESİNTİ_SÜRESİ']

df.groupby('trafo_id').sum()['KESİNTİ_SÜRESİ'].reset_index()

a = df.groupby('trafo_id').sum()['KESİNTİ_SÜRESİ'].reset_index()
a.columns = ['trafo_id', 'KESİNTİ_SÜRESİ_YENİ']
a

df = pd.merge(df, a, on='trafo_id')

dfa = df[['Tarih', 'KESİNTİ_SÜRESİ_YENİ']].sort_values(by='Tarih')
dfa

df_new = dfa.groupby('Tarih').sum()

import warnings
warnings.filterwarnings('ignore')
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
warnings.filterwarnings('ignore')
import os
from decimal import ROUND_HALF_UP, Decimal
import numpy as np
import pandas as pd
from lightgbm import LGBMRegressor
from tqdm import tqdm
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
from keras.models import Sequential
from keras.layers import Dense, LSTM

import math
dataset = df_new.values
training_data_len = math.ceil(len(dataset) * 0.8)
training_data_len

from sklearn.preprocessing import MinMaxScaler
sc = MinMaxScaler(feature_range=(0, 1))
scaled_data = sc.fit_transform(dataset)

train_data = scaled_data[0:training_data_len, :]
x_train = []
y_train = []
num = 80
for i in range(num, len(train_data)):
    x_train.append(train_data[i - num:i, 0])
    y_train.append(train_data[i, 0])

x_train, y_train = (np.array(x_train), np.array(y_train))
x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
x_train.shape

model = Sequential()
model.add(LSTM(50, return_sequences=True, input_shape=(x_train.shape[1], 1)))
model.add(LSTM(50, return_sequences=False))
model.add(Dense(25))
model.add(Dense(1))
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(x_train, y_train, batch_size=1, epochs=10)

test_data = scaled_data[training_data_len - num:, :]
x_test = []
y_test = dataset[training_data_len:, :]
for i in range(num, len(test_data)):
    x_test.append(test_data[i - num:i, 0])

x_test = np.array(x_test)
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))

predictions = model.predict(x_test)
predictions = sc.inverse_transform(predictions)

col = 'KESİNTİ_SÜRESİ_YENİ'
train = df_new[:training_data_len]
valid = df_new[training_data_len:]
valid['Predictions'] = predictions
plt.figure(figsize=(20, 8))
plt.title('Kesinti süresi')
plt.xlabel('Date', fontsize=28)
plt.ylabel(col, fontsize=28)
plt.plot(train[col])
plt.plot(valid[[col, 'Predictions']])
plt.legend(['Train', 'Val', 'Predictions'])