def main():
    fish_df = preprocessing('Fish.csv')
    (x_train, x_test, y_train, y_test) = split_df(fish_df, 'Weight', 0.8, 42)
    forest_size = 20
    max_depth = 3
    random_state_local = 42
    random_forest = create_random_forest(forest_size, max_depth, random_state_local)
    alpha = 0.5
    kf = KFold(n_splits=2, shuffle=True, random_state=42)
    for (train_index, test_index) in kf.split(x_train, y_train):
        (X_train, X_validate) = (x_train.iloc[train_index], x_train.iloc[test_index])
        (Y_train, Y_validate) = (y_train.iloc[train_index], y_train.iloc[test_index])
        initial_average_weight = np.average(Y_train['Weight'].tolist())
        (random_forest, predictions_train, r_matrix, mse_list_train) = train_forest(random_forest, initial_average_weight, X_train, Y_train, alpha)
        (predictions_validate, mse_list_validate) = test_forest(random_forest, initial_average_weight, X_validate, Y_validate, alpha)
        results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
        results['Train'] = mse_list_train
        results['Validation'] = mse_list_validate
        fig = px.scatter(results, x='tree_intervals', y=['Train', 'Validation'], size='tree_intervals')
        fig.update_layout(xaxis_title='Amount of Intervals (num.)', yaxis_title='mean square error')
        fig.show()
    (predictions_test, mse_list_test) = test_forest(random_forest, initial_average_weight, x_test, y_test, alpha)
    fig = make_subplots(rows=1, cols=3, subplot_titles=('Train', 'Validation', 'Test'), x_title='Amount of Intervals (num.)', y_title='mean square error')
    results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
    results['Train'] = mse_list_train
    fig.add_trace(go.Scatter(x=results['tree_intervals'], y=results['Train'], name='Train'), row=1, col=1)
    results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
    results['Validation'] = mse_list_validate
    fig.add_trace(go.Scatter(x=results['tree_intervals'], y=results['Validation'], name='Validation'), row=1, col=2)
    results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
    results['Test'] = mse_list_test
    fig.add_trace(go.Scatter(x=results['tree_intervals'], y=results['Test'], name='Test'), row=1, col=3)
    fig.update_layout(title_text='Random Forest Gradient Boosting')
    fig.show()
def main():
    fish_df = preprocessing('Fish.csv')
    (x_train, x_test, y_train, y_test) = split_df(fish_df, 'Weight', 0.8, 42)
    forest_size = 20
    max_depth = 3
    random_state_local = 42
    random_forest = create_random_forest(forest_size, max_depth, random_state_local)
    alpha = 0.5
    kf = KFold(n_splits=2, shuffle=True, random_state=42)
    for (train_index, test_index) in kf.split(x_train, y_train):
        (X_train, X_validate) = (x_train.iloc[train_index], x_train.iloc[test_index])
        (Y_train, Y_validate) = (y_train.iloc[train_index], y_train.iloc[test_index])
        initial_average_weight = np.average(Y_train['Weight'].tolist())
        (random_forest, predictions_train, r_matrix, mse_list_train) = train_forest(random_forest, initial_average_weight, X_train, Y_train, alpha)
        (predictions_validate, mse_list_validate) = test_forest(random_forest, initial_average_weight, X_validate, Y_validate, alpha)
        results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
        results['Train'] = mse_list_train
        results['Validation'] = mse_list_validate
        fig = px.scatter(results, x='tree_intervals', y=['Train', 'Validation'], size='tree_intervals')
        fig.update_layout(xaxis_title='Amount of Intervals (num.)', yaxis_title='mean square error')
        fig.show()
    (predictions_test, mse_list_test) = test_forest(random_forest, initial_average_weight, x_test, y_test, alpha)
    fig = make_subplots(rows=1, cols=3, subplot_titles=('Train', 'Validation', 'Test'), x_title='Amount of Intervals (num.)', y_title='mean square error')
    results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
    results['Train'] = mse_list_train
    fig.add_trace(go.Scatter(x=results['tree_intervals'], y=results['Train'], name='Train'), row=1, col=1)
    results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
    results['Validation'] = mse_list_validate
    fig.add_trace(go.Scatter(x=results['tree_intervals'], y=results['Validation'], name='Validation'), row=1, col=2)
    results = pd.DataFrame(data=np.arange(0, (forest_size + 1), 1), columns=['tree_intervals'])
    results['Test'] = mse_list_test
    fig.add_trace(go.Scatter(x=results['tree_intervals'], y=results['Test'], name='Test'), row=1, col=3)
    fig.update_layout(title_text='Random Forest Gradient Boosting')
    fig.show()