0
 import graphlab as gl
 from graphlab import mxnet as mx

# Define the network symbol, equivalent to linear regression
 net = mx.symbol.Variable('data')
 net = mx.symbol.FullyConnected(data=net, name='fc1', num_hidden=1)
 net = mx.symbol.LinearRegressionOutput(data=net, name='lr')

# Load data into SFrame and normalize features
 sf = gl.SFrame.read_csv('https://static.turi.com/datasets/regression/houses.csv')
 features = ['tax', 'bedroom', 'bath', 'size', 'lot']
 for f in features:
    sf[f] = sf[f] - sf[f].mean()
    sf[f] = sf[f] / sf[f].std()

# Prepare the input iterator from SFrame
# `data_name` must match the first layer's name of the network.
# `label_name` must match the last layer's name plus "_label".
 dataiter = mx.io.SFrameIter(sf, data_field=features, label_field='price',
                        data_name='data', label_name='lr_label',
                        batch_size=1)

# Train the network
 model = mx.model.FeedForward.create(symbol=net, X=dataiter, num_epoch=20,
                                learning_rate=1e-2,
                                eval_metric='rmse')

# Make prediction
 model.predict(dataiter)

enter image description here

I have written few lines of code to predict a parameter in my dataset, but it only gives RMSE for train data as shown in picture. What would be a way around that it shows RMSE for test data? model.evaluate(dataiter) does not work, help needed

1 Answers1

0

mx.model has been superseded by mx.module, and ultimately the mx.gluon interface is preferred. When using mx.module you can specify your evaluation metric with eval_metric and evaluation data with eval_data (which should be a DataIter). And example would be similar to;

mod = mx.mod.Module(symbol=net,
                    context=mx.cpu(),
                    data_names=['data'],
                    label_names=['softmax_label'])

mod.fit(train_data=train_iter,
        eval_data=val_iter,
        eval_metric='rmse',
        num_epoch=10)

And this will give you the required metrics in the output;

INFO:root:Epoch[0] Train-RMSE=0.364625
INFO:root:Epoch[0] Time cost=0.388
INFO:root:Epoch[0] Validation-RMSE=0.557250
...
Thom Lane
  • 993
  • 9
  • 9