コード例 #1
0
    def compile_pain_decoder(self, pain_dir=None):
        print("compiling pain dir")

        if os.path.isfile(self.decoder_file):
            print("pain data pre-saved, loading...")
            stats = pickle.load(open(self.decoder_file, "rb"))

            # pdata = Brain_Data(self.decoder_file)
        else:
            print("pain data doesn't exist, getting...")
            if (pain_dir is None):
                pdata = fetch_pain()
            else:
                pdata = fetch_pain(pain_dir)
            pdata.Y = pdata.X["PainLevel"]
            stats = pdata.predict(algorithm='ridge', plot=False)
            with open(self.decoder_file, "wb") as f:
                pickle.dump(stats, f, pickle.HIGHEST_PROTOCOL)
        self.decoder_origin = 'chang_pain_data'

        print("pain data loaded.")

        #train_subjs=pandas.DataFrame(data_subjs).sample(frac=0.9,random_state=2057)
        #test_subjs= [s for s in data_subjs if s not in train_subjs[0]]

        #data_train = pdata[train_subjs[0]]
        #data_test = pdata[test_subjs]
        #stats = data_train.predict(algorithm='ridge',plot=False)

        self.stats = stats
        self.decoder = stats['weight_map']
コード例 #2
0
cross-validation parameters. Currently, we have several different linear algorithms
implemented from `scikit-learn <http://scikit-learn.org/stable/>`_.

"""

#########################################################################
# Load Data
# ---------
#
# First, let's load the pain data for this example.  We need to specify the
# training levels.  We will grab the pain intensity variable from the data.X
# field.

from nltools.datasets import fetch_pain

data = fetch_pain()
data.Y = data.X['PainLevel']

#########################################################################
# Prediction with Cross-Validation
# --------------------------------
#
# We can now predict the output variable is a dictionary of the most
# useful output from the prediction analyses. The predict function runs
# the prediction multiple times. One of the iterations uses all of the
# data to calculate the 'weight_map'. The other iterations are to estimate
# the cross-validated predictive accuracy.

stats = data.predict(algorithm='ridge',
                     cv_dict={
                         'type': 'kfolds',