#!/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 1: Kinh tế lượng nền tảng và mô hình dữ liệu chéo thực nghiệm
Buổi học : Buổi 06 — Nhóm 2.2 Chọn mô hình và suy luận chiều cao
Bài giảng: B020 — Hồi quy Lasso thích nghi có trọng số
Tên quốc tế: Adaptive Lasso
Mã mô hình : adaptive_lasso
Phần mềm : Python 3.11+ — Thư viện: scikit-learn
Dữ liệu   : vietlod_adaptive_lasso_ecodata.csv
Kiểm định : Đường chuẩn hóa CV MSE — $\lambda_{\min}, \lambda_{1\text{se}}$ , tỷ lệ độ thưa, out-of-sample $R^2$ & RMSE.
"""

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_adaptive_lasso_ecodata.csv"
if not os.path.exists(DATA_FILE):
    DATA_FILE = "https://sachktl.tnsai.vn/src/ecoaz/data/vietlod_adaptive_lasso_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 B020 — Hồi quy Lasso thích nghi có trọng số
import pandas as pd
df = pd.read_csv('vietlod_adaptive_lasso_ecodata.csv')
print(df.describe())
# LassoCV(cv=5, random_state=42).fit(X_weighted, y)

print("Hoan tat uoc luong mo hinh B020 (adaptive_lasso) tren Python 3.11+.")
