Hobson Lane
Data Scientist and AI Hacker
$ pip install pug
>>> df = pug.data.weather.get_airport('Fresno, CA')
def build_neural_net(N_inp=7, N_hid=2):
nn = pb.structure.FeedForwardNetwork()
# layers
inlay = pb.structure.LinearLayer(N_inp, name='input')
nn.addInputModule(inlay)
outlay = pb.structure.LinearLayer(1, name='output')
nn.addOutputModule(outlay)
# connections
if N_hid:
hidlay = pb.structure.LinearLayer(N_hid, name='hidden')
nn.addModule(hidlay)
in_to_hid = pb.structure.FullConnection(inlay, hidlay)
hid_to_out = pb.structure.FullConnection(hidlay, outlay)
nn.addConnection(in_to_hid)
nn.addConnection(hid_to_out)
else:
in_to_out = pb.structure.FullConnection(inlay, outlay)
nn.addConnection(in_to_out)
nn.sortModules()
return nn
def pybrain_dataset_from_dataframe(df,
inputs=['Max Humidity', ' Mean Humidity', ' Min Humidity'],
outputs=['Max TemperatureF']):
N_inp = len(inputs)
N_out = len(outputs)
ds = pb.datasets.SupervisedDataSet(N_inp, N_out)
for sample in df[inputs + outputs].values:
ds.addSample(sample[:N_inp], sample[N_inp:])
return ds
By Hobson Lane