<jupyter_start><jupyter_text>**model.py**Model building file that is responsible for creating a model, including:    - feature engineering    - all data preprocessing    - model training<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from pathlib import Path
from sklearn.linear_model import LinearRegression
import pickle

PATH = Path(Path.cwd())
DATA = Path(PATH, 'deployment', 'data', 'raw', 'tree_months_sales.csv')
df = pd.read_csv(DATA)
df
df['rate'].fillna(0, inplace=True)

df['sales_in_first_month'].fillna(df['sales_in_first_month'].mean(), inplace=True)

X = df.iloc[:, :3]
X
def convert_word_to_int(word):
    word_dict = {'one':1, 'two':2, 'three':3, 'four':4, 'five':5, 'six':6, 'seven':7, 'eight':8,
                'nine':9, 'ten':10, 'eleven':11, 'twelve':12, 'zero':0, 0: 0}
    return word_dict[word]

X['rate'] = X['rate'].apply(lambda x : convert_word_to_int(x))

y = df.iloc[:, -1]


regressor = LinearRegression()

regressor.fit(X, y)

pickle.dump(regressor, open('model.pkl','wb'))
import pickle 
model = pickle.load(open('model.pkl','rb'))
# print(model.predict([[4, 300, 500]]))
dir<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1753191489361702, 'fraction_numerical': 0.023829787234042554, 'mean_word_length': 5.606741573033708, 'pattern_counts': {'":': 0, '<': 5, '<?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': '113297', 'license': 'MIT', 'n_tokens_mistral': 461, 'n_tokens_neox': 439, 'n_words': 99, 'path': 'app/machinelearning/Testing.ipynb', 'repo_name': 'flaviassantos/machinelearning', 'size': '1175'}