コード例 #1
0
ファイル: run_pls.py プロジェクト: jackaranda/phasespace
slices = [slice(None)]*2
start_index = field.reversemap(time=startdate)[field.time_dim].start			
end_index = field.reversemap(time=enddate)[field.time_dim].start
slices[field.time_dim] = slice(start_index, end_index+1)
predictand_data = field.variables[0][slices]
print 'predictand_data.shape = ', predictand_data.shape

locations = predictands['sources'][predictands['sources'].keys()[0]]['fields']['tasmax'].features()
#print locations

#for location in locations['features']:
#	print location

locations = locations['features'][20:22]

pls = PLS_sklearn()
pls.fit(predictors, predictand_data, locations, startdate=startdate, enddate=enddate)
#pca.save('pca.nc')
#pca.load('pca.nc')
reduced_predictors = pls.transform(predictors, startdate=startdate, enddate=enddate)

#vmin = 0
#vmax = 50
#mappable = ScalarMappable(cmap='Blues')
#mappable.set_array(np.arange(vmin,vmax,0.1))
#mappable.set_clim((vmin,vmax))

id = 20
for pred in reduced_predictors:

	tree = BinaryTree(pred, maxdepth=10)
コード例 #2
0
predictands = functions.open(config['predictands'])
path, config = predictands['sources'].items()[0]
field = config['fields']['pr']
slices = [slice(None)]*2
start_index = field.reversemap(time=startdate)[field.time_dim].start			
end_index = field.reversemap(time=enddate)[field.time_dim].start
slices[field.time_dim] = slice(start_index, end_index+1)
predictand_data = field.variables[0][slices]
print 'predictand_data.shape = ', predictand_data.shape

locations = predictands['sources'][predictands['sources'].keys()[0]]['fields']['pr'].features()

locations = locations['features'][20:22]

if method == 'pls':
	pls = PLS_sklearn()
	pls.fit(predictors, predictand_data, locations, log=True, startdate=startdate, enddate=enddate)
	reduced_predictors = pls.transform(predictors, startdate=startdate, enddate=enddate)
	reduced_predictors_subset1 = pls.transform(predictors, startdate=startdate, enddate=enddate, months=[6,7,8])
	reduced_predictors_subset2 = pls.transform(predictors, startdate=startdate, enddate=enddate, months=[12,1,2])

if method == 'pca':
	pca = PCA_sklearn()
	pca.fit(predictors, locations, startdate=startdate, enddate=enddate)
	reduced_predictors = pca.transform(predictors, startdate=startdate, enddate=enddate)
	reduced_predictors_subset1 = pca.transform(predictors, startdate=startdate, enddate=enddate, months=[6,7,8])
	reduced_predictors_subset2 = pca.transform(predictors, startdate=startdate, enddate=enddate, months=[12,1,2])



id = 20