38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
|
import pandas as pd
|
||
|
import numpy as np
|
||
|
from sklearn.metrics import mean_squared_error
|
||
|
from keras.models import Sequential
|
||
|
from keras.layers import Dense
|
||
|
|
||
|
in_columns = ['id_stacji', 'nazwa_stacji', 'typ_zbioru', 'rok', 'miesiąc']
|
||
|
df = pd.read_csv('train/in.tsv', names=in_columns, sep='\t')
|
||
|
df_test = pd.read_csv('dev-0/in.tsv', names=in_columns, sep='\t')
|
||
|
df = pd.concat([df,df_test])
|
||
|
df = df.drop(['nazwa_stacji','typ_zbioru'], axis=1)
|
||
|
x = pd.get_dummies(df,columns = ['id_stacji','rok','miesiąc'])
|
||
|
|
||
|
x = x.iloc[:-600]
|
||
|
y = pd.read_csv('train/expected.tsv', sep='\t', names=['rainfall'])
|
||
|
|
||
|
# Keras
|
||
|
model = Sequential()
|
||
|
model.add(Dense(16, input_dim=73, activation= "relu"))
|
||
|
model.add(Dense(32, activation= "relu"))
|
||
|
model.add(Dense(64, activation= "relu"))
|
||
|
model.add(Dense(32, activation= "relu"))
|
||
|
model.add(Dense(16, activation= "relu"))
|
||
|
model.add(Dense(1))
|
||
|
|
||
|
model.compile(loss= "mean_squared_error" , optimizer="adam", metrics=["mean_squared_error"])
|
||
|
model.fit(x, y, epochs=40)
|
||
|
|
||
|
#Final Test
|
||
|
x_test = pd.read_csv('test-A/in.tsv', sep='\t', names=in_columns)
|
||
|
df_train = pd.read_csv('train/in.tsv', names=in_columns, sep='\t')
|
||
|
x_test = pd.concat([x_test,df_train])
|
||
|
x_test = x_test.drop(['nazwa_stacji', 'typ_zbioru'],axis=1)
|
||
|
x_test = pd.get_dummies(x_test,columns = ['id_stacji','rok','miesiąc'])
|
||
|
x_test = x_test.iloc[:-8760]
|
||
|
pred= model.predict(x_test)
|
||
|
out = pd.DataFrame(pred)
|
||
|
out.to_csv('test-A/out.tsv',sep='\t',header=False, index=False)
|