<jupyter_start><jupyter_text>Feature Engineering<jupyter_code>SUFFIX_CAT = '__cat'
for feat in df.columns:
  if isinstance(df[feat][0], list): continue
  factorized_values = df[feat].factorize()[0]
  if SUFFIX_CAT in feat:
    df[feat] = factorized_values
  else:
    df[feat + SUFFIX_CAT] = df[feat].factorize()[0]
cat_feats = [ x for x in df.columns if SUFFIX_CAT in x]
cat_feats = [ x for x in cat_feats if 'price' not in x]
len(cat_feats)
def run_model(model, feats):
  X = df[feats].values
  y = df['price_value'].values
  model = model
  scores = cross_val_score(model, X, y, scoring='neg_mean_absolute_error')
  return np.mean(scores), np.std(scores)<jupyter_output><empty_output><jupyter_text>Decision Tree<jupyter_code>run_model(DecisionTreeRegressor(max_depth=5, random_state=2020), cat_feats)<jupyter_output><empty_output><jupyter_text>Random Forest<jupyter_code>run_model(RandomForestRegressor(n_estimators=100, max_depth=5, min_samples_split=25, random_state=2020), cat_feats)<jupyter_output><empty_output><jupyter_text>XGBoost<jupyter_code>xgbparams = {
    'n_estimators': 50, 
    'max_depth': 5,
    'learning_rate': 0.3,
    'seed': 0,
    'random_state': 2020
}

model = xgb.XGBRegressor(**xgbparams)
run_model(model, cat_feats)
m = xgb.XGBRegressor(**xgbparams)
m.fit(X,  y)

importances = PermutationImportance(m, random_state=2020).fit(X, y)
eli5.show_weights(importances, feature_names=cat_feats)
feats = ['param_rok-produkcji__cat','param_stan__cat','param_napęd__cat','param_marka-pojazdu__cat','param_skrzynia-biegów__cat','param_moc__cat','param_faktura-vat__cat','param_typ__cat','param_wersja__cat','seller_name__cat','param_pojemność-skokowa__cat','param_model-pojazdu__cat','param_kod-silnika__cat','feature_kamera-cofania__cat','feature_wspomaganie-kierownicy__cat','param_uszkodzony__cat','feature_światła-led__cat','param_liczba-miejsc__cat','feature_łopatki-zmiany-biegów__cat','feature_regulowane-zawieszenie__cat']
len(feats)
model = xgb.XGBRegressor(**xgbparams)
run_model(model, feats)
n = 'NOn'
str(n).lower()
df['param_rok-produkcji'] = df['param_rok-produkcji'].map(lambda x: -1 if str(x).lower()=='none' else int(x))
feats = ['param_rok-produkcji','param_stan__cat','param_napęd__cat','param_marka-pojazdu__cat','param_skrzynia-biegów__cat','param_moc__cat','param_faktura-vat__cat','param_typ__cat','param_wersja__cat','seller_name__cat','param_pojemność-skokowa__cat','param_model-pojazdu__cat','param_kod-silnika__cat','feature_kamera-cofania__cat','feature_wspomaganie-kierownicy__cat','param_uszkodzony__cat','feature_światła-led__cat','param_liczba-miejsc__cat','feature_łopatki-zmiany-biegów__cat','feature_regulowane-zawieszenie__cat']
model = xgb.XGBRegressor(**xgbparams)
run_model(model, feats)
df['param_moc'] = df['param_moc'].map(lambda x: -1 if str(x).lower()=='none' else int(x.split(' ')[0]))
df['param_moc'].unique()
feats = ['param_rok-produkcji','param_stan__cat','param_napęd__cat','param_marka-pojazdu__cat','param_skrzynia-biegów__cat','param_moc','param_faktura-vat__cat','param_typ__cat','param_wersja__cat','seller_name__cat','param_pojemność-skokowa__cat','param_model-pojazdu__cat','param_kod-silnika__cat','feature_kamera-cofania__cat','feature_wspomaganie-kierownicy__cat','param_uszkodzony__cat','feature_światła-led__cat','param_liczba-miejsc__cat','feature_łopatki-zmiany-biegów__cat','feature_regulowane-zawieszenie__cat']
model = xgb.XGBRegressor(**xgbparams)
run_model(model, feats)
df['param_pojemność-skokowa'] = df['param_pojemność-skokowa'].map(lambda x: -1 if str(x).lower()=='none' else int(x.split('cm')[0].replace(' ', '')))
feats = ['param_rok-produkcji','param_stan__cat','param_napęd__cat','param_marka-pojazdu__cat','param_skrzynia-biegów__cat','param_moc','param_faktura-vat__cat','param_typ__cat','param_wersja__cat','seller_name__cat','param_pojemność-skokowa','param_model-pojazdu__cat','param_kod-silnika__cat','feature_kamera-cofania__cat','feature_wspomaganie-kierownicy__cat','param_uszkodzony__cat','feature_światła-led__cat','param_liczba-miejsc__cat','feature_łopatki-zmiany-biegów__cat','feature_regulowane-zawieszenie__cat']
model = xgb.XGBRegressor(**xgbparams)
run_model(model, feats)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1533175355450237, 'fraction_numerical': 0.00900473933649289, 'mean_word_length': 12.06811145510836, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '621371', 'license': 'MIT', 'n_tokens_mistral': 1758, 'n_tokens_neox': 1717, 'n_words': 148, 'path': 'day_4_moremodels.ipynb', 'repo_name': 'bohdankoretski/dw_matrix_carprice', 'size': '4220'}