<jupyter_start><jupyter_text>Treinando novamente com cross_val<jupyter_code>from sklearn.model_selection import cross_val_score
regressor.fit(x_train, y_train)
cross_val_score(regressor, x_train, y_train, cv = 5)<jupyter_output><empty_output><jupyter_text><jupyter_code># Fazer a predição (Rodar a base de testes)

prediction = regressor.predict(x_test)
# Avaliar o erro médio e o Rˆ2

from sklearn.metrics import mean_squared_error
from sklearn.metrics import r2_score

# Dispersão entre y_test e prediction
plt.scatter(y_test, prediction, edgecolor = "Black")

print("Erro médio: ", mean_squared_error(y_test, prediction))
print("Variância: ", r2_score(y_test, prediction))
# Dispersão de predição vs Y

plt.figure(figsize = (20,7))

# Retorna os índices que ordenariam um array
indices = np.argsort(y)
pred = regressor.predict(x)

plt.scatter(range(len(y)), pred[indices], label = 'predictions')
plt.scatter(range(len(y)), y[indices], label = 'Valores originais')
plt.legend()
# Distribuição de erro
# Histograma, certificando que está distribuído normalmente

sns.distplot((y_test - prediction), bins = 50, hist_kws = dict(edgecolor = 'Black'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11205432937181664, 'fraction_numerical': 0.007640067911714771, 'mean_word_length': 7.361702127659575, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '309862', 'license': 'MIT', 'n_tokens_mistral': 453, 'n_tokens_neox': 429, 'n_words': 99, 'path': 'linear-regression/USA-Housing-Linear-Regression.ipynb', 'repo_name': 'JVBravoo/Learning-Machine-Learning', 'size': '1178'}