{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "7f20c8e7", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/hanyueju/miniconda3/envs/kronos/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "from model import Kronos, KronosTokenizer, KronosPredictor\n", "\n", "# Load from Hugging Face Hub\n", "tokenizer = KronosTokenizer.from_pretrained(\"NeoQuasar/Kronos-Tokenizer-base\")\n", "model = Kronos.from_pretrained(\"NeoQuasar/Kronos-base\")" ] }, { "cell_type": "code", "execution_count": 2, "id": "72dc9ba9", "metadata": {}, "outputs": [], "source": [ "# Initialize the predictor\n", "predictor = KronosPredictor(model, tokenizer, max_context=512)" ] }, { "cell_type": "code", "execution_count": 30, "id": "b07f8d0b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "X 的行数: 400\n", "Y 的行数: 120\n" ] } ], "source": [ "import pandas as pd\n", "\n", "# Load your data\n", "df = pd.read_csv(\"/home/hanyueju/MinModel/data/qlib_ready_csv/sz002709.csv\")\n", "df['timestamps'] = pd.to_datetime(df['date'])\n", "df.sort_values('timestamps', inplace=True, ascending=True)\n", "df = df.reset_index(drop=True)\n", "\n", "# Define context window and prediction length\n", "lookback = 400\n", "pred_len = 120\n", "\n", "# Prepare inputs for the predictor\n", "x_df = df.iloc[-(lookback + pred_len):-pred_len][['open', 'high', 'low', 'close', 'volume', 'amount']]\n", "\n", "x_timestamp = df.iloc[-(lookback + pred_len):-pred_len]['timestamps']\n", "\n", "y_timestamp = df.iloc[-pred_len:]['timestamps']\n", "# 可以打印一下长度检查是否绝对正确:\n", "print(f\"X 的行数: {len(x_df)}\") # 应该输出 400\n", "print(f\"Y 的行数: {len(y_timestamp)}\") # 应该输出 120" ] }, { "cell_type": "code", "execution_count": 32, "id": "a6466d07", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " 0%| | 0/120 [00:00