Machine Learning for Time Series Forecasting with Python. Francesca Lazzeri

Чтение книги онлайн.

Читать онлайн книгу Machine Learning for Time Series Forecasting with Python - Francesca Lazzeri страница 10

Machine Learning for Time Series Forecasting with Python - Francesca Lazzeri

Скачать книгу

of non-fraudulent transactions) and identify anything that is significantly different.Principal component analysis: Principal component analysis is a method for reducing the dimensionality of the feature space by representing it with fewer uncorrelated variables. Data scientists use it when they need to combine input features in order to drop the least important features while still retaining the most valuable information from the features in the data set.Principal component analysis is very helpful when data scientists need to answer questions such as the following:How can we understand the relationships between each variable?How can we look at all of the variables collected and focus on a few of them?How can we avoid the danger of overfitting our model to our data?

       Reinforcement learning is a type of machine learning system in which the algorithm is trained to make a sequence of decisions. The algorithm learns to achieve a goal in an uncertain, potentially complex environment by employing a trial and error process to come up with a solution to the problem (aka.ms/MLAlgorithmCS).Data scientists need to define the problem a priori, and the algorithm gets either rewards or penalties for the actions it performs. Its goal is to maximize the total reward. It's up to the model to figure out how to perform the task to maximize the reward, starting from totally random trials. Here are some examples of applications of reinforcement learning:Reinforcement learning for traffic signal controlReinforcement learning for optimizing chemical reactionsReinforcement learning for personalized news recommendations

      When data scientists are choosing an algorithm, there are many different factors to take into consideration (aka.ms/AlgorithmSelection):

       Evaluation criteria: Evaluation criteria help data scientists to evaluate the performance of their solutions by using different metrics to monitor how well machine learning models represent data. They are an important step in the training pipeline to validate a model. There are different evaluation metrics for different machine learning approaches, such as accuracy, precision, recall, F-score, receiver operating characteristic (ROC), and area under the curve (AUC) for classification scenarios and mean absolute error (MAE), mean squared error (MSE), R-squared score, and adjusted R-squared for regression scenarios. MAE is a metric that can be used to measure forecast accuracy. As the name denotes, it is the mean of the absolute error: the absolute error is the absolute value of the difference between the forecasted value and the actual value, and it is scale-dependent: The fact that this metric is not scaled to the average demand can represent a limitation for data scientists who need to compare accuracy across time series with different scales. For time series forecasting scenarios, data scientists can also use the mean absolute percentage error (MAPE) to compare the fits of different forecasting and smoothing methods. This metric expresses accuracy as a percentage of MAE and allows data scientists to compare forecasts of different series in different scales.

       Training time: Training time is the amount of time needed to train a machine learning model. Training time is often closely tied to overall model accuracy. In addition, some algorithms are more sensitive to the number of data points than others. When time is limited, it can drive the choice of algorithm, especially when the data set is large.

       Linearity: Linearity is mathematical function that identifies a specific relationship between data points of a data set. This mathematical relationship means that data points can be graphically represented as a straight line. Linear algorithms tend to be algorithmically simple and fast to train. Different machine learning algorithms make use of linearity. Linear classification algorithms (such as logistic regression and support vector machines) assume that classes in a data set can be separated by a straight line. Linear regression algorithms assume that data trends follow a straight line.

       Number of parameters: Machine learning parameters are numbers (such as the number of error tolerance, the number of iterations, the number of options between variants of how the algorithm behaves) that data scientists usually need to manually select in order to improve an algorithm's performance (aka.ms/AlgorithmSelection). The training time and accuracy of the algorithm can sometimes be quite sensitive to getting just the right settings. Typically, algorithms with large numbers of parameters require the most trial and error to find a good combination. While this is a great way to make sure you've spanned the parameter space, the time required to train a model increases exponentially with the number of parameters. The upside is that having many parameters typically indicates that an algorithm has greater flexibility. It can often achieve very good accuracy, provided you can find the right combination of parameter settings (aka.ms/AlgorithmSelection).

       Number of features: Features are properties of a phenomenon based on which data scientists would like to predict results. A large number of features can overload some learning algorithms, making training time long. Data scientists can perform techniques such as feature selection and dimensionality reduction to reduce the number and the dimensionality of the features they have to work with. While both methods are used for reducing the number of features in a data set, there is an important difference:Feature selection is simply selecting and excluding given features without changing them.Dimensionality reduction transforms features into a lower dimension.

      With these important machine learning concepts in mind, you can now learn how to reshape your forecasting scenario as a supervised learning problem and, as a consequence, get access to a large portfolio of linear and nonlinear machine learning algorithms

      We can summarize some observations from Figure 1.8 in the following way:

       The value of Sensor_1 at prior time step (for example, 01/01/2020) becomes the input (Value x) in a supervised learning problem.

       The value of Sensor_1 at subsequent time step (for example, 01/02/2020) becomes the output (Value y) in a supervised learning problem.

       It is important to note that the temporal order between the Sensor_1 values needs to be maintained during the training of machine learning algorithms.

       By performing this transformation on our time series data, the resulting supervised learning data set will show an empty value (NaN) in the first row of Value x. This means that no prior Value x can be leveraged to predict the first value in the time series data set. We suggest removing this row because we cannot use it for our time series forecasting solution.

       Finally, the subsequent next value to predict for the last value in the sequence is unknown: this is the value that needs to be predicted by our machine learning model.

      How can we turn any time series data set into a supervised learning problem? Data scientists usually exploit the values of prior time steps to predict the subsequent time step value by using a statistical method, called the sliding window method. Once the sliding window method is applied and a time series data set is converted,

Скачать книгу