是否有可能仅基于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)发布于 2019-02-07 16:33:27
一个完整的例子
import numpy as np
from sklearn.linear_model import LinearRegression
x = np.random.rand(100)
y = np.random.randint(0,2,size=100)
print (x.shape)
clf = LinearRegression()
clf.fit(x.reshape(-1,1),y)请注意重塑
https://stackoverflow.com/questions/54565585
复制相似问题