Can I plot the SVM decision boundary for 3 features(in 3D space) using Scikit learn? - plot

I am using scikit-learn to understand Support Vector Machines(SVM). I want to plot the decision boundary computed by SVM. The SVM uses 3 features. So the decision boundary must be drawn in 3D space. Is this possible using scikit-learn?
I could find only 2D plots of SVM decision boundary at the official website.
However I found links on stackoverflow which show this is possible using matlab and r. Is there a way in which I can achieve the same using scikit-learn?

You don't use scikit-learn to plot things in Python. You have to use another package, and if you check scikit-learn's examples, you will see they use matplotlib. You can create 3D plots with matplotlib, here is the tutorial. The usage is basically the same than in 2D, except you add an argument for the third dimension.
Another popular package you could use is mayavi, which was conceived especially for 3D plotting.

Related

Creating a 3D "ribbon" style plot in R

I want to plot the recorded path of an object such as a plane or drone in 3d space using R. The plotted path should be represented by a flat “ribbon” whose orientation perpendicular to the direction of travel changes to reflect the roll of the object. In other words, I want to be able to visualize the path and orientation of the object in one "ribbon" as it banks in turns.
As far as as I can tell, a traditional ribbon plot in R won't allow you to change the orientation in a third dimension.
Matlab and Python have functionality for creating quiver plots where arrows may be placed to indicate the xyz orientation of the object at a given point in time along the path. I cannot find any R packages with similar functionality.
I have played with Plot3D, Plotrgl, Plot3Drgl and cannot find a package that has this capability.
Q1: Are there any packages in R that would support this type of plot?
Q2: If there isn't, how can I go about creating this type of plot R?
Below are examples in Python and Matlab for the 3D quiver type plots, as well as an image demonstrating the ribbon concept I am imagining.
https://medium.com/analytics-vidhya/exploring-data-acquisition-and-trajectory-tracking-with-android-devices-and-python-9fdef38f25ee
Example of 3D quiver plot in python
https://github.com/xioTechnologies/Gait-Tracking-With-x-IMU
Example of 3D quiver plot in matlab
This is an example of what the "ribbon" would look like
Thanks for any help!

How can I convert a histogram (2D) into 2 pdf in zfit?

I am trying to do some 2d spectra fitting with the help of zfit.
The pdf I want to use comes from ROOT TH2D.
Is there any method to convert the input Th2D into a 2D pdf directly in zfit?
Thanks a lot!
Update
zfit supports now binned PDFs (see here) in the newest version (to be installed with pip install -U zfit --pre) and allows to load histograms. They should be a Histogram from hist if possible, using uproot you should be able to convert one to another.
An introductory tutorial to binned fits can be found here
Old answer
There is currently no direct way but there is Work In Progress to implement binned fitting.
In general, I would advise to use hist within Python, as it can be used directly with zfit in the future.
A way to implement this now is to use the hists density, create a custom PDF (such as here) in zfit and set zfit.run.set_graph_mode(False) and zfit.run.set_autograd_mode(False).

Predicting Pixel Intensity Based on Surrounding Pixels

I am trying to build a model that will try to predict the pixel intensity at a particular point based off of the surrounding pixel intensities. As of now, the only way that I can think of doing this is averaging out the points, but I really don't think this is the best option. Someone suggested I try to use auto-regressive models, ARIMA I think, but I am not very familiar with the program. Would this be an appropriate program to use for what I need, if not, does anyone have any other suggestions for what I could use to do this in R?
Have a look at the spatstat package: http://spatstat.github.io.
From the FAQ, it supports using pixel image as data.
You should then be able to run spatial autoregression using the spdep package https://cran.r-project.org/web/packages/spdep/index.html, in particular the lagsarlm function.

How to reproduce this graphical explanation (a scatter plot) of how covariance works?

I found this graphical intuitive explanation of covariance:
32 binormal points drawn from distributions with the given covariances, ordered from most negative (bluest) to most positive (reddest)
The whole material can be found at:
https://stats.stackexchange.com/questions/18058/how-would-you-explain-covariance-to-someone-who-understands-only-the-mean
I would like to recreate this sort of graphical illustration in R, but I'm not sufficiently familiar with R's plotting tools. I don't even know where to start in order to get those colored rectangles between each pair of data points, let alone make them semi-transparent.
I think this could make a very efficient teaching tool.
The cor.rect.plot function in the TeachingDemos package makes plots similar to what is shown. You can modify the code for the function to make the plot even more similar if you desire.

Is there an interactive output device to view 3D graphs in R?

I'm currently generating 3D graphs in R using the persp-command. To change the viewpoint one has to set the parameters theta and phi. To evaluate (a good viewpoint on) the graph, one has to try lots of combinations for these parameters.
I was wondering if one can define an interactive output device that allows to rotate the graph using the mouse. It would be also nice if this device gives the current values for theta and phi.
Is there such a device/package?
See the rgl package: http://cran.r-project.org/web/packages/rgl/index.html
It won't report the theta and phi values you need, IIRC (though see #Dieter's comment below for a solution to this), but you can use rgl.snapshot() or rgl.postscript() to grab the current display as a bitmap or vector image. The package has persp3d() which is very similar to persp().
See the package rggobi http://cran.r-project.org/web/packages/rggobi/index.html
For data visualisation in 3 or even more dimensions, try the package rggobi which makes use of the program ggobi. It is possible to manipulate the data using the mouse, "brush" data, identify points in the data all while visualizing in a number of dimensions.

Resources