<jupyter_start><jupyter_text><jupyter_code>import warnings
warnings.simplefilter("ignore")
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import Lasso
from sklearn.model_selection import cross_validate
from sklearn.neighbors import KNeighborsRegressor
from sklearn.model_selection import validation_curve
from sklearn.model_selection import learning_curve

%matplotlib inline
X = pd.read_csv('/content/drive/My Drive/Colab Notebooks/db/X_opening.csv')
y = X['worldwide_gross']
X = X.drop('worldwide_gross',axis=1)
X_train,X_test, y_train,y_test = train_test_split(X,y, random_state=1)
X2_train,X2_test, y2_train,y2_test = train_test_split(X,y, random_state=1)
pd.DataFrame.equals(X_train,X2_train)
scores = cross_val_score(Lasso(),X,y,cv=5,scoring='r2')
scores
scores.mean()
Lasso().fit(X_train,y_train).score(X_test,y_test)
results = cross_validate(Lasso(),X,y,return_train_score=True,cv=5)
results
test_scores = results['test_score']
train_scores = results['train_score']
print(np.mean(train_scores))
print(np.mean(test_scores))
cross_validate(KNeighborsRegressor(), X, y, cv=5)
cross_validate(KNeighborsRegressor(n_neighbors=10), X, y, cv=5)
n = np.arange(2,50,2)
train_scores, test_scores = validation_curve(KNeighborsRegressor(),
                                            X,
                                            y,
                                            param_name='n_neighbors',
                                            param_range=n,
                                            cv=5)
np.mean(train_scores,axis=1)
plt.plot(np.mean(train_scores,axis=1))
plt.plot(np.mean(test_scores,axis=1))
plt.xticks(np.arange(24),n);
lc = learning_curve(KNeighborsRegressor(n_neighbors=6),X,y,cv=5)
samples, train, test = lc[0], lc[1], lc[2]
plt.plot(samples[1:],np.mean(train,axis=1)[1:])
plt.plot(samples[1:],np.mean(test,axis=1)[1:])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12266009852216748, 'fraction_numerical': 0.017733990147783252, 'mean_word_length': 4.358839050131926, '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': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '619978', 'license': 'MIT', 'n_tokens_mistral': 748, 'n_tokens_neox': 707, 'n_words': 108, 'path': 'Model_Selection.ipynb', 'repo_name': 'XavierCarrera/movie-budget-prediction', 'size': '2030'}