I've a file setup with each line looking like this:
y x1 x2 x3 x4 x5 x6 name
I'm trying to find a function that fits x(1-6) to y.
I found this scipy method of doing so (I believe, although it could be single-variable only), but I'm not sure how the syntax is supposed to be/how to set it up for my situation.
I'm using this method of reading my file into a numpy array (Python 3.5):
data = np.loadtxt(fh,usecols=(0,1,2,3,4,5,6))
Any help with manipulating this method would be greatly appreciated, or if you know of a different way to solve this problem that would be great too - it doesn't have to be python.
I have seen this question whose answer helps with single variable fitting, and this question, which sounds similar but has little discussion with it.
I did have this test function below, but I'm not a big fan of the results I got - they're just not very accurate (I varied the increments, I doubt the data is linear but I don't know how to manually make a script to fit other data styles), and the script is slow.
result_list = []
num_add = 1
#Read in file of data
file_l = []
for x in fh:
    file_l.append(x)
#Check iterations for fit
for it1 in [x * 0.01 for x in range(-100, 100)]:
    for it2 in [x * 0.01 for x in range(-100, 100)]:
        for it3 in [x * 0.01 for x in range(-100, 100)]:
            for it4 in [x * 0.01 for x in range(-100, 100)]:
                for it5 in [x * 0.01 for x in range(-100, 100)]:
                    for it6 in [x * 0.01 for x in range(-100, 100)]:
                        diff = 0
                        for x in file_l:
                            x  = x.split()
                            hlg = float(x[0])
                            ti1 = int(x[1])
                            ti2 = int(x[2])
                            ti3 = int(x[3])
                            ti4 = int(x[4])
                            ti5 = int(x[5])
                            ti6 = int(x[6])
                            name = x[7]
                            calc_result =  it1*ti1 + it2*ti2 + it3*ti3 + it4*ti4 + it5*ti5 + it6*ti6
                            diff = diff + abs(hlg - calc_result)
                            num_add = num_add + 1
                        diff_per_add = diff / num_add
                        app_l = [diff_per_add,it4,it5,it6]
                        result_list.append(app_l)
                        print(it1,it2,it3,it4,it5,it6,diff,name)
#Deternmine the vars that gave closest fit
minv = 999999999999999999
min_l = []
for lists in result_list:
    val = float(lists[0])
    if val < minv:
        min_l = lists
        minv = val
print(min_l)
 
    