Skip to content

Instantly share code, notes, and snippets.

View MemphisMeng's full-sized avatar
💯

Anzhe Meng MemphisMeng

💯
  • Pittsburgh, PA
  • 21:18 (UTC -04:00)
View GitHub Profile
# movie profile
movie_profile = movies[['id', 'title', 'genres']]
movie_profile.rename(columns={'id': 'movieId'}, inplace=True)
genres = [item.strip() for l in all_genres for item in l ]
unique_genres = set(genres)
for genre in unique_genres:
movie_profile[genre] = 0
for i in range(len(movie_profile)):
if type(movie_profile['genres'].iloc[i]) != None.__class__:
algo = SVD()
trainset = data.build_full_trainset()
algo.fit(trainset)
# Than predict ratings for all pairs (u, i) that are NOT in the training set.
testset = trainset.build_anti_testset()
predictions = algo.test(testset)
proba = {'Manchester City': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Bayern Munich': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Paris Saint-Germain': {'qtr': 300, 'semi': 0, 'final': 0, 'champion': 0},
'Real Madrid': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Juventus': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Lyon': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Barcelona': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Napoli': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Chelsea': {'qtr': 0, 'semi': 0, 'final': 0, 'champion': 0},
'Atalanta': {'qtr': 300, 'semi': 0, 'final': 0, 'champion': 0},
from sklearn import preprocessing
from imblearn.over_sampling import RandomOverSampler
le = preprocessing.LabelEncoder()
fixtures['Score'] = le.fit_transform(fixtures['Score'].astype(str))
ros = RandomOverSampler(random_state=42)
fixtures, Score_ = ros.fit_resample(fixtures.drop(columns=['Score']), fixtures['Score'])
fixtures['Score'] = le.inverse_transform(Score_)
@MemphisMeng
MemphisMeng / merge.py
Last active August 3, 2020 19:27
medium descrption
# "fixtures" is the fixture table containing all the matches that have taken place
# "aggregate" is the set of selected features
fixtures = fixtures.merge(aggregate, left_on='Home', right_on='Squad')
fixtures = fixtures.merge(aggregate, left_on='Away', right_on='Squad', suffixes=('_Home', '_Away'))