File size: 1,510 Bytes
df0843b 4b0bb56 2db7de7 8898ec4 9f075a6 be0f990 bd6ebda be0f990 4b0bb56 df0843b be0f990 57b6c80 be0f990 6200f2f be0f990 6200f2f be0f990 484cdf8 be0f990 484cdf8 be0f990 484cdf8 be0f990 2db7de7 be0f990 70f514e be0f990 70f514e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
import gradio as gr
import xgboost as xgb
import numpy as np
import pandas as pd
from huggingface_hub import hf_hub_download
# **📥 从 Hugging Face 下载 XGBoost 模型**
repo_id = "YDluffy/lottery_prediction"
model_filename = "lottery_xgboost_model.ubj"
model_path = hf_hub_download(repo_id=repo_id, filename=model_filename)
# **✅ 加载 XGBoost 预测模型**
model = xgb.Booster()
model.load_model(model_path)
# **📥 读取历史开奖记录**
history_data_path = "cleaned_mark_six.csv"
history_data = pd.read_csv(history_data_path)
# **📌 预测函数**
def predict_lottery(year, period):
# **📌 1. 查找往年相同期数的开奖记录**
historical_matches = history_data[history_data["期数"] == period]
# **📌 2. 计算历史趋势(如高频号码、奇偶比例)**
most_frequent_numbers = historical_matches.iloc[:, -7:].mode().iloc[0].tolist()
# **📌 3. 生成 XGBoost 预测输入**
test_features = np.array([[year, period] + most_frequent_numbers])
dtest = xgb.DMatrix(test_features)
# **📌 4. 进行预测**
prediction = model.predict(dtest)
final_prediction = np.round(prediction).astype(int).tolist()
return final_prediction
# **📌 创建 API 接口**
iface = gr.Interface(
fn=predict_lottery,
inputs=["number", "number"],
outputs="text",
title="六合彩智能预测 API",
description="输入年份和期数,自动分析历史开奖记录,预测开奖号码"
)
iface.launch(share=True)
|