首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在sklearn python中根据一个值进行预测

如何在sklearn python中根据一个值进行预测
EN

Stack Overflow用户
提问于 2019-02-07 10:48:15
回答 2查看 865关注 0票数 0

是否有可能仅基于x值来训练数据和预测?

在我的图表上,我的点(35,20)是黑色的。当该值预测为35时,应该返回0,但是像15这样的点-大多数数据点都在黑线之上-应该返回1

This is what my data looks like

代码语言:javascript
复制
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)

下面是我的线性回归模型:

代码语言:javascript
复制
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)
EN

Stack Overflow用户

发布于 2019-02-07 16:33:27

一个完整的例子

代码语言:javascript
复制
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)

请注意重塑

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54565585

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档