<jupyter_start><jupyter_text>wczytywanie danych<jupyter_code>df = pd.read_hdf('data/car.h5')
df.shape
df.columns.values<jupyter_output><empty_output><jupyter_text>Dummy model<jupyter_code>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)
# zworcmy uwage ze jest rozna waluta. EUR to jedynie 0.19%
df['price_currency'].value_counts(), df['price_currency'].value_counts(normalize = True)*100
# usuwamy eur z modelu
df = df[df['price_currency'] != 'EUR']
df['price_currency'].value_counts()<jupyter_output><empty_output><jupyter_text>Features<jupyter_code># Faktoryzujemy features
SUFFIX_CAT = '__cat'
for feat in df.columns:
  if isinstance(df[feat][0], list): continue #sprawdza czy w srodku jest lista i kontynuuje, inaczej sie wykrzacza

  factorized_values = df[feat].factorize()[0] #jezeli juz istnieje, nadpisz
  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] # zapisujemy wszystkie zmienne ktore sfaktoryzowalismy w 1 tablicy
cat_feats = [x for x in cat_feats if 'price' not in x] # usuwamy ceny, bo je bedziemy prognozowac
len(cat_feats)
# trening
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)
# eli oceni teraz wagi
m = DecisionTreeRegressor(max_depth=5)
m.fit(X,y)

imp = PermutationImportance(m, random_state=0).fit(X,y)
eli5.show_weights(imp, feature_names=cat_feats)
# powzyszy kod zapiszmyjako funkcje gdzie mozemy badac rozne parametry/ficzery, podawać ile wartosci ma wyswietlac model itp

def group_and_plot(feat_groupby, feat_agg='price_value', agg_funcs=[np.mean, np.median, np.size], feat_sort='mean', top=20, subplots=True):
  return (
      df
      .groupby(feat_groupby)[feat_agg]
      .agg(agg_funcs)
      .sort_values(by=feat_sort, ascending=False)
      .head(top)

  ).plot(kind='bar', figsize=(15,5), subplots=subplots)


group_and_plot(['param_napęd','param_stan' ], feat_sort='size')
df['param_napęd'].value_counts(normalize = True)*100<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12709620476610767, 'fraction_numerical': 0.010150044130626656, 'mean_word_length': 6.408496732026144, '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': '140295', 'license': 'MIT', 'n_tokens_mistral': 939, 'n_tokens_neox': 908, 'n_words': 179, 'path': 'Part2_day3-simple_model.ipynb', 'repo_name': 'KonP969/Data-Workshop-Cars', 'size': '2266'}