<jupyter_start><jupyter_text>Cross validation<jupyter_code># Import libraries
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn.linear_model import Lasso
x = pd.read_csv(filepath_or_buffer="datasets/x_opening.csv")

y = x["worldwide_gross"]
x = x.drop(labels=["worldwide_gross"], axis=1)

x_train, x_test, y_train, y_test = train_test_split(x, y)

scores = cross_val_score(estimator=Lasso(), X=x, y=y, scoring='r2')
scores
scores.mean()
Lasso().fit(X=x_train, y=y_train).score(X=x_test, y=y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12876254180602006, 'fraction_numerical': 0.0033444816053511705, 'mean_word_length': 8.819672131147541, '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': '219265', 'license': 'MIT', 'n_tokens_mistral': 241, 'n_tokens_neox': 234, 'n_words': 44, 'path': 'cross_validation.ipynb', 'repo_name': 'ivanmtoroc/scipy-intro', 'size': '598'}