<jupyter_start><jupyter_text>Export model<jupyter_code>from sklearn.externals import joblib
import json

joblib.dump(regressor25, open('model/regressor25.sav', 'wb'))
joblib.dump(regressor85, open('model/regressor85.sav', 'wb'))
joblib.dump(poly, open('model/poly85.sav', 'wb'))
joblib.dump(regressorpoly85, open('model/regressorpoly85.sav', 'wb'))

export = {}
export['regressor25'] = {'intercept': regressor25.intercept_.tolist(), 'coef': regressor25.coef_.tolist() }
export['regressor85'] = {'intercept': regressor85.intercept_.tolist(), 'coef': regressor85.coef_.tolist() }
export['regressorpoly85'] = {'intercept': regressorpoly85.intercept_.tolist(), 'coef': regressorpoly85.coef_.tolist() }
file = open("model/regression.txt","w") 
file.write(json.dumps(export))
narrowtempandcrime = tempandcrime[tempandcrime.index < 25]

X = narrowtempandcrime.index.values.reshape(-1,1)
y = narrowtempandcrime['COUNT'].values.reshape(-1,1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

regressor = joblib.load('model/regressor25.sav')

#To retrieve the intercept:
print(regressor.intercept_)
#For retrieving the slope:
print(regressor.coef_)
y_pred = regressor.predict(X_test)
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))  
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))  
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))

x = np.linspace(-5,25,100)
y = regressor.coef_[0][0]*x+regressor.intercept_[0]

plt.figure(figsize=(20,10))
plt.plot(x, y, '-r')
plt.scatter(narrowtempandcrime.index,narrowtempandcrime['COUNT'],s=30)
narrowtempandcrime = tempandcrime[(tempandcrime.index >= 25) & (tempandcrime.index <= 85)]

X = narrowtempandcrime.index.values.reshape(-1,1)
y = narrowtempandcrime['COUNT'].values.reshape(-1,1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

regressor = joblib.load('model/regressor85.sav')

#To retrieve the intercept:
print(regressor.intercept_)
#For retrieving the slope:
print(regressor.coef_)
y_pred = regressor.predict(X_test)
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))  
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))  
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))

x = np.linspace(15,85,100)
y = regressor.coef_[0][0]*x+regressor.intercept_[0]

plt.figure(figsize=(20,10))
plt.plot(x, y, '-r')
plt.scatter(narrowtempandcrime.index,narrowtempandcrime['COUNT'],s=30)
narrowtempandcrime = tempandcrime[tempandcrime.index < 85]

X = narrowtempandcrime.index.values.reshape(-1,1)
y = narrowtempandcrime['COUNT'].values.reshape(-1,1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

regressor = joblib.load('model/regressorpoly85.sav')
poly = joblib.load('model/poly85.sav')

X_test_transfrom = poly.transform(X_test)

#To retrieve the intercept:
print(regressor.intercept_)
#For retrieving the slope:
print(regressor.coef_)
y_pred = regressor.predict(X_test_transfrom)
print('Mean Absolute Error:', metrics.mean_absolute_error(y_test, y_pred))  
print('Mean Squared Error:', metrics.mean_squared_error(y_test, y_pred))  
print('Root Mean Squared Error:', np.sqrt(metrics.mean_squared_error(y_test, y_pred)))

x = np.linspace(-5,100,100)
y = regressorpoly85.coef_[0][2]*(x**2)+regressorpoly85.coef_[0][1]*(x)+regressorpoly85.intercept_[0]

plt.figure(figsize=(20,10))
plt.plot(x, y, '-r')
plt.scatter(narrowtempandcrime.index,narrowtempandcrime['COUNT'],s=30)<jupyter_output>[208.61208972]
[[ 0.          1.504117   -0.00579864]]
Mean Absolute Error: 6.54864690005577
Mean Squared Error: 93.77087959726686
Root Mean Squared Error: 9.683536523257754
{'fraction_non_alphanumeric': 0.15865892291446673, 'fraction_numerical': 0.05279831045406547, 'mean_word_length': 7.791183294663573, 'pattern_counts': {'":': 0, '<': 7, '<?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': '516530', 'license': 'MIT', 'n_tokens_mistral': 1632, 'n_tokens_neox': 1421, 'n_words': 222, 'path': '.ipynb_checkpoints/linear_regression_analysis-checkpoint.ipynb', 'repo_name': 'chaipi-chaya/Boston-Crime-Analysis', 'size': '3788'}