<jupyter_start><jupyter_text>Poisson regressor<jupyter_code>import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, KBinsDiscretizer
from sklearn.pipeline import Pipeline
from sklearn.metrics import mean_squared_log_error
from sklearn.linear_model import PoissonRegressor
sample_submission = pd.read_csv('../data/sample_submission.csv')<jupyter_output><empty_output><jupyter_text>import merged dataframes (refer to notebook 2 for data wrangling steps)<jupyter_code>train_merged = pd.read_csv('../data/train/train_merged.csv')
train_merged.tail()
test_merged = pd.read_csv('../data/test_merged.csv')
test_merged.tail()
train_merged.columns<jupyter_output><empty_output><jupyter_text>train & run poisson regressor<jupyter_code>X = train_merged[['center_id', 'meal_id', 'checkout_price', 'base_price',
       'emailer_for_promotion', 'homepage_featured', 
       'center_type', 'category', 'cuisine', 'calendar_week']]
y = train_merged['num_orders']
X_train, X_test, y_train, y_test = train_test_split(X, y)
categories = ['center_id', 'meal_id','emailer_for_promotion', 'homepage_featured',
                                                  'center_type', 'category', 'cuisine', 'calendar_week']

metrics = ['base_price','checkout_price']
trans = ColumnTransformer([
    ('categories', OneHotEncoder(drop='first',sparse=False), categories), 
    ('metrics', KBinsDiscretizer(n_bins=10, encode='onehot-dense', strategy='quantile'), metrics)
     ])
model_pipe_poisson = Pipeline([
    ('feature_engineering', trans), 
    ('model', PoissonRegressor(alpha=0.1,max_iter=10000))
                                ])
model_pipe_poisson.fit(X_train, y_train)
y_train_poiss_pred = model_pipe_poisson.predict(X_train)
y_test_poiss_pred = model_pipe_poisson.predict(X_test)
print('train score:',np.sqrt(mean_squared_log_error(y_train, y_train_poiss_pred)))
print('test score:',np.sqrt(mean_squared_log_error(y_test, y_test_poiss_pred)))<jupyter_output>train score: 0.6655590337732898
test score: 0.6641152434159727<jupyter_text>Submission<jupyter_code>X_submission = test_merged[['center_id', 'meal_id', 'checkout_price', 'base_price',
                           'emailer_for_promotion', 'homepage_featured', 
                           'center_type', 'category', 'cuisine', 'calendar_week']]
y_submission_pred = model_pipe_poisson.predict(X_submission)
sub_2 = sample_submission
sub_2['num_orders'] = y_submission_pred
sub_2<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11897356143079316, 'fraction_numerical': 0.01827371695178849, 'mean_word_length': 6.030054644808743, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '540391', 'license': 'MIT', 'n_tokens_mistral': 916, 'n_tokens_neox': 855, 'n_words': 133, 'path': 'notebooks/3_poisson_regressor.ipynb', 'repo_name': 'hichemck/food_demand', 'size': '2572'}