Michael Rey
commited on
Commit
ยท
fc29f39
1
Parent(s):
56f4745
initial commit
Browse files- app.py +128 -0
- high_diamond_ranked_10min.csv +0 -0
- requirements.txt +6 -0
app.py
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import seaborn as sns
|
| 6 |
+
from sklearn.model_selection import train_test_split
|
| 7 |
+
from sklearn.preprocessing import StandardScaler
|
| 8 |
+
from sklearn.linear_model import LogisticRegression
|
| 9 |
+
from sklearn.metrics import accuracy_score, classification_report, confusion_matrix
|
| 10 |
+
|
| 11 |
+
# Custom Streamlit styling - Dark mode version
|
| 12 |
+
st.markdown(
|
| 13 |
+
"""
|
| 14 |
+
<style>
|
| 15 |
+
body {
|
| 16 |
+
background-color: #1E1E1E;
|
| 17 |
+
color: #FFFFFF;
|
| 18 |
+
font-family: 'Arial', sans-serif;
|
| 19 |
+
}
|
| 20 |
+
.stButton>button {
|
| 21 |
+
background-color: #4A90E2;
|
| 22 |
+
color: #FFFFFF;
|
| 23 |
+
border-radius: 15px;
|
| 24 |
+
padding: 12px 24px;
|
| 25 |
+
font-size: 16px;
|
| 26 |
+
font-weight: bold;
|
| 27 |
+
}
|
| 28 |
+
# .stSlider>div>div>div {
|
| 29 |
+
# background-color: #4A90E2;
|
| 30 |
+
}
|
| 31 |
+
.title {
|
| 32 |
+
color: #64FFDA;
|
| 33 |
+
text-shadow: 1px 1px #FF4C4C;
|
| 34 |
+
}
|
| 35 |
+
# .stSlider label, .stSlider>div>div>span {
|
| 36 |
+
# color: #FFFFFF !important;
|
| 37 |
+
}
|
| 38 |
+
</style>
|
| 39 |
+
""",
|
| 40 |
+
unsafe_allow_html=True
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
# Load the League of Legends dataset
|
| 44 |
+
st.title("๐ฎ League of Legends Game Win Predictor")
|
| 45 |
+
st.markdown("<h2 class='title'>Predict whether the Blue Team will dominate the game! ๐ฅ</h2>", unsafe_allow_html=True)
|
| 46 |
+
|
| 47 |
+
# Load dataset directly
|
| 48 |
+
file_path = 'high_diamond_ranked_10min.csv'
|
| 49 |
+
df = pd.read_csv(file_path)
|
| 50 |
+
st.write("### ๐ Dataset Preview")
|
| 51 |
+
st.dataframe(df.head())
|
| 52 |
+
|
| 53 |
+
# Select relevant columns
|
| 54 |
+
df = df[['blueFirstBlood', 'blueKills', 'blueDeaths', 'blueAssists', 'blueTotalGold', 'blueTotalExperience', 'blueDragons', 'blueHeralds', 'blueTowersDestroyed', 'blueWins']]
|
| 55 |
+
df = df.dropna()
|
| 56 |
+
|
| 57 |
+
# Define features and target
|
| 58 |
+
X = df.drop('blueWins', axis=1)
|
| 59 |
+
y = df['blueWins']
|
| 60 |
+
|
| 61 |
+
# Split data
|
| 62 |
+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
|
| 63 |
+
|
| 64 |
+
# Scale data
|
| 65 |
+
scaler = StandardScaler()
|
| 66 |
+
X_train = scaler.fit_transform(X_train)
|
| 67 |
+
X_test = scaler.transform(X_test)
|
| 68 |
+
|
| 69 |
+
# Train Logistic Regression Model
|
| 70 |
+
model = LogisticRegression(random_state=42)
|
| 71 |
+
model.fit(X_train, y_train)
|
| 72 |
+
y_pred = model.predict(X_test)
|
| 73 |
+
|
| 74 |
+
# Display model performance
|
| 75 |
+
accuracy = accuracy_score(y_test, y_pred)
|
| 76 |
+
st.write("### ๐ฅ Model Performance")
|
| 77 |
+
st.write(f"**โ
Model Accuracy:** {accuracy:.2f}")
|
| 78 |
+
|
| 79 |
+
# Visualizing performance
|
| 80 |
+
st.write("### ๐ Performance Breakdown")
|
| 81 |
+
conf_matrix = confusion_matrix(y_test, y_pred)
|
| 82 |
+
st.write("Confusion Matrix:")
|
| 83 |
+
fig, ax = plt.subplots()
|
| 84 |
+
sns.heatmap(conf_matrix, annot=True, fmt='d', cmap='coolwarm', ax=ax)
|
| 85 |
+
st.pyplot(fig)
|
| 86 |
+
|
| 87 |
+
# Feature Importance Visualization
|
| 88 |
+
st.write("### ๐ Feature Importance")
|
| 89 |
+
feature_importance = abs(model.coef_[0])
|
| 90 |
+
features = X.columns
|
| 91 |
+
fig, ax = plt.subplots()
|
| 92 |
+
ax.barh(features, feature_importance, color='#4A90E2')
|
| 93 |
+
ax.set_title("Feature Importance for Blue Team Win Prediction")
|
| 94 |
+
ax.set_xlabel("Importance")
|
| 95 |
+
st.pyplot(fig)
|
| 96 |
+
|
| 97 |
+
# Prediction section
|
| 98 |
+
st.write("### ๐ฎ Predict Game Outcome")
|
| 99 |
+
st.markdown("Adjust the stats below to simulate a match scenario!")
|
| 100 |
+
|
| 101 |
+
first_blood = st.selectbox("Did Blue Team Get First Blood?", [0, 1])
|
| 102 |
+
kills = st.slider("Blue Team Kills", min_value=0, max_value=50, value=5)
|
| 103 |
+
deaths = st.slider("Blue Team Deaths", min_value=0, max_value=50, value=5)
|
| 104 |
+
assists = st.slider("Blue Team Assists", min_value=0, max_value=50, value=10)
|
| 105 |
+
total_gold = st.slider("Blue Team Total Gold", min_value=10000, max_value=100000, value=50000)
|
| 106 |
+
total_exp = st.slider("Blue Team Total Experience", min_value=10000, max_value=100000, value=50000)
|
| 107 |
+
dragons = st.slider("Blue Team Dragons Taken", min_value=0, max_value=5, value=1)
|
| 108 |
+
heralds = st.slider("Blue Team Heralds Taken", min_value=0, max_value=2, value=0)
|
| 109 |
+
towers = st.slider("Blue Team Towers Destroyed", min_value=0, max_value=11, value=2)
|
| 110 |
+
|
| 111 |
+
if st.button("โจ Predict Win"):
|
| 112 |
+
input_data = scaler.transform([[first_blood, kills, deaths, assists, total_gold, total_exp, dragons, heralds, towers]])
|
| 113 |
+
prediction = model.predict(input_data)[0]
|
| 114 |
+
prediction_proba = model.predict_proba(input_data)[0]
|
| 115 |
+
|
| 116 |
+
st.subheader("๐ฎ Prediction Result")
|
| 117 |
+
result_text = "๐
Blue Team is likely to WIN! ๐" if prediction == 1 else "โ๏ธ Blue Team is likely to LOSE. ๐"
|
| 118 |
+
st.success(result_text) if prediction == 1 else st.error(result_text)
|
| 119 |
+
st.write(f"Confidence: {prediction_proba[prediction]:.2f}")
|
| 120 |
+
|
| 121 |
+
# Win/Loss Bar Chart
|
| 122 |
+
st.write("### ๐ Win Probability Breakdown")
|
| 123 |
+
fig, ax = plt.subplots()
|
| 124 |
+
ax.bar(["Win", "Lose"], [prediction_proba[1], prediction_proba[0]], color=["#64FFDA", "#FF4C4C"])
|
| 125 |
+
ax.set_ylim(0, 1)
|
| 126 |
+
ax.set_ylabel("Probability")
|
| 127 |
+
ax.set_title("Blue Team Win/Loss Probability")
|
| 128 |
+
st.pyplot(fig)
|
high_diamond_ranked_10min.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
matplotlib
|
| 5 |
+
seaborn
|
| 6 |
+
scikit-learn
|