<jupyter_start><jupyter_text>Load and Process Data<jupyter_code>df = pd.read_csv('data/processed/modelling_data_dropped_null_wins.csv')<jupyter_output><empty_output><jupyter_text>Fit Model<jupyter_code>df.head()
X = df.drop(columns=['Ticket_Value', 'TV_Rate'])
Y_Tickets = df['Ticket_Value']
Y_TV = df['TV_Rate']
best_params_tickets = {'subsample': 0.35000000000000003,
 'n_estimators': 5,
 'min_samples_split': 11,
 'min_samples_leaf': 5,
 'max_features': 0.9000000000000001,
 'max_depth': 10,
 'loss': 'ls',
 'learning_rate': 0.001,
 'alpha': 0.95}

best_params_TV = {'subsample': 0.8500000000000001,
 'n_estimators': 5,
 'min_samples_split': 16,
 'min_samples_leaf': 11,
 'max_features': 0.45,
 'max_depth': 6,
 'loss': 'huber',
 'learning_rate': 0.5,
 'alpha': 0.85}
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.ensemble.partial_dependence import partial_dependence
from sklearn.ensemble.partial_dependence import plot_partial_dependence
import matplotlib.pyplot as plt
%matplotlib inline
gbr_tv = GradientBoostingRegressor(**best_params_TV)
gbr_tickets = GradientBoostingRegressor(**best_params_tickets)
%%time
gbr_tv.fit(X, Y_TV)
gbr_tickets.fit(X, Y_Tickets)<jupyter_output>Wall time: 985 ms<jupyter_text>Plot Partial Dependence<jupyter_code>pdp_fig_TV, tv_axes = partial_dependence(gbr_tv, Y_TV.values, grid=X['superteam_flg'].values.reshape(1,-1), percentiles=(0,1))
pdp_fig_Tickets, tickets_axes = partial_dependence(gbr_tickets, Y_Tickets.values, grid=X['superteam_flg'].values.reshape(1,-1), percentiles=(0,1))

tickets_axes<jupyter_output><empty_output><jupyter_text>Using plot_partial_dependence function<jupyter_code>pdp_fig_TV, tv_axes = plot_partial_dependence(gbr_tv, X, features=['superteam_flg', 'Tot_WINS'], feature_names=['superteam_flg', 'Tot_WINS'],
                                              n_cols=2,
                                              percentiles=(0.0, 1.),
                                              grid_resolution=500,
                                             )
pdp_fig_TV.suptitle('Partial Dependence of Super Team on TV Ratings')
tv_axes.set_label('Super Team')
tv_axes.set_label('TV Rating Prediction')
tv_axes.ylim(0, 1)
tv_axes.xlim(-1, 2)
feat_nums = [0,1,2]
feats=['superteam_flg']
feat_names=['Super Team Y/N']
pdp_fig_TV, tv_axes = plot_partial_dependence(gbr_tv, X, feat_nums, feature_names=X.iloc[:, feat_nums].columns.values.tolist(),
                                             )
pdp_fig_TV, tv_axes = plot_partial_dependence(gbr_tv, X, features=feats, feature_names=feats
                                             )<jupyter_output>C:\Users\afurrier\AppData\Local\Continuum\miniconda3\envs\hackathon\lib\site-packages\matplotlib\axes\_base.py:3443: UserWarning: Attempting to set identical bottom==top results
in singular transformations; automatically expanding.
bottom=0.8583119524774302, top=0.8583119524774302
  'bottom=%s, top=%s') % (bottom, top))<jupyter_text>Create PDP manually Xaxis is val -- > 0 or 1Y is output prediction1) Make predictions with Avg Prediction (take mean columnwise)2) Make Prediction when Superteam ==0, and when it ==13) Plot these two rows<jupyter_code>avg_pred = pd.DataFrame(X.mean()).T
superteam_absent = avg_pred.assign(superteam_flg = 0)
superteam_present = avg_pred.assign(superteam_flg = 1)
pdp_predictions = pd.concat([superteam_absent, superteam_present])
pdp_predictions.index = ['Superteam_Absent', 'Superteam_Present']
pdp_predictions['TV_Rating_Predictions'] = gbr_tv.predict(pdp_predictions)
pdp_predictions['Ticket_Value_Predictions'] = gbr_tickets.predict(pdp_predictions.drop(columns='TV_Rating_Predictions'))
import altair as alt
plt.show(<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12102425876010782, 'fraction_numerical': 0.04097035040431267, 'mean_word_length': 5.063725490196078, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '177775', 'license': 'MIT', 'n_tokens_mistral': 1436, 'n_tokens_neox': 1300, 'n_words': 217, 'path': 'notebooks/07-PDP-Plots.ipynb', 'repo_name': 'safurrier/hackathon', 'size': '3710'}