2021-05-14 02:20:16 +02:00
|
|
|
import sys
|
|
|
|
|
2021-05-13 22:20:25 +02:00
|
|
|
import pandas as pd
|
|
|
|
import numpy as np
|
|
|
|
import tensorflow as tf
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
from tensorflow import keras
|
|
|
|
from tensorflow.keras import layers
|
|
|
|
from tensorflow.keras.layers.experimental import preprocessing
|
|
|
|
|
2021-05-14 02:20:16 +02:00
|
|
|
arguments = sys.argv[1:]
|
|
|
|
|
2021-05-14 04:01:11 +02:00
|
|
|
verbose = [command.split('=')[1] for command in arguments if command.split('=')[0] == 'verbose']
|
|
|
|
epochs = [command.split('=')[1] for command in arguments if command.split('=')[0] == 'epochs']
|
|
|
|
|
2021-05-14 02:20:16 +02:00
|
|
|
|
2021-05-13 22:20:25 +02:00
|
|
|
pd.set_option("display.max_columns", None)
|
|
|
|
|
|
|
|
# Wczytanie danych
|
2021-05-14 00:58:33 +02:00
|
|
|
train_data = pd.read_csv("./MoviesOnStreamingPlatforms_updated.train")
|
2021-05-13 22:20:25 +02:00
|
|
|
|
|
|
|
# Stworzenie modelu
|
|
|
|
columns_to_use = ['Year', 'Runtime', 'Netflix']
|
|
|
|
train_X = tf.convert_to_tensor(train_data[columns_to_use])
|
|
|
|
train_Y = tf.convert_to_tensor(train_data[["IMDb"]])
|
|
|
|
|
|
|
|
normalizer = preprocessing.Normalization(input_shape=[3,])
|
|
|
|
normalizer.adapt(train_X)
|
|
|
|
|
|
|
|
if os.path.isdir('linear_regression'):
|
|
|
|
model = keras.models.load_model('linear_regression')
|
|
|
|
else:
|
|
|
|
model = keras.Sequential([
|
|
|
|
keras.Input(shape=(len(columns_to_use),)),
|
|
|
|
normalizer,
|
2021-05-14 04:01:11 +02:00
|
|
|
layers.Dense(30, activation='relu'),
|
|
|
|
layers.Dense(10, activation='relu'),
|
|
|
|
layers.Dense(25, activation='relu'),
|
2021-05-13 22:20:25 +02:00
|
|
|
layers.Dense(1)
|
|
|
|
])
|
|
|
|
|
|
|
|
model.compile(loss='mean_absolute_error',
|
2021-05-14 04:01:11 +02:00
|
|
|
optimizer=tf.keras.optimizers.Adam(0.001),
|
|
|
|
metrics=[tf.keras.metrics.RootMeanSquaredError()])
|
2021-05-13 22:20:25 +02:00
|
|
|
|
2021-05-14 04:12:42 +02:00
|
|
|
verbose = 0 if len(verbose) == 0 else int(verbose[0])
|
|
|
|
epochs = 100 if len(epochs) == 0 else int(epochs[0])
|
2021-05-14 04:01:11 +02:00
|
|
|
model.fit(train_X, train_Y, verbose=verbose, epochs=epochs)
|
2021-05-13 22:20:25 +02:00
|
|
|
|
2021-05-14 04:01:11 +02:00
|
|
|
model.save('linear_regression.h5')
|