<jupyter_start><jupyter_text>Logistic Regressor Model<jupyter_code># Run Logistic Regression and select best mean_absolute_error 

LR_model = LogisticRegression(C=0.01, solver='liblinear')

LR_model.fit(X_train, y_train)

y_pred = LR_model.predict(X_test)

print(mean_absolute_error(y_test, y_pred))

best_score = mean_absolute_error(y_test, y_pred)

super_model = LR_model

super_model<jupyter_output>7.956521739130435<jupyter_text>MLP Regressor Model<jupyter_code># Run MLP Regression and select best mean_absolute_error 


MLP_model = MLPRegressor(hidden_layer_sizes=100, max_iter= 5000, random_state= 40, batch_size= 30, solver= 'lbfgs', 
                        activation= 'identity')

MLP_model.fit(X_train, y_train)

y_pred = MLP_model.predict(X_test)

print(mean_absolute_error(y_test, y_pred))

best_score = mean_absolute_error(y_test, y_pred)
super_model = MLP_model

super_model<jupyter_output>/opt/anaconda3/envs/dev/lib/python3.7/site-packages/sklearn/utils/validation.py:73: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  return f(**kwargs)<jupyter_text>Gradient Boosting Regressor Model<jupyter_code># Run Gradient Boosting Regression and select best mean_absolute_error 

GB_model = GradientBoostingRegressor(n_estimators= 2000, random_state= 20)

GB_model.fit(X_train, y_train)

y_pred = GB_model.predict(X_test)

print(mean_absolute_error(y_test, y_pred))
 
if (mean_absolute_error(y_test, y_pred) < best_score):
  best_score = mean_absolute_error(y_test, y_pred)
  super_model = GB_model

super_model<jupyter_output>/opt/anaconda3/envs/dev/lib/python3.7/site-packages/sklearn/utils/validation.py:73: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().
  return f(**kwargs)<jupyter_text>Random Forest Regressor Model<jupyter_code># Run Random Forest Regression and select best mean_absolute_error 

RF_model = RandomForestRegressor(n_estimators= 2000, random_state= 20)

RF_model.fit(X_train, y_train)

y_pred = RF_model.predict(X_test)

print(mean_absolute_error(y_test, y_pred))

if (mean_absolute_error(y_test, y_pred) < best_score):
  best_score = mean_absolute_error(y_test, y_pred)
  super_model = RF_model

super_model
pd.options.display.max_rows = None
"""
importance = MLP_model.feature_importances_

feature_names = super_model_data.drop('TmScore', axis=1).columns

d = {'Var_Name': feature_names, 'Imp': importance}
df = pd.DataFrame(data=d)
df = df.sort_values(by= ['Imp'], ascending = False).reset_index(drop=True)
df.head(15)
"""
# function that return the score of two teams playing

pd.options.display.max_columns = None

# Create playoff test dataset from season averages

def Praedico(home_team, away_team, super_model):
    team1 = home_team
    team2 = away_team
    
    team1_data = super_model_data[com_data['Team'] == team1].drop('TmScore', axis=1).reset_index(drop=True)
    team2_data = super_model_data[com_data['Team'] == team2].drop('TmScore', axis=1).reset_index(drop=True)
    
    week_slice = slice(9,16)
    
    #1 Remove if no team names
    team1_test = pd.DataFrame(team1_data[week_slice].mean(axis=0)).T #select week to use as average
    team1_test
    opp_columns = team1_test.filter(like='Opp').columns
    
    team1_test[opp_columns] = 0
    team1_test['Opp_' + team2] = 1
    team1_test['Home'] = 1
    
    #2
    team2_test = pd.DataFrame(team2_data[week_slice].mean(axis=0)).T #select week to use as average
    opp_columns = team2_test.filter(like='Opp').columns
    
    team2_test[opp_columns] = 0
    team2_test['Opp_' + team1] = 1
    team2_test['Home'] = 0 #remove home field advantage
    
    # head to head matchup
    team1_test[['D_1stD','D_Tot_Yd','D_P_Yd','D_R_Yd','D_TO']] = team2_test[['O_1stD','O_Tot_yd','O_P_Yd','O_R_Yd','O_TO']]
    team2_test[['D_1stD','D_Tot_Yd','D_P_Yd','D_R_Yd','D_TO']] = team1_test[['O_1stD','O_Tot_yd','O_P_Yd','O_R_Yd','O_TO']]
    
    X_Playoff_test = pd.concat([team1_test, team2_test])
    X_Playoff_test.fillna(0, inplace = True) 
    
    scores = super_model.predict(X_Playoff_test)
    print(team1, "will score", round(scores[0], 1))
    print(team2, "will score", round(scores[1], 1))
    
    if scores[0] > scores[1]:
        winner = team1
    else:
        winner = team2
        
    print(winner, "are the WINNERS!!!")
    
    return scores, winner
print(X_train.shape)<jupyter_output>(201, 57)<jupyter_text>AFC Playoff Picture1. Tennessee Titans (12-5), champions, AFC South. The Titans held on against the Texans in Week 18 to stay ahead of the Chiefs and clinch the No. 1 seed. They have home-field advantage in the AFC playoffs and the lone bye. The conference road to Super Bowl 56 will go through Nashviille.2. Kansas City Chiefs (12-5), champions, AFC West. The Chiefs will settle for the No. 2 seed after beating the Broncos in Week 18 because they lost head-to-head to the Titans in Week 7. They did win Super Bowl 54 coming from this position behind the Ravens.3. Buffalo Bills (11-6), champions, AFC East. The Bills won the division and kept this seed with a home win over the Jets. They finish a game behind the co-AFC leaders and a game ahead of the Bengals after being the AFC's No. 2 in last year's playoffs.4. Cincinnati Bengals (10-7), champions, AFC North. The Bengals rested key players because of injuries and other reasons and lost without Jo<NAME> and Jo<NAME> at the Browns in Week 18. They were set to stay here behind the East champions.5. Las Vegas Raiders (10-7), second place, AFC West. The Raiders moved into playoff position with the Colts, whom they beat in Week 17, being upset by the Jaguars in Week 18. They earned a playoff berth with the wild overtime win over the Chargers on Sunday night.6. New England Patriots (10-7), second place, AFC East. The Patriots lost to the Dolphins in Week 18, but they had already lost the East title when the Bills beat the Jets. They dropped to No. 6 with the Raiders beating the Chargers on Sunday night because of losing the tiebreaker.7. Pittsburgh Steelers (9-7-1), second place, AFC North. The Steelers got into the playoffs to extend the career of <NAME> by beating the Ravens in Week 18 while the Jaguars beat the Colts and the Raiders beat the Chargers.<jupyter_code># Creat a list of AFC teams

afc_playoff_picture = ['Tennessee Titans', 'Kansas City Chiefs', 'Buffalo Bills', 'Cincinnati Bengals', 'Las Vegas Raiders', 'New England Patriots', 'Pittsburgh Steelers']<jupyter_output><empty_output><jupyter_text>NFC Playoff Picture1. Green Bay Packers (13-4), champions, NFC North. The Packers clinched the No. 1 seed, the lone bye and the Lambeau home-field advantage in the NFC playoffs with their win over the Vikings in Week 17, matching their win total of the previous two seasons with <NAME> under Matt LaFleur with one more game left in the new schedule. They lost in Week 18 while resting Rodgers and other regulars in the second half against the Lions.2. Tampa Bay Buccaneers (13-4), champions, NFC South. The Buccaneers beat the Panthers and moved up to No. 2 because the Rams, to whom they lost in Week 3, lost to the 49ers. They finished behind the Packers because of a lesser confference record and ahead of the Cowboys, up a full game and a head-to-head tiebreaker from Week 1.3. Dallas Cowboys (12-5), champions, NFC East. The Cowboys rebounded to rout the resting Eagles in Week 18 after they lost to the Cardinals in a failed comeback in Week 17. They were able to jump the losing Rams because of winning the conference-record tiebreaker over them.4. Los Angeles Rams (12-5), champions, NFC West. The Rams failed to beat the 49ers in Week 18 but still took back the division crown with the Cardinals losing another West matchup to the Seahawks at home. They cost themselves a No. 2 seed and now need to play a third game against the Cardinals.5. Arizona Cardinals (11-6), second place, NFC West. The Cardinals could have won the division with the Rams losing but they also lost to the Seahawks. They will settle for the top wild-card spot and a rematch with the Rams in the wild-card playoffs.6. San Francisco 49ers (10-7), third place, NFC West. The 49ers locked down the second wild card by beating the Rams in overtime in Week 18. They held off the winning Saints and got up a full game on the losing Eagles, whom they also beat in Week 2.7. Philadelphia Eagles (9-8), second place, NFC East. The Eagles rested players against the Cowboys in Week 18 after they had already clinched a wild-card spot in Week 17. They stayed ahead of the winning Saints because of beating that team in Week 11.<jupyter_code># Create a list of NFC teams
nfc_playoff_picture = ['Green Bay Packers', 'Tampa Bay Buccaneers', 'Dallas Cowboys', 'Los Angeles Rams', 'Arizona Cardinals', 'San Francisco 49ers', 'Philadelphia Eagles'] 
# Remove top seed from list
afc_divisional = []
afc_divisional.append(afc_playoff_picture.pop(0))
# Remove top seet from list

nfc_divisional = []
nfc_divisional.append(nfc_playoff_picture.pop(0))<jupyter_output><empty_output><jupyter_text>AFC Playoff Wildcard Round<jupyter_code># Create a loop

while len(afc_playoff_picture) > 0:
    first_element = afc_playoff_picture.pop(0)
    last_element = afc_playoff_picture.pop(-1)
    score, team = Praedico(first_element, last_element, super_model)
    afc_divisional.append(team)<jupyter_output>Kansas City Chiefs will score 26.5
Pittsburgh Steelers will score 16.6
Kansas City Chiefs are the WINNERS!!!
Buffalo Bills will score 20.1
New England Patriots will score 30.9
New England Patriots are the WINNERS!!!
Cincinnati Bengals will score 24.6
Las Vegas Raiders will score 26.4
Las Vegas Raiders are the WINNERS!!!<jupyter_text>NFC Playoff Wildcard Round<jupyter_code># Create a loop

while len(nfc_playoff_picture) > 0:
    first_element = nfc_playoff_picture.pop(0)
    last_element = nfc_playoff_picture.pop(-1)
    score, team = Praedico(first_element, last_element, super_model)
    nfc_divisional.append(team)
# Print the AFC Divisional list created 
afc_divisional
# Print the NFC Divisional list created 
nfc_divisional
# Set AFC Champion to a empty list
afc_championship = []
# Set NFC Champion to a empty list
nfc_championship = []<jupyter_output><empty_output><jupyter_text>AFC Divisional Round<jupyter_code>while len(afc_divisional) > 0:
    first_element = afc_divisional.pop(0)
    last_element = afc_divisional.pop(-1)
    score, team = Praedico(first_element, last_element, super_model)
    afc_championship.append(team)<jupyter_output>Tennessee Titans will score 25.4
Las Vegas Raiders will score 25.0
Tennessee Titans are the WINNERS!!!
Kansas City Chiefs will score 23.0
New England Patriots will score 28.1
New England Patriots are the WINNERS!!!<jupyter_text>NFC Divisional Round<jupyter_code>while len(nfc_divisional) > 0:
    first_element = nfc_divisional.pop(0)
    last_element = nfc_divisional.pop(-1)
    score, team = Praedico(first_element, last_element, super_model)
    nfc_championship.append(team)<jupyter_output>Green Bay Packers will score 24.5
Arizona Cardinals will score 22.9
Green Bay Packers are the WINNERS!!!
Tampa Bay Buccaneers will score 28.5
San Francisco 49ers will score 26.7
Tampa Bay Buccaneers are the WINNERS!!!<jupyter_text>AFC Championship<jupyter_code>score, afc_team = Praedico(afc_championship.pop(0), afc_championship.pop(-1), super_model)<jupyter_output>Tennessee Titans will score 15.8
New England Patriots will score 35.2
New England Patriots are the WINNERS!!!<jupyter_text>NFC Championship<jupyter_code>score, nfc_team = Praedico(nfc_championship.pop(0), nfc_championship.pop(-1), super_model)<jupyter_output>Green Bay Packers will score 26.7
Tampa Bay Buccaneers will score 25.9
Green Bay Packers are the WINNERS!!!<jupyter_text>Super Bowl LVI<jupyter_code>score, super_bowl_team = Praedico(nfc_team, afc_team, super_model)
print(f'Congratulations to the {super_bowl_team} for winning Super Bowl LVI!')
print(f'The super_model with the lowest mean absolute error used was {super_model}.')<jupyter_output>The super_model with the lowest mean absolute error used was RandomForestRegressor(n_estimators=2000, random_state=20).
{'fraction_non_alphanumeric': 0.08319088319088319, 'fraction_numerical': 0.025315425315425317, 'mean_word_length': 5.100297914597816, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 52, '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': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '430185', 'license': 'MIT', 'n_tokens_mistral': 4307, 'n_tokens_neox': 3929, 'n_words': 1367, 'path': 'Super_model.ipynb', 'repo_name': 'jcsung-star/Praedico', 'size': '12307'}