<jupyter_start><jupyter_text>Imports<jupyter_code>import pandas as pd
import numpy as np
from sklearn.tree import DecisionTreeRegressor
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import cross_val_score
cd "/content/drive/My Drive/Colab Notebooks/dw_matrix/matrix_one"
df = pd.read_csv('data/shoes_prices.csv', low_memory=False)
df.shape
df.columns
mean_price = np.mean(df.prices_amountmin)
mean_price
[3] *5
y_true = df.prices_amountmin
y_pred = [mean_price] * y_true.shape[0]
mean_absolute_error(y_true, y_pred)
df.prices_amountmin.hist(bins=100)
np.log1p(df.prices_amountmin).hist(bins=100)
y_true = df.prices_amountmin
y_pred = [np.median(y_true)] * y_true.shape[0]
mean_absolute_error(y_true, y_pred)
y_true = df.prices_amountmin
price_log_mean = np.expm1(np.mean(np.log1p(y_true)))
y_pred = [price_log_mean] * y_true.shape[0]
mean_absolute_error(y_true, y_pred)
df.columns
df.brand.value_counts()
df['brand_cat'] = df.brand.factorize()[0]
df['manufacturer_cat'] = df.manufacturer.factorize()[0]
features = ['brand_cat']

def run_model(features):

  X = df[features].values
  y = df.prices_amountmin.values
  model = DecisionTreeRegressor(max_depth=5)
  scores = cross_val_score(model, X,y,scoring='neg_mean_absolute_error')
  return np.mean(scores), np.std(scores)

run_model(['brand_cat'])
run_model(['manufacturer_cat'])
run_model(['brand_cat', 'manufacturer_cat'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12952646239554316, 'fraction_numerical': 0.011838440111420613, 'mean_word_length': 7.98125, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '609684', 'license': 'MIT', 'n_tokens_mistral': 575, 'n_tokens_neox': 554, 'n_words': 85, 'path': 'matrix_one/matrix_day_4.ipynb', 'repo_name': 'maciej-zieniewicz/dw_matrix', 'size': '1436'}