#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
HỆ SINH THÁI HỌC THUẬT TNSAI — SACHKTL.TNSAI.VN & VIETLOD.TNSAI.VN
Khóa học : Khóa 4: Kinh tế lượng Bayes, SEM, học máy nhân quả và mô hình cấu trúc
Buổi học : Buổi 03 — Nhóm 12.3 Học máy kinh tế lượng
Bài giảng: B186 — Hồi quy rừng ngẫu nhiên Breiman và độ quan trọng biến hoán vị
Tên quốc tế: Random Forest
Mã mô hình : random_forest_regressor
Phần mềm : Python 3.11+ — Thư viện: scikit-learn
Dữ liệu   : vietlod_random_forest_regressor_ecodata.csv
Kiểm định : Sai số dự báo ngoài túi và $R^2$, độ quan trọng biến theo hoán vị ngoài mẫu, biểu đồ phụ thuộc riêng phần và cùng K-Fold
"""

import os
import warnings
import numpy as np
import pandas as pd

warnings.filterwarnings("ignore")

# 1. Nạp bộ dữ liệu thực hành chuẩn hóa
DATA_FILE = "vietlod_random_forest_regressor_ecodata.csv"
if not os.path.exists(DATA_FILE):
    DATA_FILE = "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_random_forest_regressor_ecodata.csv"

df = pd.read_csv(DATA_FILE)
print(f"Kich thuoc mau thuc hanh {DATA_FILE}: {df.shape[0]} quan sat x {df.shape[1]} bien so")

# 2. Thực thi kịch bản ước lượng và kiểm định B186 — Hồi quy rừng ngẫu nhiên Breiman và độ quan trọng biến hoán vị
import pandas as pd
df = pd.read_csv('vietlod_random_forest_regressor_ecodata.csv')
print(df.describe())
# RandomForestRegressor(n_estimators=200, random_state=42).fit(X, y)

print("Hoan tat uoc luong mo hinh B186 (random_forest_regressor) tren Python 3.11+.")
