Problem in defining multidimensional array matrix and regression

ROGER GRAYDON CHRISTMAN dvl at psu.edu
Sun Nov 19 22:16:44 EST 2017


On Sun, 19 Nov 2017, shalu.ashu50 at gmail.com wrote: >
Hi, All,
>
>I have 6 variables in CSV file. One is rainfall (dependent, at
>y-axis) and others are predictors (at x). I want to do multiple
>regression and create a correlation matrix between rainfall (y) and
>predictors (x; n1=5). Thus I want to read rainfall as a separate
>variable and others in separate columns, so I can apply the algo. However, I am
>not able to make a proper matrix for them. 
>
>Here are my data and codes?
>Please suggest me for the same.
>I am new to Python.
>
>RF	P1	P2	P3	P4	P5
>120.235	0.234	-0.012	0.145	21.023	0.233
>200.14	0.512	-0.021	0.214	22.21	0.332
>185.362	0.147	-0.32	0.136	24.65	0.423
>201.895	0.002	-0.12	0.217	30.25	0.325
>165.235	0.256	0.001	0.22	31.245	0.552
>198.236	0.012	-0.362	0.215	32.25	0.333
>350.263	0.98	-0.85	0.321	38.412	0.411
>145.25	0.046	-0.36	0.147	39.256	0.872
>198.654	0.65	-0.45	0.224	40.235	0.652
>245.214	0.47	-0.325	0.311	26.356	0.632
>214.02	0.18	-0.012	0.242	22.01	0.745
>147.256	0.652	-0.785	0.311	18.256	0.924
>
>import numpy as np
>import statsmodels as sm
>import statsmodels.formula as smf
>import csv
>
>with open("pcp1.csv", "r") as csvfile:
>    readCSV=csv.reader(csvfile)
>    
>    rainfall = []
>    csvFileList = [] 
>    
>    for row in readCSV:
>        Rain = row[0]
>        rainfall.append(Rain)
>
>        if len (row) !=0:
>            csvFileList = csvFileList + [row]       
>        
>print(csvFileList)
>print(rainfall)
>
>Please suggest me guys
>Thanks
>


There seems to be a conceptual disconnect here.
Do you happen to know what the letters C,S,V
stand for in CSV file?   Because I don't see any C's
in your data, and I don't see anything in your code
to use anything other than C to S your V's.

I'm thinking that is the first place you should look.
You could either modify your data file (with a nice global replace/change)
or you could give a different value to one of the default parameters
to the functions you use to open the file.

Roger Christman
Pennsylvania State University





More information about the Python-list mailing list