Python Forum
Newbie question: how to generate dataframe and use multiple regression - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Newbie question: how to generate dataframe and use multiple regression (/thread-6846.html)



Newbie question: how to generate dataframe and use multiple regression - zydjohn - Dec-10-2017

Hello:
I have some code, which is not finished yet:
from scipy.stats import linregress

x0 = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
y = [2,3,4,5,6,7,8,9,10,11]

def genList1(x, n, offset):
    list1 = []
    if (n + offset) <= len(x):
       list1 = x[offset:(offset + n)]
    return(list1)

x1 = genList1(x0, 10, 5)
x2 = genList1(x0, 10, 4)
x3 = genList1(x0, 10, 3)
x4 = genList1(x0, 10, 2)
x5 = genList1(x0, 10, 1)
I have one original list X0 with 15 items, and another list y with 10 items.
I would like to generate other 5 lists with 10 items each, the way how to generate each list is in function: genList1.
Now, I want to know how I can use the 6 lists to generate a dataframe or whatever is required to do
Multiple Regression using Statsmodels or whatever python packages.
The corresponding R linear model expression is:
fit <- lm(y ~ x1 + x2 + x3 + x4 + x5, data=dataframe1)
And I want to print coefficients for each variable (x1, x2, x3, x4, x5)
How I can do this in python?
Thanks,