Feat: Code Update

This commit is contained in:
Jakub Zaręba 2023-05-07 21:10:11 +02:00
parent 1558a59cdd
commit 4a7ae9e7bc
4 changed files with 48752 additions and 1 deletions

View File

@ -2,6 +2,15 @@ FROM ubuntu
RUN apt-get update && apt-get install -y python3 python3-pip unzip
RUN pip3 install kaggle pandas
RUN python3 -m pip install kaggle numpy pandas torchvision torch
COPY ium_DL.py
COPY ./olympics-124-years-datasettill-2020/Athletes_winter_games.csv
RUN chmod +r ./ium_DL.py
RUN chmod +r ./Athletes_winter_games.csv
RUN chmod +r ./olympics-124-years-datasettill-2020/Athletes_winter_games.csv
RUN python3 ./ium_DL.py
WORKDIR /app

34
ium_DL.py Normal file
View File

@ -0,0 +1,34 @@
import tensorflow as tf
import pandas as pd
train_data = pd.read_csv('olympics-124-years-datasettill-2020/Athletes_winter_games.csv')
X_train = train_data[['Sex']]
y_train = train_data['Medal']
X_train.loc[:, 'Sex'] = X_train['Sex'].map({'M': 0, 'F': 1})
y_train = y_train.map({'Bronze': 0, 'Silver': 1, 'Gold': 1}).fillna(0).astype('float32')
X_train = X_train.astype('float32')
y_train = y_train.astype('float32')
model = tf.keras.Sequential([
tf.keras.layers.Dense(16, activation='relu', input_shape=(X_train.shape[1],)),
tf.keras.layers.Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
model.fit(X_train, y_train, epochs=10)
model.save('model.h5')
test_data = pd.read_csv('olympics-124-years-datasettill-2020/Athletes_winter_games.csv')
test_data.loc[:, 'Sex'] = test_data['Sex'].map({'M': 0, 'F': 1})
test_data = test_data[['Sex']].astype('float32')
predictions = model.predict(test_data)
pd.DataFrame(predictions).to_csv('predictions.csv', index=False, header=False)

144
lab5.ipynb Normal file
View File

@ -0,0 +1,144 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Epoch 1/10\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\kmjay\\AppData\\Local\\Temp\\ipykernel_17164\\3575846689.py:9: SettingWithCopyWarning: \n",
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
"Try using .loc[row_indexer,col_indexer] = value instead\n",
"\n",
"See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
" X_train.loc[:, 'Sex'] = X_train['Sex'].map({'M': 0, 'F': 1})\n",
"C:\\Users\\kmjay\\AppData\\Local\\Temp\\ipykernel_17164\\3575846689.py:9: DeprecationWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`\n",
" X_train.loc[:, 'Sex'] = X_train['Sex'].map({'M': 0, 'F': 1})\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1518/1518 [==============================] - 2s 758us/step - loss: 0.3609 - accuracy: 0.9112\n",
"Epoch 2/10\n",
"1518/1518 [==============================] - 1s 726us/step - loss: 0.2763 - accuracy: 0.9216\n",
"Epoch 3/10\n",
"1518/1518 [==============================] - 1s 731us/step - loss: 0.2751 - accuracy: 0.9216\n",
"Epoch 4/10\n",
"1518/1518 [==============================] - 1s 725us/step - loss: 0.2750 - accuracy: 0.9216\n",
"Epoch 5/10\n",
"1518/1518 [==============================] - 1s 733us/step - loss: 0.2750 - accuracy: 0.9216\n",
"Epoch 6/10\n",
"1518/1518 [==============================] - 1s 733us/step - loss: 0.2750 - accuracy: 0.9216\n",
"Epoch 7/10\n",
"1518/1518 [==============================] - 1s 729us/step - loss: 0.2750 - accuracy: 0.9216\n",
"Epoch 8/10\n",
"1518/1518 [==============================] - 1s 728us/step - loss: 0.2750 - accuracy: 0.9216\n",
"Epoch 9/10\n",
"1518/1518 [==============================] - 1s 727us/step - loss: 0.2750 - accuracy: 0.9216\n",
"Epoch 10/10\n",
"1518/1518 [==============================] - 1s 755us/step - loss: 0.2750 - accuracy: 0.9216\n"
]
}
],
"source": [
"import tensorflow as tf\n",
"import pandas as pd\n",
"\n",
"train_data = pd.read_csv('olympics-124-years-datasettill-2020/Athletes_winter_games.csv')\n",
"\n",
"X_train = train_data[['Sex']]\n",
"y_train = train_data['Medal']\n",
"\n",
"X_train.loc[:, 'Sex'] = X_train['Sex'].map({'M': 0, 'F': 1})\n",
"y_train = y_train.map({'Bronze': 0, 'Silver': 1, 'Gold': 1}).fillna(0).astype('float32')\n",
"\n",
"X_train = X_train.astype('float32')\n",
"y_train = y_train.astype('float32')\n",
"\n",
"model = tf.keras.Sequential([\n",
" tf.keras.layers.Dense(16, activation='relu', input_shape=(X_train.shape[1],)),\n",
" tf.keras.layers.Dense(1, activation='sigmoid')\n",
"])\n",
"\n",
"model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])\n",
"\n",
"model.fit(X_train, y_train, epochs=10)\n",
"\n",
"model.save('model.h5')"
]
},
{
"cell_type": "code",
"execution_count": 52,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 170/1518 [==>...........................] - ETA: 0s"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\kmjay\\AppData\\Local\\Temp\\ipykernel_17164\\2746302769.py:3: DeprecationWarning: In a future version, `df.iloc[:, i] = newvals` will attempt to set the values inplace instead of always setting a new array. To retain the old behavior, use either `df[df.columns[i]] = newvals` or, if columns are non-unique, `df.isetitem(i, newvals)`\n",
" test_data.loc[:, 'Sex'] = test_data['Sex'].map({'M': 0, 'F': 1})\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1518/1518 [==============================] - 1s 574us/step\n"
]
}
],
"source": [
"test_data = pd.read_csv('olympics-124-years-datasettill-2020/Athletes_winter_games.csv')\n",
"\n",
"test_data.loc[:, 'Sex'] = test_data['Sex'].map({'M': 0, 'F': 1})\n",
"test_data = test_data[['Sex']].astype('float32')\n",
"\n",
"predictions = model.predict(test_data)\n",
"\n",
"pd.DataFrame(predictions).to_csv('predictions.csv', index=False, header=False)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}

48564
predictions.csv Normal file

File diff suppressed because it is too large Load Diff