<jupyter_start><jupyter_text><jupyter_code>import numpy as np
from flows.flows import Flows
flow = Flows(flow_id=0, categorical_threshold=10)
path = os.path.join('data','flow_0')
files_list = ["train.csv","test.csv"]
dataframe_dict, columns_set = flow.load_data(path, files_list)
 columns_set
dataframe_dict, columns_set = flow.encode_categorical_feature(dataframe_dict)
ignore_columns = ['Id', 'SalePrice']
dataframe_dict, columns_set = flow.scale_data(dataframe_dict, ignore_columns)
flow.exploring_data(dataframe_dict, "train")
flow.comparing_statistics(dataframe_dict)
ignore_columns = ["Id", "SalePrice"]
columns = dataframe_dict["train"].columns
train_dataframe = dataframe_dict["train"][[x for x in columns_set["train"]["continuous"] if x not in ignore_columns]]
test_dataframe = dataframe_dict["test"][[x for x in columns_set["train"]["continuous"] if x not in ignore_columns]]
train_target = dataframe_dict["train"]["SalePrice"]
parameters = {
    "data": {
        "train": {"features": train_dataframe, "target": train_target.to_numpy()},
    },
    "split": {
        "method": "kfold",  # "method":"kfold"
        "fold_nr": 5,  # fold_nr:5 , "split_ratios": 0.3 # "split_ratios":(0.3,0.2)
    },
    "model": {"type": "Ridge linear regression",
              "hyperparameters": {"alpha": "optimize",  # alpha:optimize
                                  },
              },
    "metrics": ["r2_score"],
    "predict": {
        "test": {"features": test_dataframe}
    }
}
model_index_list, save_models_dir, y_test = flow.training(parameters)
parameters_lighgbm = {
    "data": {
        "train": {"features": train_dataframe, "target": train_target.to_numpy()},
    },
    "split": {
        "method": "kfold",  # "method":"kfold"
        "fold_nr": 5,  # fold_nr:5 , "split_ratios": 0.3 # "split_ratios":(0.3,0.2)
    },
    "model": {"type": "lightgbm",
              "hyperparameters": dict(objective='regression', metric='root_mean_squared_error', num_leaves=5,
                                      boost_from_average=True,
                                      learning_rate=0.05, bagging_fraction=0.99, feature_fraction=0.99, max_depth=-1,
                                      num_rounds=10000, min_data_in_leaf=10, boosting='dart')
              },
    "metrics": ["mean_squared_error"],
    "predict": {
        "test": {"features": test_dataframe}
    }
}
model_index_list, save_models_dir, y_test = flow.training(parameters_lighgbm)
parameters_xgboost = {
    "data": {
        "train": {"features": train_dataframe, "target": train_target.to_numpy()},
    },
    "split": {
        "method": "kfold",  # "method":"kfold"
        "fold_nr": 5,  # fold_nr:5 , "split_ratios": 0.3 # "split_ratios":(0.3,0.2)
    },
    "model": {"type": "xgboost",
              "hyperparameters": {'max_depth': 5, 'eta': 1, 'eval_metric': "rmse", "num_round": 100}
              },
    "metrics": ["r2_score", "mean_squared_error"],
    "predict": {
        "test": {"features": test_dataframe}
    }
}
model_index_list, save_models_dir, ytest = flow.training(parameters_xgboost)
parameters_sklearn = {
    "data": {
        "train": {"features": train_dataframe, "target": train_target.to_numpy()},
    },
    "split": {
        "method": "split",
        "split_ratios": 0.2,
        "stratify": False  # set to True only for classification tasks
    },
    "model": {
        "type": "sklearn.ensemble.RandomForestRegressor",
        "hyperparameters": {
            'params_grid':{
                'criterion': ["mse", "mae"],
                'max_depth': [5, 10, 15, 999],
                'min_samples_leaf': [4, 1],
                'max_depth': [4, 8, 12],
            },
            'params_fixed': {
                'min_samples_split': 10, 
                'random_state': 11
            },
            'params_cv': {
                'n_splits': 5, 
                'shuffle': True, 
                'random_state': 11
            },
            'objective': 'regression',  # 'classification'
            "grid_search_scoring": ['r2', 'neg_mean_squared_error']
        },
    },
    "metrics": ["r2_score", "mean_squared_error"],
    "predict": {
        "test": {"features": test_dataframe}
    }
}

model_index_list, save_models_dir, y_test = flow.training(parameters_sklearn)
parameters_sklearn = {
    "data": {
        "train": {"features": train_dataframe, "target": train_target.to_numpy()},
    },
    "split": {
        "method": "split",
        "split_ratios": 0.2,
        "stratify": False  # set to True only for classification tasks
    },
    "model": {
        "type": "sklearn.linear_model.ElasticNet",
        "hyperparameters": {
            'params_grid':{
                'alpha': np.logspace(-3,3,7),
                'l1_ratio': np.linspace(0, 0., num=4)+0.01
            },
            'params_fixed': {
                'normalize': True, 
                'max_iter': 2000,
                'random_state': 11
            },
            'params_cv': {
                'n_splits': 5, 
                'shuffle': True, 
                'random_state': 11
            },
            'objective': 'regression',  # 'classification'
            "grid_search_scoring": ['r2', 'neg_mean_squared_error']
        },
    },
    "metrics": ["r2_score", "mean_squared_error"],
    "predict": {
        "test": {"features": test_dataframe}
    }
}

model_index_list, save_models_dir, y_test = flow.training(parameters_sklearn)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15909505564677978, 'fraction_numerical': 0.018427294289363256, 'mean_word_length': 2.498404594767071, 'pattern_counts': {'":': 85, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '53986', 'license': 'Apache-2.0', 'n_tokens_mistral': 1876, 'n_tokens_neox': 1779, 'n_words': 313, 'path': 'tutorials/flow_0.ipynb', 'repo_name': 'KI-labs/ML-Navigator', 'size': '5481'}