<jupyter_start><jupyter_text>Scatterplots of features<jupyter_code>fig, axs = plt.subplots(figsize = (16,8), ncols = 4, nrows=2)
# print(fig,axs)
lm_features = ['ZN', 'INDUS','NOX','AGE',\
               'DIS', 'RAD','PTRATIO', 'LSTAT']
for i, feature in enumerate(lm_features):
    row = int(i/4)
    col = i%4
#     print(row, col)
    sns.regplot(x = feature, \
                y = bostonDF.columns[-1], \
                data = bostonDF, ax = axs[row][col])

# scatterplot, lmplot<jupyter_output><empty_output><jupyter_text>Modeling<jupyter_code>from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score


y_target = bostonDF['PRICE']
X_data = bostonDF.drop(['PRICE'],axis=1,inplace=False)

X_train , X_test , y_train , y_test = train_test_split(X_data , y_target ,test_size=0.3, random_state=156)

lr = LinearRegression()
lr.fit(X_train,y_train)

y_preds = lr.predict(X_test)

mse = mean_squared_error(y_test, y_preds)
rmse = np.sqrt(mse)
r2 = r2_score(y_test, y_preds)

print("mse : {:3f}".format(mse))
print("rmse : {:3f}".format(rmse))
print("Variance_score : {}".format(r2))

print( "intercept values : {}".format(lr.intercept_ ) ,'\n' )
# print(lr.coef_)
print("coefficients : " , np.round(lr.coef_,1))

coef = np.round(lr.coef_, 1)
coeff = pd.Series(coef, index = X_train.columns )
coeff.sort_values(ascending = False)
from sklearn.model_selection import StratifiedKFold
from sklearn.model_selection import cross_val_score


y_target = bostonDF['PRICE']
X_data = bostonDF.drop(['PRICE'],axis=1,inplace=False)
lr = LinearRegression()


neg_mse_scores = cross_val_score(lr, X_data, y_target, scoring="neg_mean_squared_error", cv = 3)
rmse_scores  = np.sqrt(-1 * neg_mse_scores)
avg_rmse = np.mean(rmse_scores)

print(' 5 folds Negative MSE scores: ', np.round(neg_mse_scores, 2))
print(' 5 folds RMSE scores : ', np.round(rmse_scores, 2))
print(' 5 folds average RMSE : {0:.3f} '.format(avg_rmse))<jupyter_output>5 folds Negative MSE scores:  [ -20.63  -34.48 -451.91]
 5 folds RMSE scores :  [ 4.54  5.87 21.26]
 5 folds average RMSE : 10.558
{'fraction_non_alphanumeric': 0.1499535747446611, 'fraction_numerical': 0.02924791086350975, 'mean_word_length': 5.03641456582633, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '221899', 'license': 'MIT', 'n_tokens_mistral': 924, 'n_tokens_neox': 852, 'n_words': 164, 'path': 'ML/Chapter 05_04.ipynb', 'repo_name': 'gurher/Data-Analysis', 'size': '2154'}