<jupyter_start><jupyter_text>**E-Sport Team Analisis**---<jupyter_code>import pandas as pd
import seaborn as sns
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA, KernelPCA
from sklearn.cluster import MeanShift, KMeans
df = pd.read_csv("/content/sample_data/highest_earning_teams.csv")<jupyter_output><empty_output><jupyter_text>**Entendiendo el dataframe**Vamos a analizar, graficar y limpiar el dataframe para posteriormente responder preguntas e intentar llegar a conclusiones que ayuden para la creacion del modelo.<jupyter_code>df
df.dtypes
df.describe()
df.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
RangeIndex: 928 entries, 0 to 927
Data columns (total 6 columns):
 #   Column            Non-Null Count  Dtype  
---  ------            --------------  -----  
 0   TeamId            928 non-null    int64  
 1   TeamName          928 non-null    object 
 2   TotalUSDPrize     928 non-null    float64
 3   TotalTournaments  928 non-null    int64  
 4   Game              928 non-null    object 
 5   Genre             928 non-null    object 
dtypes: float64(1), int64(2), object(3)
memory usage: 43.6+ KB<jupyter_text>***Pregunta 1: ¿Cuales son los equipos mejores pagados?***<jupyter_code>df_t = df.sort_values(by="TotalUSDPrize", ascending=False)
sns.set(rc={"figure.figsize": (15,9)})
sns.barplot(data=df_t.head(10), x="TeamName", y="TotalUSDPrize")<jupyter_output><empty_output><jupyter_text>***Respuesta: OG es el equipo mejor pagado***---  ***Pregunta 2: ¿Que juego genera mas ganancia?***<jupyter_code>def game_code(x):
  if x == "Counter-Strike: Global Offensive":
    return "CSGO" 
  if x == "League of Legends":
    return "LOL"
  if x == "Heroes of the Storm":
    return "HOS"
  return x
df["Game"] = df["Game"].apply(lambda x: game_code(x))
df_g = pd.pivot_table(data=df, index=["Game"]).reset_index()
sns.boxplot(data=df_t, x="Game", y="TotalUSDPrize")
sns.barplot(data=df_g.sort_values(by="TotalUSDPrize", ascending=False), x="Game", y="TotalUSDPrize")
df_g<jupyter_output><empty_output><jupyter_text>***Respuesta: El juego mejor pagado es el Dota2 no solo contando la naturaleza de sus datos sino tambien sus outliers***---  ***Pregunta 3: ¿El numero de torneos afecta al precio ganado por equipo? ¿Cuanto gana cada equipo por torneo?***<jupyter_code>sns.scatterplot(data=df_t, x="TotalTournaments", y="TotalUSDPrize")
sns.heatmap(df_t.corr(), annot=True)
df_t["PricePerTournaments"] = df_t["TotalUSDPrize"]
df_t["PricePerTournaments"] = df_t["PricePerTournaments"].apply(lambda x: round(x / df["TotalTournaments"], 2))
df_t = df_t.sort_values(by="PricePerTournaments", ascending=False)
sns.pairplot(df_t)
df_t<jupyter_output><empty_output><jupyter_text>***Respuesta 3: El numero de torneos no parece afectar de manera significativa la lista de los equipos mejores pagados***---  **Clustering**Para encontrar patrones dentro de los datos.<jupyter_code>df
X = df.drop(columns=["TeamName", "TeamId"])
X = pd.get_dummies(X)
X
X = StandardScaler().fit_transform(X)<jupyter_output><empty_output><jupyter_text>***MeanShift***  ***Con PCA***<jupyter_code>pca = PCA(n_components=2)
pca = pca.fit(X)

X_p = pca.transform(X)
X_p
meanshift = MeanShift(max_iter=1000)
meanshift = meanshift.fit(X_p)
X_p = pd.DataFrame(X_p)
X_p
sns.scatterplot(x=X_p[0], y=X_p[1], hue=meanshift.predict(X_p))
df["group"] = meanshift.predict(X_p)
sns.scatterplot(x=df["TotalTournaments"], y=df["TotalUSDPrize"], hue=df["group"])
df
max(meanshift.predict(X_p))<jupyter_output><empty_output><jupyter_text>***Con KPCA***<jupyter_code>kpca = KernelPCA(n_components = 2, kernel="poly")
kpca = kpca.fit(X)
X_kp = kpca.transform(X)
meanshift = MeanShift(max_iter=1000)
meanshift = meanshift.fit(X_kp)
max(meanshift.predict(X_kp))
X_kp = pd.DataFrame(X_kp)
sns.scatterplot(x=X_kp[0], y=X_kp[1], hue=meanshift.predict(X_kp))
sns.scatterplot(x=df["TotalTournaments"], y=df["TotalUSDPrize"], hue=meanshift.predict(X_kp))
df["group"] = meanshift.predict(X_kp)
df
max(meanshift.predict(X_kp))<jupyter_output><empty_output><jupyter_text>***Sin PCA***<jupyter_code>X
meanshift = MeanShift(max_iter=1000)
meanshift = meanshift.fit(X)
X_w = meanshift.predict(X)
sns.scatterplot(x=df["TotalTournaments"], y=df["TotalUSDPrize"], hue=meanshift.predict(X))
max(meanshift.predict(X))<jupyter_output><empty_output><jupyter_text>***KMeans*** Usamos el metodo del codo para encontrar el mejor numero de clusters<jupyter_code>wcss = []
for i in range(1, 11):
  kmeans = KMeans(n_clusters=i, max_iter=1000)
  kmeans = kmeans.fit(X)
  wcss.append(kmeans.inertia_)

sns.lineplot(x=range(1, 11), y=wcss)
wcss<jupyter_output><empty_output><jupyter_text>***Con PCA***<jupyter_code>pca = PCA(n_components=2)
pca = pca.fit(X)
sns.lineplot(x = range(pca.n_components_), y = pca.explained_variance_ratio_)
X_p = pca.transform(X)
X_p
kmeans = KMeans(n_clusters=5)
kmeans = kmeans.fit(X_p)
df["group"] = kmeans.predict(X_p)
sns.scatterplot(x=df_t["TotalTournaments"], y=df_t["TotalUSDPrize"], hue=kmeans.predict(X_p))
X_p = pd.DataFrame(X_p)
sns.scatterplot(x = X_p[0], y = X_p[1], hue=kmeans.predict(X_p))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15276967930029153, 'fraction_numerical': 0.017687074829931974, 'mean_word_length': 6.197202797202797, 'pattern_counts': {'":': 4, '<': 45, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '11', 'dir': 'jupyter-structured-clean-dedup', 'id': '480129', 'license': 'MIT', 'n_tokens_mistral': 2196, 'n_tokens_neox': 2041, 'n_words': 377, 'path': 'g-E_Sports_Team.ipynb', 'repo_name': 'zedeme/e-sports-teams', 'size': '5145'}