Skip to content

Instantly share code, notes, and snippets.

@daveklotz
Created July 31, 2021 19:35
Show Gist options
  • Save daveklotz/a798c85edb64352d104921a1521c3238 to your computer and use it in GitHub Desktop.
Save daveklotz/a798c85edb64352d104921a1521c3238 to your computer and use it in GitHub Desktop.
BaseballANN-DRAminus.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "BaseballANN-DRAminus.ipynb",
"provenance": [],
"collapsed_sections": [],
"include_colab_link": true
},
"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.8.5"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/daveklotz/a798c85edb64352d104921a1521c3238/baseballann-draminus.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "lP6JLo1tGNBg"
},
"source": [
"# DRA- Based Artificial Neural Network"
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true,
"id": "MxkJoQBkUIHC"
},
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import tensorflow as tf\n",
"from sklearn.preprocessing import StandardScaler\n",
"from sklearn.model_selection import KFold\n"
],
"execution_count": 1,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"collapsed": true,
"id": "SyEfdFFEAOMb"
},
"source": [
"np.set_printoptions(suppress=True)\n",
"tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)"
],
"execution_count": 2,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"collapsed": true,
"id": "MXUkhkMfU4wq"
},
"source": [
"#dataset = pd.read_csv('mlb odds 2019-DRAm-random-games.csv')\n",
"dataset = pd.read_csv('ann_input_example.csv')\n",
"\n",
"# 1 - Game ID, / 0\n",
"# 4 - FEATURE: Visitor or Home as 0 or 1, / 1\n",
"# 48 - FEATURE: Win % diff (team - opponent), / 2\n",
"# 60 - FEATURE: Starter DRA- diff / 3\n",
"\n",
"X = dataset.iloc[:, [1, 4, 48, 60]].values\n",
"y = dataset.iloc[:, 54].values"
],
"execution_count": 16,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"collapsed": true,
"id": "-M1KboxFb6OO"
},
"source": [
"sc = StandardScaler()\n",
"X_scaled = X\n",
"X_scaled[:, [1, 2, 3]] = sc.fit_transform(X[:, [1, 2, 3]])\n"
],
"execution_count": 19,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"scrolled": true,
"id": "3hMEObuEAOMp"
},
"source": [
"units = 10\n",
"\n",
"ann = tf.keras.models.Sequential()\n",
"#ann.add(tf.keras.layers.Dense(units=units, activation='relu'))\n",
"#ann.add(tf.keras.layers.Dense(units=units, activation='relu'))\n",
"#ann.add(tf.keras.layers.Dense(units=units, activation='relu'))\n",
"ann.add(tf.keras.layers.Dense(units=units, activation='sigmoid'))\n",
"ann.add(tf.keras.layers.Dense(units=units, activation='sigmoid'))\n",
"ann.add(tf.keras.layers.Dense(units=units, activation='sigmoid'))\n",
"\n",
"\n",
"ann.add(tf.keras.layers.Dense(units=1, activation='sigmoid'))\n",
"ann.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy'])\n",
"\n",
"\n",
"X_for_training = X_scaled\n",
"X_for_training = X_for_training[:, [1,2,3]]\n",
"#print(X_for_training)\n",
"\n",
"\n",
"\n"
],
"execution_count": 22,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "0uZiMAtnAOMr"
},
"source": [
"history = ann.fit(X_for_training, y, batch_size = 8, epochs = 100, verbose=1)"
],
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "I1h0Sy2BAOMs",
"outputId": "83e8cb3c-77dc-44aa-a2ab-781dc481a0af"
},
"source": [
"prediction = ann.predict( sc.transform([[0, 0, 0]]) )\n",
"print(prediction[0][0])\n",
"\n",
"prediction = ann.predict( sc.transform([[1, 0, 0]]) )\n",
"print(prediction[0][0])"
],
"execution_count": 25,
"outputs": [
{
"output_type": "stream",
"text": [
"0.49958766\n",
"0.5308103\n"
],
"name": "stdout"
}
]
},
{
"cell_type": "code",
"metadata": {
"collapsed": true,
"id": "1bTwDJoVAOMt"
},
"source": [
""
],
"execution_count": null,
"outputs": []
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment