Skip to content

Forecast service

Generates a forecast for the temperature data received from the input topic. This is to predict a potential failure condition, when the ambient temperature of the 3D printer drops below the minimum threshold for successful ABS-based printing.

Forecast pipeline segment

The forecast is made using the downsampled data as the input, and using the scikit-learn library. The forecasts are published to the forecast topic. The Alert service and Printers dashboard service both subscribe to this topic.

Data format

The forecast data format is:

  "Epoch": 0,
  "Timestamps": [
  "NumericValues": {
    "forecast_fluctuated_ambient_temperature": [
  "StringValues": {},
  "BinaryValues": {},
  "TagValues": {
    "printer": [
      "Printer 19-down-sampled",
      "Printer 19-down-sampled",
      "Printer 19-down-sampled",
      "Printer 19-down-sampled"

Prediction algorithm

The work of the prediction is carried out by the scikit-learn library, using a quadratic polynomial (second order) linear regression algorithm:

forecast_input = df[parameter_name]

# Define the degree of the polynomial regression model
degree = 2
# Create a polynomial regression model
model = make_pipeline(PolynomialFeatures(degree), LinearRegression())
# Fit the model to the data, 1), forecast_input)
# Forecast the future values
forecast_array = np.array(range(len(forecast_input), len(forecast_input) + forecast_length)).reshape(-1, 1)
forecast_values = model.predict(forecast_array)
# Create a DataFrame for the forecast
fcast = pd.DataFrame(forecast_values, columns=[forecast_label])

🏃‍♀️ Next step

Part 5 - Alert service