2021-04-21 22:08:54 +02:00
|
|
|
import numpy as np
|
|
|
|
import pandas as pd
|
|
|
|
import tensorflow as tf
|
|
|
|
import sys
|
2021-05-10 19:36:19 +02:00
|
|
|
import wget
|
2021-04-21 22:08:54 +02:00
|
|
|
from tensorflow import keras
|
|
|
|
from sklearn.metrics import r2_score, mean_squared_error
|
|
|
|
from math import sqrt
|
|
|
|
from sklearn.model_selection import train_test_split
|
|
|
|
from sklearn import preprocessing
|
|
|
|
# Importing the dataset
|
|
|
|
|
|
|
|
url = 'https://git.wmi.amu.edu.pl/s434804/ium_434804/raw/branch/master/country_vaccinations.csv'
|
|
|
|
wget.download(url, out='country_vaccinations.csv', bar=None)
|
|
|
|
|
|
|
|
df = pd.read_csv('country_vaccinations.csv').dropna()
|
|
|
|
dataset = df.iloc[:, 3:-3]
|
|
|
|
sys.stdout=open("prediction_output.txt","w")
|
|
|
|
print(dataset.head())
|
|
|
|
dataset = df.groupby(by=["country"], dropna=True).sum()
|
|
|
|
X = dataset.loc[:,dataset.columns != "daily_vaccinations"]
|
|
|
|
y = dataset.loc[:,dataset.columns == "daily_vaccinations"]
|
|
|
|
|
|
|
|
# Splitting the dataset into the Training set and Test set
|
|
|
|
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 42)
|
|
|
|
|
|
|
|
# Feature Scaling
|
|
|
|
model = keras.Sequential([
|
|
|
|
keras.layers.Dense(512,input_dim = X_train.shape[1],kernel_initializer='normal', activation='relu'),
|
|
|
|
keras.layers.Dense(512,kernel_initializer='normal', activation='relu'),
|
|
|
|
keras.layers.Dense(256,kernel_initializer='normal', activation='relu'),
|
|
|
|
keras.layers.Dense(256,kernel_initializer='normal', activation='relu'),
|
|
|
|
keras.layers.Dense(128,kernel_initializer='normal', activation='relu'),
|
|
|
|
keras.layers.Dense(1,kernel_initializer='normal', activation='linear'),
|
|
|
|
])
|
|
|
|
|
|
|
|
model.compile(loss='mean_absolute_error', optimizer='adam', metrics=['mean_absolute_error'])
|
|
|
|
|
|
|
|
model.fit(X_train, y_train, epochs=50, validation_split = 0.3)
|
|
|
|
|
|
|
|
prediction = model.predict(X_test)
|
|
|
|
print(prediction)
|
2021-05-10 19:36:19 +02:00
|
|
|
sys.stdout.close()
|
|
|
|
model.save('vaccines_model')
|