I am a beginner using HTM.when I run the quick-start example in the website(http://nupic.docs.numenta.org/stable/quick-start/opf.html) with the datasets I made,I didn’t change any parameters,and I suffered an problem:
the quick-start example codes:
import yaml
from nupic.frameworks.opf.model_factory import ModelFactory
_PARAMS_PATH = "model.yaml"
with open(_PARAMS_PATH, "r") as f:
modelParams = yaml.safe_load(f)
print modelParams
model = ModelFactory.create(modelParams)
# This tells the model the field to predict.
model.enableInference({'predictedField': 'consumption'})
import csv
import datetime
#file = open('data.csv','w+')
# Open the file to loop over each row
with open ("realMode.csv") as fileIn:
reader = csv.reader(fileIn)
# The first three rows are not data, but we'll need the field names when
# passing data into the model.
headers = reader.next()
reader.next()
reader.next()
for record in reader:
# Create a dictionary with field names as keys, row values as values.
modelInput = dict(zip(headers, record))
# Convert string consumption to float value.
modelInput = dict(zip(headers, record))
# Convert string consumption to float value.
modelInput["consumption"] = float(modelInput["consumption"])
# Convert timestamp string to Python datetime.
modelInput["timestamp"] = datetime.datetime.strptime(
modelInput["timestamp"], "%m/%d/%y %H:%M"
)
# Push the data into the model and get back results.
result = model.run(modelInput)
#print result
bestPredictions = result.inferences['multiStepBestPredictions']
allPredictions = result.inferences['multiStepPredictions']
oneStep = bestPredictions[1]
twoStep = bestPredictions[2]
fiveStep = bestPredictions[5]
# Confidence values are keyed by prediction value in multiStepPredictions.
oneStepConfidence = allPredictions[1][oneStep]
fiveStepConfidence = allPredictions[5][fiveStep]
twoStepConfidence = allPredictions[2][twoStep]
result = (oneStep, oneStepConfidence * 100,twoStep, twoStepConfidence*100,
fiveStep, fiveStepConfidence * 100)
#esult = (fifStep,fifStepConfidence * 100)
print "1-step: {:16} ({:4.4}%)\t 2-step: {:16} ({:4.4}%)\t 5-step: {:16} ({:4.4}%)".format(*result)
Datasets of mine:
timestamp,consumption
float,float
,
08/02/10 00:00,0
08/02/10 01:00,1
08/02/10 02:00,2
08/02/10 03:00,3
08/02/10 04:00,4
08/02/10 05:00,5
08/02/10 06:00,6
08/02/10 07:00,7
08/02/10 08:00,8
08/02/10 09:00,9
08/02/10 10:00,10
08/02/10 11:00,11
08/02/10 12:00,12
08/02/10 13:00,13
08/02/10 14:00,14
08/02/10 15:00,15
08/02/10 16:00,16
08/02/10 17:00,17
08/02/10 18:00,18
08/02/10 19:00,19
08/02/10 20:00,20
08/02/10 21:00,21
08/02/10 22:00,22
08/02/10 23:00,23
.......
02/26/11 05:00,4997
02/26/11 06:00,4998
02/26/11 07:00,4999
it is a sequence like the function y=x,total 5000 rows
and the result:
1-step: 4978.66666667 (99.99%) 2-step: 4978.66666667 (99.99%) 5-step: 4978.66666667 (99.99%)
1-step: 4979.66666667 (100.0%) 2-step: 4979.66666667 (100.0%) 5-step: 4979.66666667 (100.0%)
1-step: 4980.66666667 (99.97%) 2-step: 4980.66666667 (99.85%) 5-step: 4980.66666667 (99.97%)
1-step: 4981.66666667 (92.65%) 2-step: 4981.66666667 (92.41%) 5-step: 4981.66666667 (92.26%)
1-step: 4982.66666667 (89.2%) 2-step: 4982.66666667 (89.03%) 5-step: 4982.66666667 (88.6%)
1-step: 4983.66666667 (92.78%) 2-step: 4983.66666667 (92.77%) 5-step: 4983.66666667 (92.77%)
1-step: 4984.66666667 (99.99%) 2-step: 4984.66666667 (99.98%) 5-step: 4984.66666667 (99.99%)
1-step: 4985.66666667 (99.95%) 2-step: 4985.66666667 (99.96%) 5-step: 4985.66666667 (99.96%)
1-step: 4986.66666667 (93.35%) 2-step: 4986.66666667 (92.99%) 5-step: 4986.66666667 (94.28%)
1-step: 4987.66666667 (98.29%) 2-step: 4987.66666667 (98.3%) 5-step: 4987.66666667 (98.45%)
1-step: 4992.0 (49.19%) 2-step: 4992.0 (48.18%) 5-step: 4992.0 (47.94%)
1-step: 4989.66666667 (97.96%) 2-step: 4989.66666667 (97.98%) 5-step: 4989.66666667 (97.96%)
1-step: 4990.66666667 (98.76%) 2-step: 4990.66666667 (98.78%) 5-step: 4990.66666667 (98.78%)
1-step: 4991.66666667 (98.54%) 2-step: 4991.66666667 (98.57%) 5-step: 4991.66666667 (98.54%)
1-step: 4992.66666667 (98.48%) 2-step: 4992.66666667 (98.46%) 5-step: 4992.66666667 (98.44%)
1-step: 4993.66666667 (97.8%) 2-step: 4993.66666667 (97.79%) 5-step: 4993.66666667 (97.82%)
1-step: 4994.66666667 (97.47%) 2-step: 4994.66666667 (97.52%) 5-step: 4994.66666667 (97.49%)
1-step: 4995.66666667 (96.86%) 2-step: 4995.66666667 (96.87%) 5-step: 4995.66666667 (96.87%)
as we see, the prediction value is always less than the orgin value(and it should be equal with the origin data) ,and values of 1-step,2-step,and 5-step are almost the same.So I assume that the algorithm didn’t learn the function y=x well .But the function is so simple,why HTM can not learn such a simple function ?And I assume the fuction is too simple,so the paramters do not need to change . if I use Linear regression of scikit-learn ,it will perform perfectly! So I don’t know what is the problem.