Skip to content

Instantly share code, notes, and snippets.

View michelkana's full-sized avatar

Michel Kana michelkana

View GitHub Profile
best_model = KNNModels[3]
x_new = np.arange(start=1, stop=3*365*24*60, step=1)
x_new = x_new.reshape(-1, 1)
y_new_predicted = best_model.predict(x_new)
indices_min_score = np.argwhere(y_new_predicted == 0)
index_min_score = indices_min_score[-1][0]
index_max_score = np.argmax(y_new_predicted)
r2df = pd.DataFrame(r2_scores, columns=["k", "train_data_score", "test_data_score"])
f, ax = plt.subplots(1, 1, figsize=(30,5))
ax.scatter(r2df.k, r2df.train_data_score, label='Train data score')
ax.scatter(r2df.k, r2df.test_data_score, color='r', label='Test data score')
plt.xticks(r2df.k)
plt.legend()
plt.xlabel('k values')
plt.ylabel(r'$R^2$')
plt.grid(False)
from sklearn.model_selection import train_test_split
import numpy as np
from sklearn.neighbors import KNeighborsRegressor
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score
KNNModels = {}
k_list = [1,3,5,10,12,15,20,75,250]
for k in k_list:
knr = KNeighborsRegressor(n_neighbors=k)
plt.figure(figsize=(20, 5))
plt.scatter(df['Minutes Played'] / (24*60), df['Score'])
plt.xlabel('Days Played')
plt.ylabel('Score')
plt.title('Matches Played vs. Score');
import plotly.express as px
minute_top10 = df[['Player','Minutes Played']].sort_values('Minutes Played',
ascending=False).head(10)
fig = px.bar(minute_top10, x='Minutes Played',y='Player', orientation='h', height=500,
title='Top 10 Players by minutes played')
fig.show()
import pandas as pd
df = pd.read_csv('https://gist.githubusercontent.com/michelkana/99a77e7dc656406025f0c09823dfc7b6/raw/74fdea4c4dbcb51141838d9d7adcd7ed83c936bd/Fortnite_players_stats.csv', index_col=0)
df = df.reset_index()
df['Minutes Played'] = df['Solo minutesPlayed'] + df['Duos minutesPlayed'] +
df['Trios minutesPlayed'] + df['Squads minutesPlayed'] +
df['LTM minutesPlayed']
df['Score'] = df['Solo score'] + df['Duos score'] +
df['Trios score'] + df['Squads score'] +
df['LTM score']
df.head()
We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 37 columns, instead of 28. in line 3.
Player,Solo score,Solo top1,Solo kd,Solo winRatio,Solo matches,Solo kills,Solo minutesPlayed,Duos score,Duos top1,Duos kd,Duos winRatio,Duos matches,Duos kills,Duos minutesPlayed,Trios score,Trios top1,Trios kd,Trios winRatio,Trios matches,Trios kills,Trios minutesPlayed,Squads score,Squads top1,Squads kd,Squads winRatio,Squads matches,Squads kills,Squads minutesPlayed,LTM score,LTM top1,LTM top3,LTM kd,LTM winRatio,LTM matches,LTM kills,LTM minutesPlayed
Prospеring,2476763,1828,4.37,18,10150,36328,81389,4702684,5584,10.71,45.7,12229,71137,133725,299128,244,6.65,31.2,783,3584,10280,3640415,5116,6.88,31.7,16131,75787,117967,101589,170,118,5.78,26.8,634,2682,2865
BH nixxxay,439562,1694,8.71,29.1,5817,35895,12732,4065613,4141,9.49,21.5,19252,143330,119678,6432,4,8.06,19,21,137,207,5275367,4978,10.24,30.3,16433,117327,150439,151358,229,190,8.2,18.2,1259,8442,4206
Raпger,4519465,4582,9.6,34,13488,85481,122171,1137279,1390,7.78,24.6,5649,33123,31744,990451,716,4.75,26.4,2711,9477,36634,2745537,4435,8.4,32.9,13494,7
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# convert stars' dictionary to pandas dataframe
frame = pd.DataFrame(star_table)
# format stars' dataframe
frame.credits = frame.credits.astype('int')
frame.year_born = frame.year_born.astype('int')
# find all star <div> elements
stars = star_soup.find_all(class_="lister-item mode-detail")
star_table = []
rank = 1
# loop through each star
for star in stars:
# find the star name
name_soup = star.find(class_='lister-item-header').find('a')
import requests
from bs4 import BeautifulSoup
# read the content of the web page
PAGE_URL = "https://www.imdb.com/list/ls082599715/"
my_page = requests.get(PAGE_URL)
# parse the content as html
star_soup = BeautifulSoup(my_page.content, 'html.parser')