<jupyter_start><jupyter_text>Working with jsonsaving the model in the json format<jupyter_code>import json
model.coef_
model.intercept_
model_param={}
model_param['coef']=list(model.coef_)
model_param['intercept']=model.intercept_.tolist()
json_txt=json.dumps(model_param,indent=4)
json_txt
with open('models/regressor_param.txt','w') as file:
    file.write(json_txt)
with open('models/regressor_param.txt','r') as file:
    json_text=json.load(file)
json_model=LinearRegression()
json_model.coef_=np.array(json_text['coef'])
json_model.intercept_=np.array(json_text['intercept'])
y_pred=json_model.predict(x_test)
r2_score(y_test,y_pred)
testing_score<jupyter_output><empty_output><jupyter_text>Working with picklesaving the model in pickle format<jupyter_code>import pickle

pickle.dump(model,open('models/model.pkl','wb'))
pickle_model=pickle.load(open('models/model.pkl','rb'))
y_pred=pickle_model.predict(x_test)

r2_score(y_test,y_pred)<jupyter_output><empty_output><jupyter_text>Working with joblibsaving the model using joblib<jupyter_code>import joblib
filename='models/model.joblib'
joblib.dump(model,filename)
joblib_model=joblib.load(filename)
y_pred=joblib_model.predict(x_test)
r2_score(y_test,y_pred)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13001605136436598, 'fraction_numerical': 0.0032102728731942215, 'mean_word_length': 11.989583333333334, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '316747', 'license': 'MIT', 'n_tokens_mistral': 485, 'n_tokens_neox': 476, 'n_words': 57, 'path': 'Serializing_Sklearn_Model.ipynb', 'repo_name': 'avitomar12/Regression-Classification-Clustring', 'size': '1246'}