I am having great trouble generating the decision boundary for the results of an SVM classification.
Using the following chunk of code:
contmap = go.Contour(z = pred_grid, showlegend = True,
name = "Prediction",
text =np.asarray(list(map(lambda x: "Accepted" if x == 1 else "Rejected",
pred_grid.flatten()))).reshape(x0m.shape),
hoverinfo = "name+x+y+text" ,
ncontours = 5,
line = dict(smoothing=1.3, width = 2),
contours = dict(coloring="lines"),
showscale = False)
plotly.offline.iplot({
"data": [contmap],
"layout" : go.Layout(title = "Test",
xaxis = dict(title="X1"),
yaxis = dict(title="X2"))
})
I am able to see a decision boundary line that looks like this:
However, when I add in the arguments for
x
and y
into go.Contour
, with this code, the decision boundary just disappears:
contmap = go.Contour(z = pred_grid, x=x0m, y=x1m, showlegend = True,
name = "Prediction",
text =np.asarray(list(map(lambda x: "Accepted" if x == 1 else "Rejected",
pred_grid.flatten()))).reshape(x0m.shape),
hoverinfo = "name+x+y+text" ,
ncontours = 5,
line = dict(smoothing=1.3, width = 2),
contours = dict(coloring="lines"),
showscale = False)
plotly.offline.iplot({
"data": [contmap],
"layout" : go.Layout(title = "Test",
xaxis = dict(title="X1"),
yaxis = dict(title="X2"))
})
that code gives just a blank plot:
To clarify what values the variables are, they are:
pred_grid
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1],
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 1, 1, 1, 1, 1]], dtype=uint8)
x1m
array([[ 1.6177 , 1.6177 , 1.6177 , 1.6177 , 1.6177 ,
1.6177 , 1.6177 , 1.6177 , 1.6177 , 1.6177 ],
[ 1.95086667, 1.95086667, 1.95086667, 1.95086667, 1.95086667,
1.95086667, 1.95086667, 1.95086667, 1.95086667, 1.95086667],
[ 2.28403333, 2.28403333, 2.28403333, 2.28403333, 2.28403333,
2.28403333, 2.28403333, 2.28403333, 2.28403333, 2.28403333],
[ 2.6172 , 2.6172 , 2.6172 , 2.6172 , 2.6172 ,
2.6172 , 2.6172 , 2.6172 , 2.6172 , 2.6172 ],
[ 2.95036667, 2.95036667, 2.95036667, 2.95036667, 2.95036667,
2.95036667, 2.95036667, 2.95036667, 2.95036667, 2.95036667],
[ 3.28353333, 3.28353333, 3.28353333, 3.28353333, 3.28353333,
3.28353333, 3.28353333, 3.28353333, 3.28353333, 3.28353333],
[ 3.6167 , 3.6167 , 3.6167 , 3.6167 , 3.6167 ,
3.6167 , 3.6167 , 3.6167 , 3.6167 , 3.6167 ],
[ 3.94986667, 3.94986667, 3.94986667, 3.94986667, 3.94986667,
3.94986667, 3.94986667, 3.94986667, 3.94986667, 3.94986667],
[ 4.28303333, 4.28303333, 4.28303333, 4.28303333, 4.28303333,
4.28303333, 4.28303333, 4.28303333, 4.28303333, 4.28303333],
[ 4.6162 , 4.6162 , 4.6162 , 4.6162 , 4.6162 ,
4.6162 , 4.6162 , 4.6162 , 4.6162 , 4.6162 ]])
x0m
array([[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ],
[ 0.086405 , 0.52291556, 0.95942611, 1.39593667, 1.83244722,
2.26895778, 2.70546833, 3.14197889, 3.57848944, 4.015 ]])
all 3 meshgrids, pred_grid
,x0m
and x1m
are of exactly the same shape.
I am really puzzled why my plot just isnβt working right, even though I am using the same code which worked for a contour plot that I had successfully generated previously in an earlier project that can be seen here.