Spaces:
Build error
Build error
Download time_series_splitter.py from Abdulabin/AutoML_Model: direct link, hf CLI and curl.
- Browser
- Download file 635 Bytes
-
https://huggingface.co/spaces/Abdulabin/AutoML_Model/resolve/main/time_series_splitter.py
- Command line
-
hf download hf://spaces/Abdulabin/AutoML_Model/time_series_splitter.py
-
curl -L -o time_series_splitter.py https://huggingface.co/spaces/Abdulabin/AutoML_Model/resolve/main/time_series_splitter.py
635 Bytes
| import pandas as pd | |
| from sklearn.model_selection import train_test_split | |
| def split_time_series_data(date_column,X, y, test_size=0.2): | |
| """Split time series data into training and testing sets.""" | |
| # Sort the data by date | |
| X_sorted = X.sort_values(by=date_column) | |
| y_sorted = y.loc[X_sorted.index] | |
| # Calculate the split index | |
| split_index = int(len(X_sorted) * (1 - test_size)) | |
| # Split the data | |
| X_train, X_test = X_sorted.iloc[:split_index], X_sorted.iloc[split_index:] | |
| y_train, y_test = y_sorted.iloc[:split_index], y_sorted.iloc[split_index:] | |
| return X_train, X_test, y_train, y_test | |