<jupyter_start><jupyter_text>LOAD PACKAGES AND DATA<jupyter_code># LOAD DATASET
from sklearn.datasets import load_boston

# LOAD MODELS
from sklearn.linear_model import LinearRegression, BayesianRidge, LassoCV, ElasticNetCV
from sklearn.metrics import mean_squared_error

# LOAD EXTRAS
from sklearn.cross_validation import train_test_split, KFold
import numpy as np
import matplotlib.pyplot as plt
data = load_boston()

features = data.data
target = data.target<jupyter_output><empty_output><jupyter_text>Linear Regression (Train test split)<jupyter_code>X_train, X_test, y_train, y_test = train_test_split(features, target, test_size = 0.33, random_state = 42)
lr_tts = LinearRegression(fit_intercept=True, normalize=True)
lr_tts.fit(X_train, y_train)
y_hat_lr_tts = lr_tts.predict(X_test)
lr_tts.score(X_test, y_test)
mse_lr_tts = mean_squared_error(y_test, y_hat_lr_tts)
print(np.sqrt(mse_lr_tts))<jupyter_output>4.55490322184<jupyter_text>Linear Regression (KFold)<jupyter_code>kf = KFold(len(features), n_folds=5)
lr_kf = LinearRegression(fit_intercept=True, normalize=True)
scores_lr_kf = []
mse_lr_kf = []
for train, test in kf:
    lr_kf.fit(features[train], target[train])
    y_hat_lr_kf = lr_kf.predict(features[test])
    scores_lr_kf.append(lr_kf.score(features[test], target[test]))
    mse_lr_kf.append(np.sqrt(mean_squared_error(y_hat_lr_kf, target[test])))
for i in range(0, len(mse_lr_kf)):
    print('RMSE: {0}\t| SCORE: {1}'.format(mse_lr_kf[i], scores_lr_kf[i]))<jupyter_output>RMSE: 3.53279637288	| SCORE: 0.638610693529
RMSE: 5.10844425141	| SCORE: 0.638610693529
RMSE: 5.75499399415	| SCORE: 0.713344317153
RMSE: 8.99072042601	| SCORE: 0.586451336256
RMSE: 5.79520108817	| SCORE: 0.0784249546783<jupyter_text>Lasso  ElasticNet<jupyter_code>l1_ratio = [.01, .05, .25, .5, .75, .95, .99]

kf = KFold(len(features), n_folds=5)
met = ElasticNetCV(n_jobs = 4, l1_ratio = l1_ratio)

scores = []
mse = []
for train, test in kf:
    met.fit(features[train], target[train])
    y_hat = met.predict(features[test])
    mse.append(mean_squared_error(target[test], y_hat))
    scores.append(met.score(features[test], target[test]))
for i in range(0, len(mse)):
    print('RMSE: {0}\t| SCORE: {1}'.format(np.sqrt(mse[i]), scores[i]))<jupyter_output>RMSE: 4.20186755552	| SCORE: 0.488762380111
RMSE: 5.82730997593	| SCORE: 0.626990854355
RMSE: 7.52467450392	| SCORE: 0.293011565935
RMSE: 7.78636743235	| SCORE: 0.308787620353
RMSE: 4.44216554715	| SCORE: 0.257838137208<jupyter_text>Bayesian Ridge<jupyter_code>clf = BayesianRidge(normalize=True)
clf.fit(X_train, y_train)
y_hat = clf.predict(X_test)
clf.score(X_test, y_test)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1301575393848462, 'fraction_numerical': 0.10990247561890473, 'mean_word_length': 6.985029940119761, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, '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': '374098', 'license': 'MIT', 'n_tokens_mistral': 1357, 'n_tokens_neox': 1165, 'n_words': 189, 'path': 'Boston House Prices/Boston.model.ipynb', 'repo_name': 'HishamElamir/DataModels', 'size': '2666'}