1

I am still quite new to code and I am hoping this is a quick fix. So far I have been able to use linear regression to find the x centroid and y centroid position of 5 sided shapes separately. As found out, the x and y centroids vary with each other so I need to use some form of linear regression to use both x and y in the same regression algorithm.

I have 2 shapes (more shapes will be used when algorithm is running) that have x and y coordinates. These are given in 'a' below. Values from 'b' are the centroid positions of these shapes.

#a = [[[ax1,ay1],[ax2,ay2],[ax3,ay3],[ax4,ay4],[ax5,ay5]],[[bx1,by1],[bx2,by2],[bx3,by3],[bx4,by4],[bx5,by5]]]
a = [[[6,4],[0,5],[0,4],[4,-5],[7,-3]],[[7,5],[1,6],[1,5],[5,-4],[8,-2]]]

#b = [[a_cx,a_cy],[b_cx,b_cy]]
b = [[3.88,0.59],[4.88,1.59]]

LR = LinearRegression()
LR.fit(a,b)
new_shape = [[[9,12],[2,8],[1,4],[16,2],[14,8]]]
centroid = LR.predict(new_shape)
print("results = ",centroid)

I get the error:

'ValueError: Found array with dim 3. Estimator expected <= 2.'

I am unsure how to get passed this error and would appreciate any help or tips!

JKerr
  • 11
  • 1
  • 3
    You shouldn't be using linear regression for this. In linear regression, you determine a linear relationship. So for each set of features x, you predict a y, where y=f(x) and f is a linear function. In your example, you have many points for one prediction y. Moreover, you don't need to predict a centroid if you know all the points, you can simply calculate it. see as an example [here](https://stackoverflow.com/questions/23020659/fastest-way-to-calculate-the-centroid-of-a-set-of-coordinate-tuples-in-python-wi) – Zoe Dec 18 '18 at 15:07
  • Hi @Zoe - thanks for the response. I am trying to use a form of 'machine learning' to calculate the centroid as my project will move further forward with the concept of identifying different points etc so I don't want to keep it with the calculation alone. Is multivariate linear regression any use? I cannot find much info online about how to use it for numbers – JKerr Dec 18 '18 at 15:15

0 Answers0