1
votes

I have a problem trying to figure out how to plot my predicted values against expected values. But i keep on getting this error:

AttributeError: 'numpy.ndarray' object has no attribute 'inverse_transform'

Below are my python Theano Backend for my Machine Learning purposes:

url = 'mydata.csv'
df = pd.read_csv(url)

y = df.loc[0:250, 'Y']
y = np.array(y)
X = df.loc[0:250, ['A','B','C', 'D', 'E']]
X = np.array(X)

X_train, X_test, y_train, y_test = cross_validation.train_test_split(X, y, 
test_size=-.10, random_state=3)

model = Sequential()
model.add(Dense(128, input_dim=5, activation='tanh'))
model.add(Dropout(0.2))
model.add(Activation("tanh"))
model.add(Dense(64, activation='tanh'))
model.add(Activation("tanh"))
model.add(Dense(32, activation='tanh'))
# Output layer
model.add(Dense(1))

model.compile(loss='mse', optimizer='SGD',metrics=["accuracy"])

# Training model with train data. Fixed random seed
np.random.seed(7)
model.fit(X_train, y_train, nb_epoch=100, batch_size=10, verbose=1) 

# Evaluation
scores = model.evaluate(X, y)
print("%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))

pyplot.plot(y.inverse_transform(predicted), color="blue")
pyplot.plot(y.inverse_transform(y_test), color="green")
pyplot.show()#

No idea how to solve this. I'm a newbie anyway.

1
Well the error message is quite clear. You have a numpy array and try to call a member function that does not exist. What is the function inverse_transform supposed to do? - Thomas Kühn

1 Answers

0
votes

Suppose if we have done the encoding of y like

encoded_y = scaler.fit_transform(original_dataset)

then, the decoding of y (to bring it back to its original state) should be done like

y = scaler.inverse_transform(original_dataset)

This will ensure that y is decoded again with the same parameters with which it was encoded before.

In your code, I am not able to locate where the initial encoding / Transformation is done, but I hope the idea is clear.