Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h3>Your first segment of code defines a classifier on <code>1d</code> data.</h3> <p><code>X</code> represents the feature vectors.</p> <pre><code>[0] is the feature vector of the first data example [1] is the feature vector of the second data example .... [[0],[1],[2],[3]] is a list of all data examples, each example has only 1 feature. </code></pre> <p><code>y</code> represents the labels.</p> <p>Below graph shows the idea:</p> <p><img src="https://i.stack.imgur.com/umFVj.png" alt="enter image description here"></p> <ul> <li>Green nodes are data with label 0</li> <li>Red nodes are data with label 1 </li> <li>Grey nodes are data with unknown labels. </li> </ul> <pre> print(neigh.predict([[1.1]])) </pre> <p>This is asking the classifier to predict a label for <code>x=1.1</code>. </p> <pre><code> print(neigh.predict_proba([[0.9]])) </code></pre> <p>This is asking the classifier to give membership probability estimate for each label.</p> <p>Since both grey nodes located closer to the green, below outputs make sense.</p> <pre><code> [0] # green label [[ 0.66666667 0.33333333]] # green label has greater probability </code></pre> <h3>The second segment of code actually has good instructions on <code>scikit-learn</code>:</h3> <blockquote> <p>In the following example, we construct a NeighborsClassifier class from an array representing our data set and ask who’s the closest point to [1,1,1]</p> </blockquote> <pre> >>> samples = [[0., 0., 0.], [0., .5, 0.], [1., 1., .5]] >>> from sklearn.neighbors import NearestNeighbors >>> neigh = NearestNeighbors(n_neighbors=1) >>> neigh.fit(samples) NearestNeighbors(algorithm='auto', leaf_size=30, ...) >>> print(neigh.kneighbors([1., 1., 1.])) (array([[ 0.5]]), array([[2]]...)) </pre> <p>There is no target value here because this is only a <code>NearestNeighbors</code> class, it's not a classifier, hence no labels are needed. </p> <h3>For your own problem:</h3> <p>Since you need a classifier, you should resort to <code>KNeighborsClassifier</code> if you want to use <code>KNN</code> approach. You might want to construct your feature vector <code>X</code> and label <code>y</code> as below:</p> <pre><code>X = [ [h1, e1, s1], [h2, e2, s2], ... ] y = [label1, label2, ..., ] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload