Skip to content

Instantly share code, notes, and snippets.

View Tathagatd96's full-sized avatar

Tathagat Dasgupta Tathagatd96

View GitHub Profile
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)
#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)
#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)
#Training the model
model.train(input_fn=input_func,steps=1000)
#Evaluating the model
train_metrics=model.evaluate(input_fn=input_func,steps=1000)
#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"])
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):
ts_data=TimeSeriesData(250,0,10)
plt.plot(ts_data.x_data,ts_data.y_true)
plt.show()
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()
plt.plot(ts_data.x_data,ts_data.y_true)
plt.plot(ts.flatten()[1:],y1.flatten(),"g*")
plt.show()