Linear regression NN in Theano using List

I am quite new to Theano, while having used Neural Networks in MATLAB before.

I have succeeded with reading all my data from my excel files, and create the input and output lists.

To separate each group, both in input and output, I have created a list that contains lists :

input = [[1 , 2 , 2 ], [5 , 5 ,2], [7 ,8 ,8], [7 ,1 ,1]]

The same goes for output.

So my Input[i] correlates the output[i].

If I create an array, would I lose this correlation? Should I convert my input output to array first and definitely?

Additionally, could a matrix be used instead of array in input and target definition in Theano?

This is also the code I used : list-1 is input and list-2 , output When I tried to convert my data directly from their format I got this error :

Wrong number of dimensions: expected 1, got 2 with shape (29, 9).

import theano
import numpy
import theano.tensor as T
import matplotlib.pyplot as plt
rng = numpy.random

#Training Data
X = numpy.asarray(list-1)
Y = numpy.asarray(list-2)

m_value = rng.randn()
c_value = rng.randn()
m = theano.shared(m_value,name ='m')
c = theano.shared(c_value,name ='c')

x = T.vector('x')
y = T.vector('y')
num_samples = X.shape[0]

prediction = T.dot(x,m)+c
cost = T.sum(T.pow(prediction-y,2))/(2*num_samples)

gradm = T.grad(cost,m)
gradc = T.grad(cost,c)

learning_rate = 0.01
training_steps = 10000

train = theano.function([x,y],cost,updates = [(m,m-learning_rate*gradm),(c,c-learning_rate*gradc)])
test = theano.function([x],prediction)

for i in range(training_steps):
    costM = train(X,Y)
    print(costM)


print("Slope :")
print(m.get_value())
print("Intercept :")
print(c.get_value())

a = linspace(0,10,10)
b = test(a)
plt.plot(X,Y,'ro')
plt.plot(a,b)

Just as an update I used another code here and I got this error which is more or less the same but the expectance is the contrary :

Wrong number of dimensions: expected 2, got 1 with shape (6,).

Topic theano neural-network

Category Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.