<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kyle Hammerberg on Medium]]></title>
        <description><![CDATA[Stories by Kyle Hammerberg on Medium]]></description>
        <link>https://medium.com/@khammerberg53?source=rss-a323e774aaec------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ZIJJWJ6WfUk2s9Vdb2Atcg.jpeg</url>
            <title>Stories by Kyle Hammerberg on Medium</title>
            <link>https://medium.com/@khammerberg53?source=rss-a323e774aaec------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 10:37:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@khammerberg53/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Anomaly Detection with Isolation Forest]]></title>
            <link>https://medium.com/@khammerberg53/anomaly-detection-with-isolation-forest-47c4996d2894?source=rss-a323e774aaec------2</link>
            <guid isPermaLink="false">https://medium.com/p/47c4996d2894</guid>
            <category><![CDATA[cancer]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[isolation-forests]]></category>
            <category><![CDATA[anomaly-detection]]></category>
            <dc:creator><![CDATA[Kyle Hammerberg]]></dc:creator>
            <pubDate>Tue, 28 Mar 2023 06:04:52 GMT</pubDate>
            <atom:updated>2023-03-28T06:04:52.367Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*KFdgByXybUcXpc51H8KBug.png" /></figure><p>Anomaly detection is an important task in a variety of industries. One popular algorithm for anomaly detection is the Isolation Forest. Isolation Forest is a tree-based approach that is relatively simple to understand and straightforward to implement with the python’s scikit-learn package.. In this article, we’ll provide a step-by-step tutorial on how to implement the Isolation Forest algorithm for anomaly detection on the Breast Cancer Wisconsin dataset, which is a publicly available dataset that contains labeled examples of malignant vs. benign tumors.</p><p><strong>Overview of Isolation Forest</strong></p><p>The Isolation Forest algorithm is an unsupervised learning technique used for anomaly detection. It is based on the concept of isolating anomalies in a dataset by building multiple random trees, called isolation trees. It was introduced by Fei Tony Liu, Kai Ming Ting, and Zhi-Hua Zhou in their 2008 paper “Isolation Forest.”</p><p>The core idea behind Isolation Forest is that anomalies can be easily isolated because they have different attribute values compared to normal instances. In the algorithm, each tree is constructed by recursively splitting the dataset using randomly selected features and values until every instance is isolated.</p><p>Here are the key elements of the Isolation Forest algorithm:</p><ol><li>Random partitioning: At each node of an isolation tree, the algorithm selects a random feature and a random split value within the range of the selected feature. The dataset is then split into two subsets based on the split value.</li><li>Recursive tree construction: The random partitioning process is repeated recursively until all instances are isolated, or a maximum depth limit (typically set as log2(n), where n is the number of instances) is reached.</li><li>Path length: The path length from the root node to the terminating node is a measure of how easily an instance can be isolated. Anomalies tend to have shorter path lengths because they can be isolated more quickly than normal instances.</li><li>Ensemble of isolation trees: The algorithm constructs an ensemble of isolation trees, usually several hundred trees, to improve detection performance. Each tree is built on a subsample of the dataset.</li><li>Anomaly score: For each instance, the average path length across all trees in the forest is calculated. The anomaly score is then computed by normalizing the average path length. Instances with higher anomaly scores are considered more likely to be anomalies.</li></ol><p>The sklearn implementation of the Isolation Forest algorithm can be found in the sklearn.ensemble.IsolationForest class. It provides an easy-to-use interface for training and predicting with the algorithm, as well as options for adjusting various parameters, such as the number of trees, subsampling size, and random seed.</p><p>The algorithm works as follows:</p><ol><li>Randomly select a feature and a split point for the data.</li><li>Partition the data into two subsets based on the selected feature and split point.</li><li>Repeat steps 1 and 2 recursively until each data point is isolated in its own subset.</li><li>The isolation score for each data point is the number of splits required to isolate it.</li><li>Anomalies are identified as data points with a high isolation score.</li></ol><p>The Isolation Forest algorithm has several advantages over other anomaly detection algorithms, such as being insensitive to the distribution of the data and being able to handle high-dimensional datasets efficiently. It also has a few hyperparameters that can be tuned, such as the number of trees in the forest and the maximum depth of each tree.</p><p><strong>Tutorial: Anomaly Detection with Isolation Forest</strong></p><p>Now, let’s walk through a step-by-step tutorial on how to implement the Isolation Forest algorithm for anomaly detection on the Breast Cancer Wisconsin dataset.</p><p><strong>Step 1: Import the Required Libraries</strong></p><p>We’ll start by importing the required libraries for loading the dataset, preprocessing the data, and implementing the Isolation Forest algorithm. In this tutorial, we’ll use Pandas, NumPy, Scikit-learn, and Matplotlib.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c2e93e42931db2835f98eab01708d158/href">https://medium.com/media/c2e93e42931db2835f98eab01708d158/href</a></iframe><p><strong>Step 2: Load and Preprocess the Dataset</strong></p><p>Next, we’ll load the dataset and assign our target (dependent) variable to <em>y </em>and the features (independent variables) to <em>X</em>. Finally, we’ll set aside 30% of the dataset to validate the model (e.g., establish a test set).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9e5b367ef86471c8942f7826766f85e1/href">https://medium.com/media/9e5b367ef86471c8942f7826766f85e1/href</a></iframe><p><strong>Step 3: Train the Isolation Forest Model</strong></p><p>We’ll now train the Isolation Forest model on the training set using the default hyperparameters and then generate predictions. The np.where() function will be used to code the prediction output to match how the original dataset codes benign vs. malignant observations klearn returns a 1 for inliers and 0 for outliers, but the breast cancer dataset codes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7538983fd40e7aca52a59e666c83c00d/href">https://medium.com/media/7538983fd40e7aca52a59e666c83c00d/href</a></iframe><p>Next, we’ll generate a confusion matrix and print the classification report to gauge the model’s performance. The code snippet below uses seaborn’s heatmap() function to create a nicely annotated visualization of the confusion matrix. The annot parameter is set to True to display the actual values in each cell. The fmt parameter is set to &#39;d&#39; for integer formatting, and the cmap parameter is set to &#39;coolwarm&#39; for a blue-to-red color scale. We disable the colorbar by setting the cbar parameter to False. Finally, we customize the labels using the xticklabels, yticklabels, xlabel, ylabel, and title properties.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c45d22cc81b07b76d9c700ad2d439289/href">https://medium.com/media/c45d22cc81b07b76d9c700ad2d439289/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*RlXHlG4ifACJ7HK0qtek7g.png" /></figure><p>The confusion matrix above shows that, in identifying malignant tumors, we had 11 true positives, 8 false positives, 100 true negatives, and 52 false negatives.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EtBGjZ5E-h4i6uepOzOLlw.png" /></figure><p>Here’s a brief summary of each metric in the classification report:</p><ol><li>Precision: The proportion of true positive predictions among all positive predictions. High precision indicates that when the model predicts a positive class, it is usually correct.</li><li>Recall (also known as Sensitivity or True Positive Rate): The proportion of true positive predictions among all actual positive instances. High recall indicates that the model is good at identifying positive instances.</li><li>F1-score: The harmonic mean of precision and recall. It provides a single score that balances both precision and recall. A high F1-score indicates that both precision and recall are high.</li><li>Support: The number of instances for each class in the true labels. It gives an idea of the class distribution in the dataset.</li><li>Accuracy: The proportion of correct predictions among all predictions. It is a widely used metric, but can be misleading if the class distribution is imbalanced.</li><li>Macro average: The average of a metric across all classes, without considering the class size. It gives equal weight to each class.</li><li>Weighted average: The average of a metric across all classes, considering the class size (support). It is a better measure when dealing with imbalanced datasets.</li></ol><p>Now, let’s interpret the results:</p><p>Class 0 (Malignant):</p><ul><li>Precision: 0.58, meaning that when the model predicts an instance as malignant, it is correct 58% of the time.</li><li>Recall: 0.17, meaning that the model correctly identifies only 17% of the malignant instances.</li><li>F1-score: 0.27, a low score indicating that the model is not performing well for the malignant class.</li></ul><p>Class 1 (Benign):</p><ul><li>Precision: 0.66, meaning that when the model predicts an instance as benign, it is correct 66% of the time.</li><li>Recall: 0.93, meaning that the model correctly identifies 93% of the benign instances.</li><li>F1-score: 0.77, a relatively good score, indicating that the model performs better for the benign class.</li></ul><p>Overall performance:</p><ul><li>Accuracy: 0.65, meaning that the model is correct 65% of the time. However, accuracy alone may not be a reliable metric due to potential class imbalance.</li><li>Macro average F1-score: 0.52, suggesting average performance across both classes.</li><li>Weighted average F1-score: 0.58, which is slightly better than the macro average, indicating that the model performs better on the more common benign class.</li></ul><p>In summary, the model performs better at identifying benign instances (class 1) than malignant instances (class 0). The overall performance is not very high, suggesting that there is room for improvement.</p><p>Now, let’s try to improve the model by adjusting the contamination parameter. This parameter represents the proportion of outliers we expect in the dataset. Since we know the true labels, we can estimate the proportion of malignant cases in the training set:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31f841575f80d39e955225f2e65377e1/href">https://medium.com/media/31f841575f80d39e955225f2e65377e1/href</a></iframe><p>Finally, let’s visualize the results. We’ll create a confusion matrix heatmap for both the initial and the improved model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*KEUQ38IdxDUPzTLrJNM7Fg.png" /></figure><p>It’s clear immediately that our model is much better at identifying our target Malignant class. Let’s take a look at the classification report for the new model:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/944/1*KnlqlEoODnQqa726k2eArA.png" /></figure><p><strong>Comparison:</strong></p><p><strong>Class 0 (Malignant):</strong></p><ul><li>Precision remains the same in both models (0.58).</li><li>Recall improves significantly from 0.17 to 0.65.</li><li>F1-score also improves significantly from 0.27 to 0.61.</li></ul><p><strong>Class 1 (Benign):</strong></p><ul><li>Precision improves from 0.66 to 0.78.</li><li>Recall decreases from 0.93 to 0.72.</li><li>F1-score decreases slightly from 0.77 to 0.75.</li></ul><p><strong>Overall performance:</strong></p><ul><li>Accuracy improves from 0.65 to 0.70.</li><li>Macro average F1-score improves from 0.52 to 0.68.</li><li>Weighted average F1-score improves from 0.58 to 0.70.</li></ul><p>The new model shows a significant improvement in the classification of malignant instances (class 0), with a higher recall and F1-score. The precision for benign instances (class 1) has also improved, but the recall and F1-score for class 1 have slightly decreased.</p><p>Overall, the new model demonstrates better performance across all metrics, with higher accuracy, macro average, and weighted average scores. This indicates that the new model is likely to be a better classifier than the previous one.</p><p>Although we improved the model’s performance to some extent, there may still be room for further improvements. Possible paths forward include:</p><ul><li>Fine-tuning the model parameters (e.g., the number of estimators or the maximum samples) to find an optimal configuration.</li><li>Feature engineering to improve the representation of the data, such as removing irrelevant features, normalization, or dimensionality reduction.</li><li>Ensuring the model is not overfitting by using techniques such as cross-validation, regularization, and monitoring performance on a separate validation set.</li></ul><p>Apart from the Isolation Forest algorithm, there are other anomaly detection algorithms that might perform better depending on the dataset and the specific problem:</p><ul><li>Local Outlier Factor (LOF): This method calculates the local density deviation of instances with respect to their neighbors, identifying instances that have lower density than their surroundings as outliers.</li><li>One-Class Support Vector Machine (OCSVM): A variation of the standard SVM, this algorithm is trained on only one class and aims to separate the instances of that class from the origin in feature space, detecting anomalies as instances that fall outside the separation boundary.</li><li>DBSCAN (Density-Based Spatial Clustering of Applications with Noise): A clustering algorithm that groups instances based on density, treating sparse regions as noise or outliers.</li><li>Autoencoders: Neural networks that learn to reconstruct input data, where the reconstruction error can be used to measure the “outlierness” of instances. High reconstruction errors are often associated with anomalies.</li></ul><p>In the next article in our series on anomaly detection, we will walk through the process of building an autoencoder using TensorFlow and Keras to detect credit card fraud transactions. I hope you enjoyed!</p><p>[1] <a href="https://scikit-learn.org/stable/index.html">https://scikit-learn.org/stable/index.html</a></p><p>[2] <a href="https://www.researchgate.net/publication/224384174_Isolation_Forest">https://www.researchgate.net/publication/224384174_Isolation_Forest</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=47c4996d2894" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Stock Price Prediction: LightGBM & MLForecast (Pt. 1)]]></title>
            <link>https://medium.com/@khammerberg53/stock-price-prediction-lightgbm-mlforecast-pt-1-7a79c7861d28?source=rss-a323e774aaec------2</link>
            <guid isPermaLink="false">https://medium.com/p/7a79c7861d28</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[lightgbm]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[investing]]></category>
            <category><![CDATA[stock-market]]></category>
            <dc:creator><![CDATA[Kyle Hammerberg]]></dc:creator>
            <pubDate>Sun, 14 Aug 2022 17:21:54 GMT</pubDate>
            <atom:updated>2022-08-15T15:52:07.766Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*USfoEXczggdrghpnRFkY1w.jpeg" /><figcaption><a href="https://unsplash.com/photos/DfjJMVhwH_8">Photo by Austin Distel</a></figcaption></figure><p><strong>Introduction</strong></p><p>This article assumes the reader has some foundational knowledge in time series analysis and machine learning. I will do the best I can to offer brief refreshers as we move through the material, but for the sake of maintaining focus, I won’t spend too much time on digressions or explanations of sub-topics that aren’t the primary concern of this article.</p><p>Today, I’m going to be demonstrating a method that should offer the reader a starting point for forecasting stock prices with machine learning. This article will ultimately be the first in a series of many. This article is intended to provide just a simple introduction / method to modeling stock prices with ML.</p><p>It should be noted that the methods shared in this article are not investment advice. The stock market is notoriously difficult to model. I would not recommend using this code to make investment decisions.</p><p>With that being said, let’s get started…</p><p><strong>The Algorithm</strong></p><p>Today we’re going to be building a forecasting model with the open source, gradient boosting framework LightGBM. LGBM is a highly distributed tree-based algorithm developed by Microsoft that uses multiple loss functions, bagging, regularization, and sparse optimization to efficiently deliver more accurate results [1]. Gradient boosted trees use decision trees to approximate a function we’ll call <em>F-hat</em> by splitting nodes where the most information gain occurs, minimizing some loss function <em>L. </em>This can be expressed formally as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/470/1*vpoZptdyZW_fa2PtaZ-1PQ.png" /><figcaption>img source: <a href="https://en.wikipedia.org/wiki/Gradient_boosting">https://en.wikipedia.org/wiki/Gradient_boosting</a></figcaption></figure><p>The formula above is just a precise way of saying we’re finding the smallest possible expected value of the loss function. In gradient boosting, the model learns by measuring the incremental changes to the loss function as measured by the gradient. Remember, the gradient is just a vector of derivatives and derivatives measure rate of change.</p><p>‘Boosting’ refers to the process of aggregating numerous ‘weak’ learners to produce a single ‘strong’ learner. Gradient boosting will make an approximation of the function, measure the residuals, and then fit a new weak learner that maps the feature vector to the residual vector. Repeating this process and aggregating the weak learners incrementally moves the overall model closer to the correct target [2].</p><p>The two primary innovations driving LGBM’s increased performance are Gradient Based One Side Sampling (GOSS) and Exclusive Feature Bundling (EFB). The researchers that introduced LGBM in <a href="https://proceedings.neurips.cc/paper/2017/file/6449f44a102fde848669bdd9eb6b76fa-Paper.pdf">this</a> seminal paper noted that gradient size played a significant role in how much different training instances contributed to information gain. Instead of uniformly sampling the instances at random, the under-trained instances (those with large gradients) are retained, while the instances with small gradients are dropped at random. The second innovation driving LGBMs state of the art performance, <em>Exclusive Feature Bundling</em>, reduces the number of effective features in a manner that results in almost no loss in performance. The paper uses the example of compressing <a href="https://machinelearningmastery.com/one-hot-encoding-for-categorical-data/">one-hot encoded features</a> down into a single feature. These features are often extremely sparse and can be easily combined into a single feature [3].</p><p><strong>Forecasting Time Series with Machine Learning</strong></p><p>For many years, methods like ARIMA and ETS were the standard for time series forecasting. In the last 10–15 years, deep learning techniques like LSTM neural networks and transformer-based sequence prediction algorithms have become prominent, but until very recently, machine learning methods like tree-based algorithms have not often been used. In the past, machine learning methods typically would perform poorly, and the implementation was not straightforward. However, that’s beginning to change. Machine learning frameworks like XGBoost, Catboost, and LightGBM are now being applied quite successfully to time series problems on websites like Kaggle and other competitive data science platforms.</p><p>One of the main challenges associated with time series forecasting using ML techniques is the complexity associated with updating features for each forecasted time step. Fortunately, the python package MLForecast provides an easy-to-use framework that offers users a simple, efficient way to update the model features recursively by recomputing them with the most recent target variable forecast and then updating the model.</p><p>Today, we’re going to use the python package MLForecast to forecast stock prices, first, with a base model that uses traditional time series indicators like lagged values and expanding means. In the next article in the series, we’ll include other macro variables that have been fractionally differenced. Fractional differencing renders time series stationary, while still preserving memory.</p><p><strong>MLForecast</strong></p><p>In Figure 1 below, I’ve provided a visualization that illustrates the way the predicted value at a given time step is fed back into the model as the value for the lag-1 feature, and then the model is updated with the new value for the Yt-1 feature and then the updated model is used to forecast the next value for Yt. This process iterates until the model has forecasted out to the desired time step.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mPvtR7GPUrxu8UPjdo-liA.png" /><figcaption>Figure 1: Recursively Updating Lagged Feature [4]</figcaption></figure><p>To get started creating our own forecasting model that leverages MLForecast, let’s import the packages we’re going to be using, and then read in some data. It should be noted that this code was produced in Google Colab, so to ensure it’s completely reproducible for you, I would recommend running it on the same platform.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e6a89f1bfaacf8fc0f1e0ef49ba2748/href">https://medium.com/media/2e6a89f1bfaacf8fc0f1e0ef49ba2748/href</a></iframe><p>Now that we’ve read in our data, let’s reformat it to be compatible with MLForecast. For the initial model, we’re not going to worry about anything other than our target variable (the stock’s closing price) and the time series features we will initialize later. To prepare our dataframe, we will drop the OHLV columns, rename the column for closing price as ‘y’ as it’s our target variable, then we will insert a new index titled ‘unique_id,’ and finally, we will convert our ‘date’ index into a new column labeled ‘ds.’ We could include multiple series in one dataframe, denoted by their unique series id in the index, but for the sake of simplicity, we’ll just use one series to start.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fa76356e7c6433742fdbb11d9104b01a/href">https://medium.com/media/fa76356e7c6433742fdbb11d9104b01a/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*SD72XCCF96hlzf3XicW96g.png" /><figcaption>Figure 2: Proper df format for MLForecast</figcaption></figure><p>Next, let’s initialize our model and our time series object. I’m not going to spend a lot of time discussing hyperparameter tuning / selection. I will mention that we’re optimizing for root mean squared error, a common metric used in time series analysis. Overall, parameterization is outside the scope of this article, but I will briefly discuss the time series object we’re creating. This project will ultimately end up being a series of articles and hyperparameter selection will be covered in a later article. First, I just want to get you up and running with a simple model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e19934936bf6598419fa21498e62dcd8/href">https://medium.com/media/e19934936bf6598419fa21498e62dcd8/href</a></iframe><p>We’re using the TimeSeries() function from the MLForecast package to create a time series object, and I’m going to walk you through each argument.</p><p>First, we specify ‘D’ indicating that the time steps occur in daily intervals, then we specify what lagged-values we want to use. In this case, I’ve selected the 3rd and 7th lagged values of our target variable. We’re also going to compute the expanding mean for lag-1, and then the rolling mean for lag 7 using a 14 day sliding window. We will use the specific day of the week and the month as features, as these features can have an impact on stock price behavior. Finally, by specifying a ‘num_threads’ value &gt; 1, computing the transformations can be parallelized using <a href="https://www.techtarget.com/whatis/definition/multithreading#:~:text=Multithreading%20is%20the%20ability%20of,requests%20from%20the%20same%20user.">multithreading</a> [5].</p><p>Next, we will initialize a forecasting object with the Forecast() function. This function takes the model and time series object we just created as arguments and returns a new forecasting object. Then we will call .fit on the forecasting object we’ve created and then call .preprocess() to generate a new dataframe with all of the time series features we’ve created.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5c229f0abc137e68dbc668cf435c8395/href">https://medium.com/media/5c229f0abc137e68dbc668cf435c8395/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3xteJgbXM-YwiXRLhwIubQ.png" /><figcaption>Figure 3: New dataframe with time series features</figcaption></figure><p>Now, we will set up a test-train split using masking, and then fit our model, and generate the loss curve. Again, this article is really just about getting started with a functional forecasting model, so I won’t be diving into tuning the model, but it will be covered later in the series.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c307016518927cde264207803dc6451/href">https://medium.com/media/2c307016518927cde264207803dc6451/href</a></iframe><p>Finally, we’re ready to make some predictions! Predicting is as simple as calling .predict() on our forecasting object. I’ve also written a simple function that will convert the date column in our prediction dataframe into a column that tells us how many trading days out a prediction is being made. I did this because otherwise it would date predictions for days when the markets aren’t open (e.g., the weekends or holidays).</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c79e6e05f5425f577bf3d34fca1e7bcc/href">https://medium.com/media/c79e6e05f5425f577bf3d34fca1e7bcc/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*naGuEV7ZTVQa7uQ8_UOI3g.png" /></figure><p>Congratulations!</p><p>You’ve just used machine learning to forecast stock prices. In the next article in this series, I’ll show you how to integrate various macro variables and fractional differencing into your model.</p><p>[1] LightGBM, <a href="https://lightgbm.readthedocs.io/en/v3.3.2/">documentation</a></p><p>[2] Explained.AI, <a href="https://explained.ai/gradient-boosting/faq.html#:~:text=To%20improve%20its%20predictions%2C%20gradient,vector%20to%20that%20residual%20vector.">Gradient Boosting</a></p><p>[3] Ke et. al., <a href="https://proceedings.neurips.cc/paper/2017/file/6449f44a102fde848669bdd9eb6b76fa-Paper.pdf">LightGBM: A Highly Efficient Gradient Boosting Decision Tree</a>, 2017</p><p>[4] Dask &amp; José Morales,<a href="https://www.youtube.com/watch?v=yc7V177X53A&amp;ab_channel=Dask"> MLForecast: Scalable Machine Learning Based Time Series Forecasting</a>, 2021</p><p>[5] PyPi, <a href="https://pypi.org/project/mlforecast/">MLForecast Documentation</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7a79c7861d28" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>