Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created November 14, 2020 07:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save amankharwal/85f63d3fb7534d34119b2ef53be5905a to your computer and use it in GitHub Desktop.
Save amankharwal/85f63d3fb7534d34119b2ef53be5905a to your computer and use it in GitHub Desktop.
def prepare_data(df,forecast_col,forecast_out,test_size):
label = df[forecast_col].shift(-forecast_out) #creating new column called label with the last 5 rows are nan
X = np.array(df[[forecast_col]]) #creating the feature array
X = preprocessing.scale(X) #processing the feature array
X_lately = X[-forecast_out:] #creating the column i want to use later in the predicting method
X = X[:-forecast_out] # X that will contain the training and testing
label.dropna(inplace=True) #dropping na values
y = np.array(label) # assigning Y
X_train, X_test, Y_train, Y_test = train_test_split(X, y, test_size=test_size, random_state=0) #cross validation
response = [X_train,X_test , Y_train, Y_test , X_lately]
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment