def __init__(self,argv):
        
        try:
            opts, args = getopt.getopt(argv,"hn:d:t:",["net=","descs=","trn="])
        except getopt.GetoptError:
            print 'predict.py -n [Networks] -d [Descs] -t [TrnData]'
            sys.exit(2)
        
#         if len(args) == 0:
#             print 'Please provide networks, descriptors and training data, use -h for help'
#             sys.exit(2)
            
        for opt, arg in opts:
            if opt == '-h':
                print 'predict.py -n <network> -s <SMILEs>'
                sys.exit()
            elif opt in ("-n", "--net"):
                self.networks = arg
            elif opt in ("-d", "--descs"):
                self.descs = self._readDescs(arg)
            elif opt in ("-t", "--trn"):
                self.trn = self._readTrn(arg)
            else:
                print "Wrong arguments, use -h for helps."
        
        try:
            self.aPredictor = ann.predicting(network_name=self.networks,
                                predict_descs=self.descs,
                                training_descs=self.trn,
                                featureNorm=True)
        except AttributeError:
            print 'Worng input files, please provide networks, descriptors and training data, use -h for help'
            sys.exit(2)
Beispiel #2
0
                   xlab='acidification Reported Value', 
                   ylab='Estimated Value', 
                   title='')

# calculate median relative error

theError = aTrainer.calc_Diff(real_tst, prediction_tst)


#save network to xml file
raw_input('Save the network?')
aTrainer.save_network('testNetwork.xml')

raw_input('Going to the part of using exsisting network to do prediction, press anykey to continue')

# here set up the predictor class, must load your original X value for corresponding network to do feature Normalization
aPredictor = ann.predicting(network_name='testNetwork.xml',
                            predict_descs=X,
                            training_descs=X,
                            featureNorm=True)
# do feature normalization
normedDescs = aPredictor.featureNorm(aPredictor.descsForPred, aPredictor.X_scalar)

# prediction here
prediction_results = aPredictor.predict(aPredictor.network, normedDescs)
# still, transform back 
prediction_results = np.exp(prediction_results)
raw_input('Going to save the prediction results')
np.savetxt('prediction_results.csv',prediction_results,delimiter=',')

import regression as ann

# import classifier
import numpy as np

X = np.loadtxt("./data/trn_data_32.csv", skiprows=1, delimiter=",")
y = np.loadtxt("./data/CED_Y_171.csv", skiprows=1, delimiter=",")
tst_idx = np.loadtxt("./net_Feb16/CED_testIndex.txt", delimiter=",")
tst_idx = tst_idx.astype(np.int64)
net = "./net_Feb16/CED.xml"

trn_X = np.delete(X, tst_idx, 0)
tst_X = X[tst_idx, :]
real_test = y[tst_idx]

aPredictor = ann.predicting(network_name=net, predict_descs=X, training_descs=trn_X, featureNorm=True)
# prediction here
prediction_results = aPredictor.predict(aPredictor.network, aPredictor.normed_descsForPred)
prediction_results = np.exp(prediction_results)

real_all = y
prediction_all = prediction_results
# plot the prediction error on all data
aPredictor.plot_diff2(real_all, prediction_all, xlab="CED Reported Value", ylab="Estimated Value", title="")

# predict on the test data
aPredictor2 = ann.predicting(network_name=net, predict_descs=tst_X, training_descs=trn_X, featureNorm=True)

prediction_test = aPredictor2.predict(aPredictor2.network, aPredictor2.normed_descsForPred)
prediction_test = np.exp(prediction_test)
aPredictor2.plot_diff2(real_test, prediction_test, xlab="CED Reported Value", ylab="Estimated Value", title="")