Piece-wise regression by clustering I was wondering about the possibilities of clustering numerical data (more than 3 dimensions) into different clusters and doing curve fitting on each cluster to get much higher accuracy than using a single model. 

Since linear regression is preferred, is there any way to cluster the data points based on their linear fitting?

This is because I need a result matching the input data and do not care about unseen data. I cannot hard code the data and use a lookup mechanism. Instead an approximate math function would be preferable.

Is there an existing implementation ? (Preferably in Python)
If you use these 2 packages:

http://scikit-learn.org/stable/modules/generated/sklearn.cluster.KMeans.html

https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html

you will get what you want :)