Ad

Automating This Function With A Loop Taking Multiple Inputs - Python 3.7

- 1 answer

I have written a function that predicts stock data using ESM. It takes two inputs, one being a column name, and the other being the training ratio. Now, I have set it up to take these as user inputs, and so I have to manually type them in everytime I run it. There are 4 columns, and each column (stock) needs to be run at training ratios of 0.6, 0.7, 0.8 and 0.9. So, I will need a loop that starts off by taking the first column, then takes the 4 ratios for this one by one and then moves to the next column. Any help with this will be appreciated.

I tried googling it, but could not find anything specific. Trust me guys, I tried. Sorry, Im an absolute noob at this. Please see below part of the code that's relevant to the problem.

def esm():
    data  = input('Please Enter Stock Name: ')
    ratio = float(input('Please enter split: '))

    X = series[data].values
    size = int(len(X) * ratio)
Ad

Answer

is it what you want? You can make your esm function can take two parameters and you can reuse this function in loop.

def esm(data, ratio):
    X = series[data].values
    size = int(len(X) * ratio)


for data in ["col1", "col2", "col3", "col4"]:
    for ratio in [0.6, 0.7, 0.8, 0.9]:
        esm(data, ratio)
        # do something
Ad
source: stackoverflow.com
Ad