<jupyter_start><jupyter_text>Dataset<jupyter_code>DATA_PATH = os.path.abspath(
    r"C:\Users\Jan\Dropbox\_Coding\UdemyML\Chapter13_CaseStudies\CaseStudyWebServer\employee_data.csv"
)
df = pd.read_csv(DATA_PATH)

df = df.drop("Unnamed: 0", axis=1)
df = df.drop("id", axis=1)
df.head()
data = df.to_numpy()

x = data[:, :-1]
y = data[:, -1]

categorical_features = [0]
numerical_features = [1, 2, 3]

print(f"x shape: {x.shape}")
print(f"y shape: {y.shape}")<jupyter_output>x shape: (1000, 4)
y shape: (1000,)<jupyter_text>Sklearn Imports<jupyter_code>from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OrdinalEncoder
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.pipeline import Pipeline
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.3)
regr = RandomForestRegressor(n_estimators=100)
numeric_transformer = Pipeline(
    steps=[
        ('scaler', StandardScaler())
    ]
)

categorical_transformer = Pipeline(
    steps=[
        ('ordinal', OrdinalEncoder())
    ]
)

preprocessor_odinal = ColumnTransformer(
    transformers=[
        ('numeric', numeric_transformer, numerical_features),
        ('categorical', categorical_transformer, categorical_features)
    ]
)
pipe_ordinal = Pipeline(
    steps=[
        ('preprocessor_odinal', preprocessor_odinal),
        ('regressor', regr)
    ]
)
pipe_ordinal.fit(x_train, y_train)
score = pipe_ordinal.score(x_test, y_test)

print(f"Score: {score}")
import pickle

pickle.dump(regr, open("model.pkl", "wb"))
regr = pickle.load(open("model.pkl", "rb"))

x_sample = np.array([0, 40, 10, 10])
y_pred = regr.predict([x_sample])

print(f"Pred: {y_pred}")<jupyter_output>Pred: [4303.44]
{'fraction_non_alphanumeric': 0.13968957871396895, 'fraction_numerical': 0.02106430155210643, 'mean_word_length': 5.423487544483986, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '630262', 'license': 'MIT', 'n_tokens_mistral': 704, 'n_tokens_neox': 677, 'n_words': 123, 'path': 'Chapter13_CaseStudies/CaseStudyWebServer/model.ipynb', 'repo_name': 'tomex74/UdemyML', 'size': '1804'}