import requests import zipfile import os # 下载Telco Customer Churn数据集 def download_telco_churn(): # 使用公开可访问的数据集URL url = "https://raw.githubusercontent.com/IBM/telco-customer-churn-on-icp4d/master/data/Telco-Customer-Churn.csv" # 创建data目录(如果不存在) os.makedirs("data", exist_ok=True) # 下载文件 response = requests.get(url) response.raise_for_status() # 保存文件 file_path = "data/Telco-Customer-Churn.csv" with open(file_path, "wb") as f: f.write(response.content) print(f"数据集已成功下载到 {file_path}") return file_path if __name__ == "__main__": download_telco_churn()