<jupyter_start><jupyter_text>Wczytywanie danych<jupyter_code>df = pd.read_hdf('data/car.h5');
df.shape
df.columns<jupyter_output><empty_output><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(normalize=True)
df = df[ df['price_currency'] != 'EUR']
df.shape<jupyter_output><empty_output><jupyter_text>Features<jupyter_code>df['param_color'].factorize()[0].min()
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
np.mean(scores)
def group_and_barplot(feat_groupby, feat_agg='price_value', agg_funcs = [np.mean, np.median, np.size], feat_sort='mean', top=50, subplots=True):
  return (
  df
    .groupby(feat_groupby )[feat_agg]
    .agg(agg_funcs) # np.mean
    .sort_values(by=feat_sort, ascending=False)
    .head(top)
  ).plot(kind='bar', figsize=(15,5), subplots=subplots)
cat_feats = [x for x in df.columns if SUFFIX_CAT in x and 'price' not in x]
len(cat_feats) 
X = df[cat_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')

np.mean(scores)
model2 = DecisionTreeRegressor(max_depth=5)
model2.fit(X,y)

imp = PermutationImportance(model2, random_state=0).fit(X, y)
eli5.show_weights(model2, feature_names=cat_feats)
group_and_barplot('param_napęd');
group_and_barplot('param_rok-produkcji');
group_and_barplot('param_moc');<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14934354485776805, 'fraction_numerical': 0.009846827133479213, 'mean_word_length': 6.952173913043478, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '106677', 'license': 'MIT', 'n_tokens_mistral': 757, 'n_tokens_neox': 737, 'n_words': 121, 'path': 'matrix_two/matrix2_day3_simple_model.ipynb', 'repo_name': 'marqsmax/dw_matrix', 'size': '1828'}