Instructions to use GeoTrix/Datathon with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Keras
How to use GeoTrix/Datathon with Keras:
# !pip install -U keras tensorflow huggingface_hub # Keras needs TensorFlow installed to read "hf://" paths, so the tensorflow backend is selected here; # "jax" and "torch" also work for computation once TensorFlow is installed. import os os.environ["KERAS_BACKEND"] = "tensorflow" import keras model = keras.saving.load_model("hf://GeoTrix/Datathon") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from GeoTrix/Datathon: direct link, hf CLI and curl.
- Browser
- Download file 3.21 kB
-
https://huggingface.co/GeoTrix/Datathon/resolve/main/README.md
- Command line
-
hf download hf://GeoTrix/Datathon/README.md
-
curl -L -o README.md https://huggingface.co/GeoTrix/Datathon/resolve/main/README.md
3.21 kB
| license: unknown | |
| datasets: | |
| - GeoTrix/Datathon | |
| # Model For Datathon | |
| This repo holds 2 final models that was used and made for Ristek Datathon. The first model is a Linear Regression Model, | |
| and the other is an LSTM Model. The datasets use to train the model rely with the yfinance python module, which is a module that was made by | |
| Yahoo! that stores the stock market data, from what price it opens, close, the highest price it reach on that day and the lowest and the volume. | |
| It was also slighly modified with some added features that was used for the Linear Regression Model, adding SMA, EMA and RSI. While the LSTM Model | |
| only relied only on the Closing price of the stock and without the added modified dataset due to during testing it generated the best result | |
| when just using the close feature. | |
| ## Using Linear Regression Model | |
| Sample python code to see the linear regression model | |
| ``` | |
| from joblib import load | |
| import yfinance as yf | |
| # Grab the most recent stock data | |
| data = yf.download('AAPL', period='40d') | |
| # Adding SMA (Simple Moving Average) into the data | |
| data['SMA_5'] = data['Close'].rolling(window=5).mean() | |
| data['SMA_10'] = data['Close'].rolling(window=10).mean() | |
| # Adding EMA (Exponential Moving Average) into the data | |
| data['EMA_5'] = data['Close'].ewm(span=5, adjust=False).mean() | |
| data['EMA_10'] = data['Close'].ewm(span=10, adjust=False).mean() | |
| # Adding RSI (Relative Strength Index) into the data | |
| delta = data['Close'].diff() | |
| avg_gain = (delta.where(delta > 0, 0)).rolling(window=14).mean() | |
| avg_loss = (-delta.where(delta < 0, 0)).rolling(window=14).mean() | |
| rs = avg_gain / avg_loss | |
| data['RSI'] = 100 - (100 / (1 + rs)) | |
| # Grab the features of the final stock price to predict the next day stock | |
| feature = data[['Open', 'High', 'Low', 'Close', 'Volume', 'SMA_5', 'SMA_10', 'EMA_5', 'EMA_10', 'RSI']].tail().values | |
| # Load the models in your directory | |
| model = load('Path/Of/The/Model') | |
| predictions = model.predict(feature) | |
| # Predicts gives the next day stock | |
| print(f"Predicted: ${predictions[0]:.2f}") | |
| ``` | |
| ## Using LSTM Model | |
| Sample python code to see the LSTM model | |
| ``` | |
| import yfinance as yf | |
| from tensorflow.keras.models import load_model | |
| from sklearn.preprocessing import MinMaxScaler | |
| import numpy as np | |
| # Grab the most recent stock data | |
| data = yf.download('AAPL', period='40d') | |
| # Normalize the data | |
| scaler = MinMaxScaler(feature_range=(0, 1)) | |
| scaled_features = scaler.fit_transform(data[['Close']]) | |
| # Grabbing the last 30 days of data for prediction | |
| windows_size = 30 | |
| last_30_days = scaled_features[-windows_size:] | |
| # Shaping the data to match the model input | |
| x = np.reshape(last_30_days, (1, windows_size, 1)) | |
| # Loading model | |
| model = load_model('Models/Stockly-lstm.keras') | |
| # Predicting the next day's stock price | |
| predictions = model.predict(x) | |
| predictions = scaler.inverse_transform(predictions) | |
| print(f"Predicted: ${predictions[0][0]:.2f}") | |
| ``` | |
| **NOTE:** These models are still very new and not that highly accurate. So don't really use them for actual usage to trade in the stock market, | |
| but rather have fun with it, since the model itself was made pretty rushed to complete the Datathon. If the model ever get updated to be more accurate | |
| this NOTE should be gone. | |