Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
Binary file added Escape Room/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes
453 changes: 453 additions & 0 deletions Escape Room/your-code/.ipynb_checkpoints/sample-code-checkpoint.ipynb

Large diffs are not rendered by default.

716 changes: 716 additions & 0 deletions Escape Room/your-code/main_vMaster 2.ipynb

Large diffs are not rendered by default.

Binary file added FIFA Moneyball/.DS_Store
Binary file not shown.
Binary file added FIFA Moneyball/deliverable/.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,348 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "kQvYkx3jmwdV"
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import seaborn as sns\n",
"import matplotlib.pyplot as plt\n",
"from sklearn import linear_model\n",
"from sklearn.preprocessing import StandardScaler"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "oF9NZcRpnZG5"
},
"outputs": [],
"source": [
"players_fifa = pd.read_csv('Fifa 23 Players Data Final.csv')\n",
"\n",
"players = players_fifa[['Full Name', 'Overall', 'Potential', 'Value',\n",
" 'Positions Played','Best Position', 'Nationality', 'Age','Club Name', 'Wage', 'Release Clause', 'Club Position',\n",
" 'Contract Until']]\n",
"\n",
"#We create a subset with only the players that play for Real Madrid, so we can analize our team\n",
"\n",
"Real_Madrid = players[players['Club Name'] == 'Real Madrid CF']\n",
"Real_Madrid"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 237
},
"id": "jC7_yA10nyS8",
"outputId": "f6aae012-45d0-463c-c612-0128fd402811"
},
"outputs": [],
"source": [
"#We decided to sell our oldest players, so we filter our Real_Madrid DataFrame to find the players who are older than 30.\n",
"Real_Madrid[Real_Madrid['Age'] > 30]\n",
"\n",
"#We also take a look at their wages.\n",
"Real_Madrid[['Full Name', 'Wage']].sort_values(by='Wage', ascending= False).head(7)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "poJvQLrCMs-x"
},
"outputs": [],
"source": [
"#We start the search of our now players, filterting the dataset with the following conditions and we save the result in a new DataFrame.\n",
"\n",
"possible_transfers = players[players['Positions Played'].isin(['LW', 'LW,CAM','LW,LM','LW,ST']) & (players['Age'] < 25) & (players['Age'] > 20) & (players['Potential'] >= 85)]\n",
"\n",
"#Since we only want to analize the top 10 players, we update our DataFrame with only the top 10 players.\n",
"\n",
"possible_transfers = possible_transfers.head(10)\n",
"\n",
"#We create a new column called 'Transfer Index' where we can see how good the pontential of each player is compare to their Release Clause\n",
"\n",
"possible_transfers['Transfer Index'] = possible_transfers['Potential'] / possible_transfers['Release Clause']\n",
"\n",
"#We sort the data by this index and we pick the first player.\n",
"\n",
"possible_transfers.sort_values(by='Transfer Index', ascending = False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "Lq8bPexqnVlY",
"outputId": "57e257b7-0ea4-4a13-b81b-e00779ebaee2"
},
"outputs": [],
"source": [
"# Select the feature columns from the 'players' DataFrame\n",
"X = players[['Overall', 'Potential', 'Value', 'Age', 'Release Clause']]\n",
"\n",
"# Create a StandardScaler to standardize the feature data\n",
"scaler = StandardScaler()\n",
"\n",
"# Standardize the feature data using the StandardScaler\n",
"X_standardized = scaler.fit_transform(X)\n",
"\n",
"# Select the data for the player named 'Kvaratskhelia'\n",
"Kvaratskhelia = X_standardized[1284]\n",
"\n",
"# Reshape the 'Kvaratskhelia' data to match the shape of the other data\n",
"Kvaratskhelia = pd.DataFrame(Kvaratskhelia).transpose()\n",
"\n",
"# Remove the 'Kvaratskhelia' data from the standardized feature matrix\n",
"X_standardized = np.delete(X_standardized, 1284, axis=0)\n",
"\n",
"# Select the target column 'Wage' from the 'players' DataFrame\n",
"y = players[['Wage']]\n",
"\n",
"# Remove the 'Kvaratskhelia' row from the target data\n",
"y = y.drop(1284)\n",
"\n",
"# Create a Linear Regression model\n",
"model = linear_model.LinearRegression()\n",
"\n",
"# Fit the Linear Regression model to the standardized features and target\n",
"result = model.fit(X_standardized, y)\n",
"\n",
"#Finally we predict the wage of our player\n",
"predicted_wage = model.predict(Kvaratskhelia)\n",
"\n",
"print(predicted_wage)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Pick players for CM positions according to expected conditions\n",
"fifa_data_performance_CM = players_fifa[(players_fifa['Overall' ]>85) & (players_fifa['Age' ]<28) & (players_fifa['Club Name'] !='Real Madrid CF')&(players_fifa['Best Position']=='CM')]\n",
"fifa_data_performance_CM"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Data with more related columns\n",
"CM_selected = fifa_data_performance_CM[['Full Name','CM Rating',\"Passing Total\", \"Dribbling Total\", \"Defending Total\", \"Physicality Total\", \"Short Passing\", \"BallControl\", \"Vision\", \"Stamina\", \"Interceptions\", \"Positioning\"]]\n",
"\n",
"numeric_data = CM_selected.select_dtypes(include='number').corr()\n",
"plt.figure(figsize=(20, 5))\n",
"sns.heatmap(numeric_data,annot=True, cmap='viridis', fmt='.2f')\n",
"plt.title('Correlation Heatmap')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Data with more refined skills from previous findings above\n",
"CM_selected_second = fifa_data_performance_CM[['Full Name','CM Rating',\"Passing Total\", \"Dribbling Total\", \"Short Passing\",'BallControl', \"Vision\", \"Interceptions\"]]\n",
"\n",
"numeric_data_second = CM_selected_second.select_dtypes(include='number').corr()\n",
"plt.figure(figsize=(20, 5))\n",
"sns.heatmap(numeric_data_second,annot=True, cmap='viridis', fmt='.2f')\n",
"plt.title('Correlation Heatmap')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Display results by ordered price per performance ratio\n",
" \n",
"CM_selected_second['Total CM skills'] = CM_selected[\"Passing Total\"]+ CM_selected[\"Dribbling Total\"]+ CM_selected [\"Short Passing\"] + CM_selected['BallControl'] + CM_selected[\"Vision\"] + CM_selected[\"Interceptions\"]\n",
"CM_selected_second[\"Release Clause\"] = fifa_data_performance_CM[\"Release Clause\"]\n",
"CM_selected_second['Release Clause/Total CM skills'] = CM_selected_second['Release Clause']/CM_selected_second['Total CM skills']\n",
"sorted_CM = CM_selected_second.sort_values(by='Release Clause/Total CM skills')\n",
"display(sorted_CM)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Top three players\n",
"sorted_CM.head(3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Predicted Wage for our player choice\n",
"X = players_fifa[['Overall','Potential','Value','Age','Release Clause']]\n",
"scaler = StandardScaler()\n",
"X_standardized = scaler.fit_transform(X)\n",
"Sergej = X_standardized[64]\n",
"Sergej = pd.DataFrame(Sergej).transpose()\n",
"X_standardized = np.delete(X_standardized, 64, axis=0)\n",
"y = players_fifa[['Wage']]\n",
"y = y.drop(64)\n",
"model = linear_model.LinearRegression()\n",
"result = model.fit(X_standardized,y)\n",
"# display(result.intercept_)\n",
"# display(result.coef_)\n",
"print(result.score(X_standardized,y))\n",
"predicted_wage = model.predict(Sergej)\n",
"print(predicted_wage)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Checking the end of contract day\n",
"sorted_CM[\"Contract Until\"] = fifa_data_performance_CM[\"Contract Until\"]\n",
"sorted_CM"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Pick players for ST position with expected conditions\n",
"fifa_data_ST = players_fifa[(players_fifa['Age'] < 25) &\n",
" (players_fifa['Overall'] > 70) &\n",
" (players_fifa['Overall'] < 90) &\n",
" (players_fifa['Positions Played'].isin (['ST','CF,ST','ST,LW','RW,ST']))]\n",
"\n",
"\n",
"fifa_data_ST"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Filter out data with necessary columns for ST position\n",
"filter_ST = players_fifa[['Full Name', 'ST Rating', \"Passing Total\", \"Dribbling Total\", \"Shooting Total\", \"Heading Accuracy\", \"Jumping\", \"BallControl\", \"Vision\", \"Acceleration\", \"Positioning\"]]\n",
"\n",
"numeric_data = filter_ST.select_dtypes(include='number').corr()\n",
"plt.figure(figsize=(15, 5))\n",
"sns.heatmap(numeric_data,annot=True, cmap='viridis', fmt='.2f')\n",
"plt.title('Correlation Heatmap')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Sort players with Release Clause per ST point ratio\n",
"total_column = filter_ST.select_dtypes(include='number').sum(axis=1)\n",
"filter_ST[\"Total ST Point\"] = total_column\n",
"filter_ST[\"Release Clause\"] = players_fifa[\"Release Clause\"]\n",
"filter_ST['Ratio Column'] = filter_ST['Release Clause']/filter_ST['Total ST Point']\n",
"sorted_ST = filter_ST.sort_values(by='Ratio Column')\n",
"display(sorted_ST)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# check first 6 players\n",
"sorted_ST.head(6)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"fifa_data_ST['fifa_data_ST Index'] = fifa_data_ST['Potential'] / fifa_data_ST['Release Clause']\n",
"players_fifa.loc[:, 'fifa_data_23 Index'] = players_fifa['Potential'] / players_fifa['Release Clause']"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Predicted wage for ST position\n",
"X = players_fifa [['Overall','Potential','Value','Age','Release Clause']]\n",
"scaler = StandardScaler()\n",
"X_standardized = scaler.fit_transform(X)\n",
"Tammya = X_standardized[220]\n",
"Tammya = pd.DataFrame(Tammya).transpose()\n",
"X_standardized = np.delete(X_standardized, 220, axis=0)\n",
"y = players_fifa [['Wage']]\n",
"y = y.drop(220)\n",
"model = linear_model.LinearRegression()\n",
"result = model.fit(X_standardized, y)\n",
"predicted_wage = model.predict(Tammya)\n",
"print(predicted_wage)"
]
}
],
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.13"
}
},
"nbformat": 4,
"nbformat_minor": 1
}
Loading