machine learning model forecast and behavior of independent variables

I am trying to forecast a regression to time=20. I have to predict the variable called target and the behavior of the remaining independent variables with respect to time has been determined through the function called 'get_function'. The following code works as it should, however, I would like to ask if there is a way to change this line new_data=[[i,eq_x[i],eq_y[i]]] without explicitly writing eq_x eq_y etc... for every single independent variable ?

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
import xgboost as xgb
import datetime
import seaborn as sns
from sklearn.metrics import r2_score

data=[[1, 1,2 ,5],
        [2, 5,5,6],
        [3, 4,6,6]
        ,[5, 6,5,6],
        [8, 7,9,4]
        ,[9, 2,3,8],
        [2, 5,1,9],
        ,[3, 8,2,8],
        [6, 5,4,10],
        [6, 8,5 ,10]]

df = pd.DataFrame(data, columns=['time','x','y','target'])


#df.insert(0, "time", list(range(8)))
y = (
X=df.drop(['target'], axis = 1)
x_reg=xgb.XGBRegressor( n_estimators= 1000, max_depth=7, eta= 0.1, colsample_bytree= 0.8, subsample= 0.6),y)

def get_equation(x,y):
    degree = 2
    coefs, res, _, _, _ = np.polyfit(x,y,degree, full = True)
    ffit = np.poly1d(coefs)
    print (ffit)
    return ffit

for i in range(20):
        new_df=pd.DataFrame(new_data, columns=X.columns)

Read more here:

Content Attribution

This content was originally published by etckml at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: