weka.gui.beans.TimeSeriesForecastingCustomizer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of timeseriesForecasting Show documentation
Show all versions of timeseriesForecasting Show documentation
Provides a time series forecasting environment for Weka. Includes a wrapper for Weka regression schemes that automates the process of creating lagged variables and date-derived periodic variables and provides the ability to do closed-loop forecasting. New evaluation routines are provided by a special evaluation module and graphing of predictions/forecasts are provided via the JFreeChart library. Includes both command-line and GUI user interfaces. Sample time series data can be found in ${WEKA_HOME}/packages/timeseriesForecasting/sample-data.
The newest version!
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
/*
* TimeSeriesForecastingCustomizer.java
* Copyright (C) 2010-2016 University of Waikato, Hamilton, New Zealand
*/
package weka.gui.beans;
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.Customizer;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;
import weka.classifiers.timeseries.WekaForecaster;
import weka.core.Environment;
import weka.core.Instances;
import weka.gui.PropertySheetPanel;
/**
* Customizer for the TimeSeriesForecasting bean
*
* @author Mark Hall (mhall{[at]}pentaho{[dot]}com)
* @version $Revision: 49983 $
*
*/
public class TimeSeriesForecastingCustomizer extends JPanel implements
Customizer, CustomizerClosingListener, CustomizerCloseRequester {
/**
* For serialization
*/
private static final long serialVersionUID = -8638861579301145591L;
/** The forecaster to customize */
protected TimeSeriesForecasting m_forecaster = null;
/** The underlying WekaForecaster */
protected WekaForecaster m_forecastingModel = null;
/** The header of the data used to train the forecaster */
protected Instances m_header;
/** Handles the text field and file browser */
protected FileEnvironmentField m_filenameField =
new FileEnvironmentField();
/** Label for the num steps field */
protected JLabel m_numStepsLab;
/** Number of steps to forecast */
protected EnvironmentField m_numStepsToForecast =
new EnvironmentField();
/** Label for the artificial time stamp offset fields */
protected JLabel m_artificialLab;
/**
* Number of steps beyond the end of the training data that incoming
* historical priming data is
*/
protected EnvironmentField m_artificialOffset =
new EnvironmentField();
/** Rebuild the forecaster ? */
protected JCheckBox m_rebuildForecasterCheck = new JCheckBox();
/** Label for the save forecaster field */
protected JLabel m_saveLab;
/** Text field for the filename to save the forecaster to */
protected FileEnvironmentField m_saveFilenameField =
new FileEnvironmentField();
/** The text area to display the model in */
protected JTextArea m_modelDisplay = new JTextArea(20, 60);
/** Property sheet panel used to get the "About" panel for global info */
protected PropertySheetPanel m_sheetPanel = new PropertySheetPanel();
/** Environment variables to use */
protected transient Environment m_env = Environment.getSystemWide();
/** Frame containing us */
protected Window m_parentWindow;
/**
* Constructor
*/
public TimeSeriesForecastingCustomizer() {
setLayout(new BorderLayout());
m_filenameField.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
// first check if the field is blank (i.e. been cleared) and
// we have a loaded model - if so then just return. We'll
// encode the forecaster to base 64 and clear the filename
// field when the customizer closes.
if (TimeSeriesForecasting.isEmpty(m_filenameField.getText())) {
return;
}
loadModel();
if (m_forecastingModel != null) {
m_modelDisplay.setText(m_forecastingModel.toString());
checkIfModelIsUsingArtificialTimeStamp();
checkIfModelIsUsingOverlayData();
}
}
});
}
/**
* Set the object to edit
*
* @param object the object to edit
*/
public void setObject(Object object) {
setupLayout();
m_forecaster = (TimeSeriesForecasting)object;
m_sheetPanel.setTarget(m_forecaster);
String loadFilename = m_forecaster.getFilename();
if (!TimeSeriesForecasting.isEmpty(loadFilename) &&
!loadFilename.equals("-NONE-")) {
m_filenameField.setText(loadFilename);
loadModel();
} else {
String encodedForecaster = m_forecaster.getEncodedForecaster();
if (!TimeSeriesForecasting.isEmpty(encodedForecaster) &&
!encodedForecaster.equals("-NONE-")) {
try {
List