Я использую язык программирования R. Я пытаюсь следовать этому руководству здесь: http://www.semspirit.com/artificial-intelligence/machine-learning/regression/support-vector-regression/support-vector-regression-in-r/
Для известного набора данных Iris я пытаюсь построить трехмерную поверхность решения для алгоритма случайного леса (используя размеры tsne):
library(Rtsne)
library(dplyr)
library(ggplot2)
library(plotly)
library(caret)
library(randomForest)
#data
a = iris
a <- unique(a)
#create two species just to make things easier
s <- c("a","b")
species<- sample(s , 149, replace=TRUE, prob=c(0.3, 0.7))
a$species = species
a$species = as.factor(a$species)
#split data into train/test, and then random forest
index = createDataPartition(a$species, p=0.7, list = FALSE)
train = a[index,]
test = a[-index,]
rf = randomForest(species ~ ., data=train, ntree=50, mtry=2)
#have the model predict the test set
pred = predict(rf, test, type = "prob")
labels = as.factor(ifelse(pred[,2]>0.5, "a", "b"))
confusionMatrix(labels, test$species)
#tsne algorithm
tsne_obj_3 <- Rtsne(test[,-5], perplexity=1, dims=3)
df_m2 <- as.data.frame(tsne_obj_3$Y)
df_m2$labels = test$species
Отсюда я пытаюсь построить трехмерную поверхность принятия решений (http://www.semspirit.com/artificial-intelligence/machine-learning/regression/support-vector-regression/support-vector-regression-in-r /) :
axis_1 = df_m2$V1
axis_2 = df_m2$V2
axis_3 = df_m2$V3
plot_ly(x=as.vector(axis_1),y=as.vector(axis_2),z=axis_3, type = "scatter3d", mode = "markers", name = "Obs", marker = list(size = 3)) %>%
add_trace(x=as.vector(axis_1),y=as.vector(axis_2),z=df_m2$labels, type = "mesh3d", name = "Preds")
Но я получаю следующую ошибку:
2: In RColorBrewer::brewer.pal(N, "Set2") :
minimal value for n is 3, returning requested palette with 3 different levels
3: 'mesh3d' objects don't have these attributes: 'mode', 'marker'
Valid attributes include:
'type', 'visible', 'legendgroup', 'name', 'uid', 'ids', 'customdata', 'meta', 'hoverlabel', 'stream', 'uirevision', 'x', 'y', 'z', 'i', 'j', 'k', 'text', 'hovertext', 'hovertemplate', 'delaunayaxis', 'alphahull', 'intensity', 'intensitymode', 'color', 'vertexcolor', 'facecolor', 'cauto', 'cmin', 'cmax', 'cmid', 'colorscale', 'autocolorscale', 'reversescale', 'showscale', 'colorbar', 'coloraxis', 'opacity', 'flatshading', 'contour', 'lightposition', 'lighting', 'hoverinfo', 'showlegend', 'xcalendar', 'ycalendar', 'zcalendar', 'scene', 'idssrc', 'customdatasrc', 'metasrc', 'xsrc', 'ysrc', 'zsrc', 'isrc', 'jsrc', 'ksrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'intensitysrc', 'vertexcolorsrc', 'facecolorsrc', 'hoverinfosrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'
Создается 3D-график, но 3D-плоскость полностью отсутствует.
Может кто-нибудь, пожалуйста, скажите мне, что я делаю неправильно?
Я пытаюсь сделать так, чтобы при наведении указателя мыши на каждую точку для этой точки отображалось значение a$Sepal.Length, a$Sepal.Width, a$Petal.Length, a$Petal.Width, $ виды
Спасибо
Когда вы позвонили add_trace()
, z
назначено неправильно. Этикетки не будут отображаться; вам нужно построить вероятности, которые вы определили, z=df_m2$pred
.
Есть несколько способов исправить проблемы с графиком сетки, но проще всего использовать add_mesh
вместо add_trace
.
plot_ly(x=as.vector(axis_1),
y=as.vector(axis_2),
z=axis_3,
type = "scatter3d",
mode = "markers",
name = "Obs",
marker = list(size = 3)) %>%
add_mesh(x=as.vector(axis_1),
y=as.vector(axis_2),
z=df_m2$pred,
type = "mesh3d",
name = "Preds")
Не могли бы вы взглянуть на это, если у вас есть время? stackoverflow.com/questions/65434105/… спасибо
Большое спасибо! Я потратил часы, пытаясь понять это! Идеально! Всего два вопроса: как вы делаете метки (ширина лепестка, длина лепестка и т.д.) при наведении мышки на каждую точку? И можно ли сделать точки с меткой «а» синим, а «б» красным? Большое спасибо!