def interpolate(self, timeseries, **args):
        cs = 'corrected_score'
        sp = 'speed'
        date = 'date'
        fields = ['corrected_score', 'speed']

        timestep = args['timestep']
        neighbor_series = args['neighbor_series']
        reg = args['reg']

        # override missing on neighbors
        lnseries = len(neighbor_series)
        # if neighbor missing raise exception
        for nseries in neighbor_series:
            misses = MissingDataFinder().find(nseries, timestep)
            if(len(misses) > 0):
                return self.multi_interpolate(timeseries, args)

        ovtimeseries = OverrideMissing().override(timeseries, timestep, -1)

        for field in fields:
            X, Y = [], []

            for t in xrange(len(neighbor_series[0])):
                if(ovtimeseries[t][field] != -1):
                    Y.append(ovtimeseries[t][field])
                    pattern = []
                    for nseries in neighbor_series:
                        pattern.append(nseries[t][field])
                    X.append(pattern)

            Xa, Ya = array(X), array(Y)

            if(reg == 'knn'):
                regargs = args['regargs']
                variant = regargs['variant']

                if('kfold' in regargs.keys()):
                    kfold = regargs['kfold']
                    ncandidates = regargs['n']

                    regressors = {}
                    best_n = ncandidates[0]
                    regressor = KNeighborsRegressor(best_n, variant)
                    regressors[best_n] = regressor
                    best_score = cross_val_score(regressor, Xa, Ya, cv=kfold).mean()

                    for n in ncandidates[1:]: # try every n and use cross validation
                        regressor = KNeighborsRegressor(n, variant)
                        regressors[n] = regressor
                        score = cross_val_score(regressor, Xa, Ya, cv=kfold).mean()
                        if(score > best_score):
                            best_n = n
                            best_score = score
                    regressor = regressors[best_n]
                else:
                    neighbors = regargs['n']
                    regressor = KNeighborsRegressor(neighbors, variant)

            elif(reg == 'linear_model'):
                regressor = linear_model.LinearRegression()
            elif(reg == 'svr'):
                regargs = args['regargs']

                if(regargs['cv_method'] == 'kfold'):
                    fold = regargs['cv_args']['k_folds']
                    pattern_count = Xa.shape[0]
                    cv_method = KFold(pattern_count, fold)
                else:
                    raise Exception("not implemented")

                # search for the best parameters with crossvalidation.
                kernel, epsilon, tuned_parameters =\
                    regargs['kernel'], regargs['epsilon'], regargs['tuned_parameters']
                grid = GridSearchCV(SVR(kernel = kernel, epsilon = epsilon),\
                    param_grid = tuned_parameters, cv=cv_method, verbose = 0)

                grid.fit(Xa, Ya)

                # train a SVR regressor with best found parameters.
                regressor = SVR(kernel=kernel, epsilon=0.1, C = grid.best_params_['C'],\
                    gamma = grid.best_params_['gamma'])

                # if regressor hook function specified, call hook
                if('reghook' in args.keys()):
                    args['reghook'](regressor)
            else:
                raise Exception("No regressor selected.")

            regressor.fit(Xa,Ya)

            for t in xrange(len(ovtimeseries)):
                if(ovtimeseries[t][field] == -1):
                    pattern = []
                    for nseries in neighbor_series:
                        pattern.append(nseries[t][field])
                    y_hat = regressor.predict(array(pattern))
                    if(len(y_hat.shape) > 0):
                        ovtimeseries[t][field] = y_hat[0]
                    else:
                        ovtimeseries[t][field] = y_hat

        return ovtimeseries
dataset/ETHPy150Open cigroup-ol/windml/windml/preprocessing/mreg_interpolation.py/MRegInterpolation.interpolate/original