ium_434684/ium_zadanie5.py
2021-04-25 21:38:20 +02:00

44 lines
1.2 KiB
Python

import tensorflow as tf
from keras.models import Sequential
from keras import layers
# from keras.layers import Flatten,Dense,Dropout, GlobalAveragePooling2D
from keras.optimizers import Adam
import numpy as np
import pandas as pd
from sklearn.metrics import mean_squared_error
movies_train = pd.read_csv('movies_train.csv')
movies_test = pd.read_csv('movies_test.csv')
x_train = movies_train.copy()
x_test = movies_test.copy()
y_train = x_train.pop('rottentomatoes_audience_score')
y_test = x_test.pop('rottentomatoes_audience_score')
x_train.pop('Unnamed: 0')
x_test.pop('Unnamed: 0')
model = Sequential()
model.add(layers.Input(shape=(22,)))
model.add(layers.Dense(64))
model.add(layers.Dense(64))
model.add(layers.Dense(32))
model.add(layers.Dense(1))
model.compile(loss='mean_absolute_error', optimizer=Adam(0.001))
history = model.fit(
x = tf.convert_to_tensor(x_train, np.float32),
y = y_train,
verbose=0, epochs=99)
y_predicted = model.predict(x_test, batch_size=64)
error = mean_squared_error(y_test, y_predicted)
np.savetxt("test_predictions.csv", y_predicted, delimiter=",")
with open('evaluation.txt', 'w') as f:
f.write('Mean square error: %d' % error)