Giter VIP home page Giter VIP logo

Comments (3)

rasbt avatar rasbt commented on May 13, 2024

Hi, seth814,
hope we can figure on what's going on here in your case. I think the easiest way would be if you could upload your script (if you are okay with sharing it) so that I can take a look and inspect what's going on inside the plot_decision_regions function that may cause this behavior on your dataset.

One thing that I could think of may be non-supported input shapes of the numpy arrays "X" and "y" in plot_decision_regions(X, y, classifier, resolution=0.02). This decision region plotting functions expects these X and y in the shape that scikit-learn works with. E.g., the y-array has to be a 1D integer type array. And X has to be a 2D float (or integer) type array.

Would be nice if you could check your input data and let me know what the result of the "print" functions (see below) looks like -- that would be very helpful

Input:

import numpy as np

y = np.array([1, 2, 0, 0, 2])
X = np.array([[1., 2.],  
              [3., 4.],
              [5., 6.],
              [8., 9.],
              [7., 8.]])

print('y:', y.shape, y.dtype)
print('X:', X.shape, X.dtype)

Output:

y: (5,) int64
X: (5, 2) float64

Above is an example of how the expected shape may look like.

PS: I have a slightly more sophisticated function implemented here: http://rasbt.github.io/mlxtend/user_guide/evaluate/plot_decision_regions/

I am currently a bit busy (at SciPy 2016), but several people asked me about 3D decision spaces recently, which I am going to add soon!

from python-machine-learning-book.

seth814 avatar seth814 commented on May 13, 2024

No worries. I'm not in a huge hurry, but I am curious as to what is going on in the function.

I uploaded the data and file under Vertical Abduction in my repo. I tried to upload a zip but it said the format wasn't supported. The shapes and datatypes are both correct so it's probably something else.

from python-machine-learning-book.

rasbt avatar rasbt commented on May 13, 2024

About the FutureWarning, I think that's not an issue here; it comes from the fact that y_train is a Pandas DataFrame, not a NumPy array. I'd just recommend putting a y_train = y_train.values into your code.

Hm, about the plot itself, I don't think this is a bug. This is how the decision region of the SVM looks like in this case -- you may want to do some hyperparameter tuning here.
E.g., when I plot the first 2 dimensions of the input data, it kind of looks like this:

plt.scatter(X_train.values[:, 0], X_train.values[:, 1])

unknown

So, for a more visually pleasing analysis, you could maybe try a non-linear dimensionality reduction technique (e.g., Kernel SVM or other algorithms for manifold learning that are implemented in scikit-learn: http://scikit-learn.org/stable/modules/manifold.html)

from python-machine-learning-book.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.