145 lines
5.2 KiB
Plaintext
145 lines
5.2 KiB
Plaintext
![]() |
{
|
||
|
"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
|
||
|
}
|