<jupyter_start><jupyter_text>Split dataset into train and testset<jupyter_code>X_train, X_test, y_train, y_test =  train_test_split(data[["sepal-length", "sepal-width", "petal-length", "petal-width"]], target["target"], test_size=0.33, random_state=0)
# 2nd method
n_valid = 300
n_trn = len(df_trn)-n_valid
X_train, X_valid = split_vals(df_trn, n_trn)
y_train, y_valid = split_vals(y_trn, n_trn)
raw_train, raw_valid = split_vals(df_raw, n_trn)
print("X_train shape: {}, y_train shape: {}".format(X_train.shape, y_train.shape))
print("X_test  shape: {} , y_test  shape: {}".format(X_test.shape, y_test.shape))<jupyter_output><empty_output><jupyter_text>Create a model for our problem<jupyter_code>from sklearn import tree

model = tree.DecisionTreeClassifier(random_state=0)
model = tree.DecisionTreeRegressor(random_state=0)
model = model.fit(X_train, y_train)
y_pred = model.predict(X_test)<jupyter_output><empty_output><jupyter_text>Get score of the prediction<jupyter_code>print_r2_score(y_test, y_pred)
print_mean_squared_error(y_test, y_pred)
from sklearn import metrics

print(metrics.accuracy_score(y_test, y_pred))<jupyter_output><empty_output><jupyter_text>Check on feature importance<jupyter_code>from sklearn.feature_selection import SelectKBest, chi2

selector = SelectKBest(chi2, k=2).fit(X_train, y_train) 
X_train, X_test, y_train, y_test = train_test_split(data, target['target'], test_size=0.33, random_state=42)
print(selector.get_support())
X_train_new =  selector.transform(X_train)
X_test_new =  selector.transform(X_test)
model_new =  tree.DecisionTreeClassifier(random_state=0)
model_new.fit(X_train_new, y_train)
y_pred_new =  model_new.predict(X_test_new)<jupyter_output><empty_output><jupyter_text>Get score after feature importance  Pretty overfitting tho but nothing to worry about XOXO<jupyter_code>print_r2_score(y_test, y_pred_new)
print_mean_squared_error(y_test, y_pred_new)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11455108359133127, 'fraction_numerical': 0.010835913312693499, 'mean_word_length': 9.772222222222222, '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': '203669', 'license': 'MIT', 'n_tokens_mistral': 767, 'n_tokens_neox': 748, 'n_words': 122, 'path': 'PXL_DIGITAL_JAAR_2/Data Advanced/Bestanden/notebooks_data/Machine Learning Exercises/Machine Learning.ipynb', 'repo_name': 'Limoentaart/PXL_IT_JAAR_1', 'size': '1938'}