<jupyter_start><jupyter_text>****Preprocessing<jupyter_code>import torch
import torchvision
from torch import nn
from torch import optim
from torch.utils.data import DataLoader
import pandas as pd
from sklearn.linear_model import LinearRegression
import numpy as np

#*** PREPROCESSING ***

def preprocess(train_path, test_path, test=False):
  df = pd.read_csv(train_path)[:restrict_idx]
  df = df.dropna(subset=['Sales'])

  df_test = pd.read_csv(test_path)
  del df_test['Id']
  l_test = len(df_test)
  
  df_test['Sales'] = 0
  df = pd.concat([df, df_test])

  print(df.columns)

  df['month'] = pd.DatetimeIndex(df['Date']).month
  df['DayInMonth'] = pd.DatetimeIndex(df['Date']).day
  df = pd.get_dummies(data=df, columns=['Store','AssortmentType', 'StoreType', 'StateHoliday', "month", "DayOfWeek"])
  del df["Date"]
  Y = df["Sales"].values
  del df["Sales"]

  df = df.values
    
  return df, Y, l_test

X_train, Y_train, l_test = preprocess("/content/drive/MyDrive/Lithuanian_Challenge/train_data.csv", "/content/drive/MyDrive/Lithuanian_Challenge/test_data.csv")

X_test_submission, X_train, Y_train = X_train[-l_test:], X_train[:-l_test], Y_train[:-l_test]

X_val, Y_val = X_train[-50000:], Y_train[-50000:] 
X_train, Y_train = X_train[:-50000], Y_train[:-50000]  


print('Submission Set Shape: ',X_test_submission.shape)
print('Train Set Shape: ',X_train.shape)
print('Y Train Shape: ', Y_train.shape)
print('Validation Set Shape: ', X_val.shape)<jupyter_output>/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py:2822: DtypeWarning: Columns (6) have mixed types.Specify dtype option on import or set low_memory=False.
  if self.run_code(code, result):<jupyter_text>****CNN<jupyter_code>from keras import optimizers
from keras.utils import plot_model
from keras.models import Sequential, Model
from keras.layers.convolutional import Conv1D, MaxPooling1D
from keras.layers import Dense, LSTM, RepeatVector, TimeDistributed, Flatten, Dropout


from keras import backend as K
def rmse(y_true, y_pred):
        return K.sqrt(K.mean(K.square(float(y_pred) - float(y_true)))) 

X_train = X_train.reshape((X_train.shape[0], X_train.shape[1], 1))
X_val = X_val.reshape((X_val.shape[0], X_val.shape[1], 1))

epochs = 3
batch = 256
lr = 0.001
adam = optimizers.Adam(lr)

model_cnn = Sequential()
model_cnn.add(Conv1D(filters=256, kernel_size=2, activation='relu', input_shape=(X_train.shape[1], X_train.shape[2])))
model_cnn.add(MaxPooling1D(pool_size=2))
model_cnn.add(Flatten())
model_cnn.add(Dropout(0.1))
model_cnn.add(Dense(1024, activation='relu'))
model_cnn.add(Dense(1))
model_cnn.compile(loss=rmse, optimizer=adam)
model_cnn.summary()


cnn_history = model_cnn.fit(X_train, Y_train, epochs=epochs, validation_data=(X_val, Y_val), verbose=1) 
res = model_cnn.predict(X_test_submission.reshape((X_test_submission.shape[0], X_test_submission.shape[1], 1)))
print("res_min", np.min(res))
print('res_max', np.max(res))
print('res_mean', np.mean(res))<jupyter_output>res_min -167.53598
res_max 21987.955
res_mean 7085.8296
{'fraction_non_alphanumeric': 0.14890127910790424, 'fraction_numerical': 0.028861921941620204, 'mean_word_length': 6.45721271393643, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '506080', 'license': 'MIT', 'n_tokens_mistral': 1255, 'n_tokens_neox': 1176, 'n_words': 215, 'path': 'Track-2-store-sales-predictions/CNN.ipynb', 'repo_name': 'mantasbandonis/lithuanian_ai_hackathon', 'size': '3049'}