Beispiel #1
0
X_cleaned = pd.concat(
    [X.drop("x5", inplace=False, axis=1),
     onehot_encode(X[["x5"]])], axis=1)
model = RandomForestRegressor(random_state=123)
model.fit(X_cleaned, y)

print("Writting X ...... ")
with open(os.path.join(path_to_fixtures, "X.pickle"), "wb") as X_pickle:
    X.to_pickle(X_pickle)
print("Writting X_cleaned ...... ")
with open(os.path.join(path_to_fixtures, "X_cleaned.pickle"),
          "wb") as X_pickle:
    X_cleaned.to_pickle(X_pickle)
print("Writting y ...... ")
with open(os.path.join(path_to_fixtures, "y.npy"), "wb") as y_npy:
    np.save(y_npy, y)
print("Writting the model ...... ")
with open(os.path.join(path_to_fixtures, "model.pickle"),
          "wb") as model_pickle:
    pickle.dump(model, model_pickle)

print("Saving metadata ...... ")
with open(os.path.join(path_to_fixtures, "fixtures_metadata.txt"),
          "w") as metadata_file:
    metadata_file.writelines([
        "Time created: {}\n".format(pd.Timestamp.now()),
        "sklearn: {}\n".format(model.__getstate__()["_sklearn_version"]),
        "pandas: {}\n".format(pd.__version__),
        "numpy: {}\n".format(np.__version__),
    ])