#!/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: B188 — Hồi quy vectơ hỗ trợ nhân phi tuyến
Tên quốc tế: Support Vector Regression with Cross-Validated Kernel & Permutation Effects
Mã mô hình : svr_econometric
Phần mềm : Python 3.11+ — Thư viện: scikit-learn
Dữ liệu   : vietlod_svr_econometric_ecodata.csv
Kiểm định : Out-of-fold $K$-fold CV RMSE, MAE và $R^2_{\text{OOS}}$, tỷ lệ support vectors, bảng độ quan trọng biến hoán vị kèm độ lệch chuẩn, đạo hàm riêng biên trung bình.
"""

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_svr_econometric_ecodata.csv"
if not os.path.exists(DATA_FILE):
    DATA_FILE = "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_svr_econometric_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 B188 — Hồi quy vectơ hỗ trợ nhân phi tuyến
import pandas as pd
df = pd.read_csv('vietlod_svr_econometric_ecodata.csv')
print(df.describe())
# GridSearchCV(SVR(kernel='rbf'), param_grid={'C': [1, 10], 'epsilon': [0.1, 0.2]}, cv=5).fit(X_std, y)

print("Hoan tat uoc luong mo hinh B188 (svr_econometric) tren Python 3.11+.")
