有没有可能仅仅基于x值来训练数据和预测?你知道吗
在我的图表上,我有黑色的点(35,20)。当使用35进行预测时,该值应返回0,但像15这样的点(大多数数据点位于黑线上方)应返回1
This is what my data looks like
def createFeatures(startTime, datapoints, function, *days):
trueStrength = []
functionData = []
beginPrice = []
endPrice = []
deltaPrice = []
for x in range(datapoints*5):
#----Friday Data----
if x%4 == 0 and x != 0:
endPrice.append((sg.HighPrice[startTime+x]+sg.LowPrice[startTime+x]+sg.ClosePrice[startTime+x])/3)
#----Monday Data----
if x%5 == 0:
functionData.append(function(trueStrength, startTime+x, *days))
beginPrice.append((sg.HighPrice[startTime+x]+sg.LowPrice[startTime+x]+sg.ClosePrice[startTime+x])/3)
for x in range(len(beginPrice)):
deltaPrice.append(endPrice[x] - beginPrice[x])
return functionData , deltaPrice
def createLabels(data, deltaPrice):
labels = []
for x in range(len(data)):
if deltaPrice[x] > 0:
labels.append(1.0)
else:
labels.append(0.0)
return labels
x, y = createFeatures(20, 200, ti.SMA, 7)
z = createLabels(x,y)
下面是我的线性回归模型:
labels = np.asarray(at.z)
x = np.asarray([at.x])
y = np.asarray([at.y])
testX=35.1
testY=20.1
test = np.array([[testX, testY]])
clf = LinearRegression().fit(x, y)
print clf.predict(4)
一个完整的例子
注意重塑
看起来你在尝试线性回归。相关文档是here。你知道吗
你可以只根据x值来预测,但是你需要y值来训练(否则你怎么知道要预测什么?)。你知道吗
从sklearn:
相关问题 更多 >
编程相关推荐