This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scaler_model = MinMaxScaler() | |
scaler_model.fit(X_train) | |
X_train=pd.DataFrame(scaler_model.transform(X_train),columns=X_train.columns,index=X_train.index) | |
scaler_model.fit(X_eval) | |
X_eval=pd.DataFrame(scaler_model.transform(X_eval),columns=X_eval.columns,index=X_eval.index) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Creating Feature Columns | |
feat_cols=[] | |
for cols in df.columns[:-1]: | |
column=tf.feature_column.numeric_column(cols) | |
feat_cols.append(column) | |
print(feat_cols) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#The estimator model | |
model=tf.estimator.DNNRegressor(hidden_units=[6,10,6],feature_columns=feat_cols) | |
#the input function | |
input_func=tf.estimator.inputs.pandas_input_fn(X_train,y_train,batch_size=10,num_epochs=1000,shuffle=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Training the model | |
model.train(input_fn=input_func,steps=1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Evaluating the model | |
train_metrics=model.evaluate(input_fn=input_func,steps=1000) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Now to predict values we do the following | |
pred_input_func=tf.estimator.inputs.pandas_input_fn(x=X_eval,y=y_eval,batch_size=10,num_epochs=1,shuffle=False) | |
preds=model.predict(input_fn=pred_input_func) | |
predictions=list(preds) | |
final_pred=[] | |
for pred in predictions: | |
final_pred.append(pred["predictions"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeSeriesData(): | |
def __init__(self,num_points,xmin,xmax): | |
self.xmin=xmin | |
self.xmax=xmax | |
self.num_points=num_points | |
self.resolution=(xmax-xmin)/num_points | |
self.x_data=np.linspace(xmin,xmax,num_points) | |
self.y_true=np.sin(self.x_data) | |
def ret_true(self,x_series): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ts_data=TimeSeriesData(250,0,10) | |
plt.plot(ts_data.x_data,ts_data.y_true) | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num_time_steps=30 | |
y1,y2,ts= ts_data.next_batch(1,num_time_steps,True) | |
print(ts.flatten().shape) | |
plt.plot(ts.flatten()[1:],y1.flatten(),"*") | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plt.plot(ts_data.x_data,ts_data.y_true) | |
plt.plot(ts.flatten()[1:],y1.flatten(),"g*") | |
plt.show() |