Python中的多项式回归

时间:2015-02-09 19:06:31

标签: python machine-learning regression linear-regression

我使用Python编码线性回归模型,但我无法将其扩展为多项式模型。是一个f * n矩阵,其中f是特征的数量,n是训练数据集的数量,我们需要多样性的顺序直到4。 `

def rec(it,r,arr,index,ind,num):
    if index == r:

        arr=numpy.append(arr,num)

        return arr

    if ind > 3:

        return arr

    num=num*it[ind]

    #arr[index]=it[ind]

    arr=rec(it,r,arr,   index+1,ind,num   );

    arr=rec(it,r,arr,   index,ind+1,num/it[ind]   );

    return arr  



# Polynomial start from here .
     for i in range(1,5): 
        for j in range(0,n):
                   arr=numpy.array([]) # it is a f*n matrix where f is the number of features and n is the number of training sets of data , and we need polymial order till 4 , 
                   arr=rec(it[j],i,arr,0,0,1)# Suppose there are 4 feature x1,x2,x3,x4 then it will consist of x1x2,x2x3,x1*x1,,,, x1x2x3x4
                   it[j]=append(it[j],arr)
                   if i==1:
                        b=numpy.array([1])
                        it[j]=append(it[j],b)
        `

0 个答案:

没有答案