$ pip install nupic
python
import nupic
from nupic.algorithms.anomaly import computeRawAnomalyScore
from nupic.algorithms.anomaly import computeAnomalyScore
from nupic.encoders import RandomDistributedScalarEncoder
from nupic.encoders import ScalarEncoder
from nupic.encoders.spatial import GridCellEncoder
from nupic.encoders.spatial import ScalarGridEncoder
from nupic.encoders.temporal import DateEncoder
from nupic.encoders.temporal import MultiEncoder
from nupic.research.TP10X2 import TP10X2
from nupic.research.TP10X2 import TP10X2_factory
from nupic.research.TP11X2 import TP11X2
from nupic.research.TP11X2 import TP11X2_factory
from nupic.research.TP import TP
from nupic.research.TP import TP_factory
from nupic.research.TPAM11 import TPAM11
from nupic.research.TPAM11 import TPAM11_factory
from nupic.swarming import permutations_runner
from nupic.frameworks.opf.clamodels.cluster_params import getScalarMetricWithTimeOfDayAnomalyParams
python
import pandas as pd
data = pd.read_csv('your_data.csv')
time_column = 'timestamp'
value_column = 'value'
python
python
encoder = ScalarEncoder(21, 0.0, 100, 21, clipInput=True)
encoded_data = encoder.encode(data[value_column].tolist())
python
model = TP11X2_factory.create(inputWidth=input_width, columnCount=1, numLayers=num_layers, numCellsPerLayer=num_cells_per_layer)
python
model.enableLearning()
for i in range(len(encoded_data) - input_width - prediction_steps):
model.setPredictedInput([0])
model.setInput(encoded_data[i:i+input_width])
model.run()
python
future_predictions = []
for i in range(prediction_steps):
prediction = model.getPredictedInput().getSparseData([0])[0][1]
future_predictions.append(prediction)
model.setPredictedInput([prediction])
model.run()