I want to detect lines within Scatter Plots, using python.
Specifically, my data set is of the Cartesian coordinates of points. (This data was gathered using four ultrasound sensors on servos).
Here are some data sets ,
And here are the lines I'd like to detect.
the problem is to write a python program that returns the start and endpoints of high certainty lines, given a list of points on the scatter plot.
The difficulty is that piecewise linear regression can't be applied directly since data is vertically stacked.
Is there a well known solution to this problem? Or maybe an ingenuous application of piecewise linear regression could work?
I'd really appreciate some functioning python code!
Related
I am trying to plot the pdf of a dataset in a way that the pdf appears as a smooth curve.
For that, I was using seaborn.kdeplot. The problem with this is - the dataset has a strict range, and the KDE plot tends to cross the range at both edges. To limit the pdf curve within the range I tried to use the clip parameter, but it makes the edges abrupt, not a smooth starting and ending. The abrupt changes at the ends do not look good visually, therefore, I am looking for other ways to plot the pdf.
Could you please provide some insights on this issue? Is there any other way that I can plot the pdf?
As an example, pls find the following code:
data = np.random.uniform(0,1,100)
sns.kdeplot(data)
sns.kdeplot(data, clip=(0, 1))
I have GPS coordinations in a csv file that I predict it using a regression model, just two columns with longitudes and latitudes that represent a race track. Now I want to plot it on Google maps to see how it looks like.
When I do that, I noticed that the curve is not smooth which make sense since I predicted those value with my regression model and they are not taking directly from a GPS.
I made a search on how to solve this problem and I find out that usually a spline interpolation is used for this, but I have no idea how to use it. All the examples that I found in the internet assume that we have the x which are the data and y which is the function, in my case there is no function, I just give the data to the model and it predict those values that's it. so if I have longitudes and latitudes, is it possible to make some sort of interpolation so that the curve would look smooth if I plot it?
Example:
let's say those are my data
latitudes = array([58.846563, 58.846573, 58.846586, 58.846601, 58.846618, 58.846637,
58.846658, 58.846681, 58.846705, 58.846731])
longitudes = array([9.903741, 9.903733, 9.903724, 9.903713, 9.9037 , 9.903686,
9.90367 , 9.903652, 9.903633, 9.903612])
and when I plot this data it give me some sort of a plot where each point is connected to the other point with a straight line but what I want is to smooth it up. Is this possible to do only if I have longitudes and latitudes as variables and nothing more? I'd appreciate any help
I have the following edge-detected image:
edge
As you can see, there are two clearly defined lines that make up two sides of an object. I can fit one curve to the entire thing, but how can I perform a curve fitting so that two curves are fit exclusively and simultaneously to such edges, so that I end up with two lines that describe the shape? In other images, the ends may not be discontinuous in this manner.
Is there a good way to specify number of curves to fit to data, like n=2 in this instance, and have it perform a fit where each curve takes into account the other to stay away from it? I have been unable to find similar problems or libraries that can perform something like this.
The two fitted curves in this instance would end up looking like this: curves
I started learning Linear Regression and I was solving this problem. When i draw scatter plot between independent variable and dependent variable, i get vertical lines. I have 0.5M sample data. X-axis data is given within range of let say 0-20. In this case I am getting multiple target value for same x-axis point hence it draws vertical line.
My question is, Is there any way i can transform the data in such a way that it doesn't perform vertical line and i can get my model working. There are 5-6 such independent variable that draw the same pattern.
Thanks in advance.
Instead of fitting y as a function of x, in this case you should fit x as a function of y.
I'm working with some instrument data that has records the temperature at a specific latitude, longitude, and pressure (height) coordinate. I need to create a 3d grid from this instrument data that I can then use to take a vertical cross sections of the interpolated gridded data. I've looked at pretty much every interpolation function/library I can find and I'm still having trouble just wrapping my head around how to do this.
I'd prefer not to use Mayavi, since it seems to bug out on my school's server and I'd rather not try to deal with fixing it right now.
The data is currently in 4 separate 1d arrays and I used those to mock up some scatter plots of what I'm trying to get.
Here is the structure of my instrument data points:
And here is what I'm trying to create:
Ultimately, I'd like to create some kind of 3d contour from these points that I can take slices of. Each of the plotted points has a corresponding temperature attached to it, which is really what I think is throwing me off in terms of dimensions and whatnot.
There are a few options to go from the unstructured data which you have to a structured dataset.
The simplest option might be to use the scipy interpolate.griddata method which can interpolate unstructured points using, linear or cubic interpolation.
Another option is to define your grid and then average all of the unstructured points which fall into each grid cell, giving you some gridded representation of the data. You could use a tool such as CIS to do this easily (full disclosure, I wrote this package to do exactly this kind of thing).
Or, there are more complicated methods of interpolating the data by trying to determine the most likely value of the grid points based on the unstructured data, for example using kriging with the pyKriging package, though I've never used this.