<jupyter_start><jupyter_text>Dummy Model<jupyter_code>df.select_dtypes(np.number).columns
feats = ['car_id']
X = df[ feats ].values
y = df['price_value'].values

model = DummyRegressor()
model.fit(X,y)
y_pred = model.predict(X)

mae(y, y_pred)
[x for x in df.columns if 'price' in x]
df['price_currency'].value_counts()
df = df[df['price_currency'] != 'EUR']
df.shape<jupyter_output><empty_output><jupyter_text>Features factorization<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] = factorized_values
            
cat_feats = [ x for x in df.columns if SUFFIX_CAT in x]
len(cat_feats)
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 = DecisionTreeRegressor(max_depth=5)
    scores = cross_val_score(model, X, y, cv=3, scoring='neg_mean_absolute_error')
    return np.mean(scores), np.std(scores)
run_model(DecisionTreeRegressor(max_depth=5), cat_feats)<jupyter_output><empty_output><jupyter_text>Random Forest<jupyter_code>model = RandomForestRegressor(max_depth=5, n_estimators=50, random_state=0)
run_model(model, cat_feats)<jupyter_output><empty_output><jupyter_text>XGBoost<jupyter_code>xgb_params = {
    'max_depth': 5,
    'n_estimators': 50,
    'learning_rate': 0.1,
    'seed': 0,
}

model = xgb.XGXGBoostXGBoostXGBoostXGBoostBRegressor(**xgb_params)
run_model(model, cat_feats)<jupyter_output><empty_output><jupyter_text>PermutationImportance by XGBoost<jupyter_code>m = xgb.XGBRegressor(**xgb_params)
m.fit(X, y)

imp = PermutationImportance(m, random_state=0).fit(X,y)
eli5.show_weights(imp, feature_names=cat_feats)
s = """
0.1209 ± 0.0019 	param_napęd__cat
0.1175 ± 0.0030 	param_rok-produkcji__cat
0.1113 ± 0.0013 	param_stan__cat
0.0625 ± 0.0019 	param_skrzynia-biegów__cat
0.0527 ± 0.0016 	param_faktura-vat__cat
0.0461 ± 0.0015 	param_moc__cat
0.0275 ± 0.0008 	param_marka-pojazdu__cat
0.0230 ± 0.0004 	param_typ__cat
0.0227 ± 0.0007 	feature_kamera-cofania__cat
0.0191 ± 0.0007 	param_pojemność-skokowa__cat
0.0150 ± 0.0009 	seller_name__cat
0.0141 ± 0.0008 	param_kod-silnika__cat
0.0130 ± 0.0002 	param_model-pojazdu__cat
0.0119 ± 0.0004 	feature_wspomaganie-kierownicy__cat
0.0109 ± 0.0003 	param_wersja__cat
0.0095 ± 0.0007 	feature_czujniki-parkowania-przednie__cat
0.0089 ± 0.0003 	feature_asystent-pasa-ruchu__cat
0.0082 ± 0.0002 	feature_regulowane-zawieszenie__cat
0.0081 ± 0.0004 	feature_system-start-stop__cat
0.0072 ± 0.0004 	feature_światła-led__cat 
"""

s = s.replace('\n',' ')
s = s.replace('\t',' ')
dirty_feats = s.split(" ")
feats = dirty_feats[5::5]
feats


len(feats)
run_model(xgb.XGBRegressor(**xgb_params),feats)
# wynik pogorszyl sie nieznacznie
df['param_napęd'].unique()
df['param_rok-produkcji'].unique()
df['param_rok-produkcji__cat'].unique()
# rok tracony w wyniku faktoryzacji
df['param_rok-produkcji'] = df['param_rok-produkcji'].map(lambda x: -1 if str(x) == 'None' else int(x))
df['param_rok-produkcji'].unique()
feats
index=feats.index('param_rok-produkcji__cat')
feats[index]='param_rok-produkcji'
feats
run_model(xgb.XGBRegressor(**xgb_params),feats)
df['param_moc'].unique()

df['param_moc']= df['param_moc'].map(lambda x: -1 if str(x) == 'None' else int(x.split(' ')[0])  )

index = feats.index('param_moc__cat')
index
feats[5] = 'param_moc'
df['param_moc'].unique()
feats
run_model(xgb.XGBRegressor(**xgb_params),feats)
df['param_pojemność-skokowa'] = df['param_pojemność-skokowa'].map(lambda x: -1 if str(x) == 'None' else x.split('cm')[0].replace(' ',''))
index = feats.index('param_pojemność-skokowa__cat')
feats[index] = 'param_pojemność-skokowa'
run_model(xgb.XGBRegressor(**xgb_params),feats)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14583863578518708, 'fraction_numerical': 0.057266480020361415, 'mean_word_length': 5.968085106382978, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '131662', 'license': 'MIT', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1694, 'n_words': 274, 'path': 'day4.ipynb', 'repo_name': 'fu1ryn4/dw_matrix_car', 'size': '3929'}