无论从对象' d'中选择什么字母,我都试图为节点6和7着色。
g <- graph_from_literal(1:2:3:4:5 -- 6:7)
# Rename (sum up all the vertices)
d <- c("a", "b", "c", "d", "e", "f", "g","h", "i", "j")
V(g)$name <- sample(d, 7, replace=TRUE)
colours <- c("red")
V(g)$color <- ifelse(V(g)$name == c('a','e'), "white", colours)
plot.igraph(g, layout=layout_with_dh, vertex.label=V(g)$name,
vertex.size=35,
vertex.color=V(g)$color, #colors.r
vertex.label.cex=0.7,
)
我尝试了上面的ifelse(),但他们似乎没有取数值。我很感激一些帮助。
我想要的是节点6例如是白色和7是例如绿色,其他节点为红色。
谢谢!
答案 0 :(得分:5)
你可以做到
V(g)$color <- "red"
V(g)$color[6] <- "white"
V(g)$color[7] <- "green"
答案 1 :(得分:1)
你也可以这样做:
import pandas as pd
from sklearn.cross_validation import train_test_split
from sklearn.linear_model import LinearRegression
data = pd.read_csv("https://raw.github.com/pydata/pandas/master/pandas/tests/data/iris.csv")
data.head()
features_cols = ['SepalLength', 'SepalWidth', 'PetalLength', 'PetalWidth']
X = df[features_cols]
y = data.Name
X_train, X_test, y_train, y_test = train_test_split(X,y,random_state=1)
linreg = LinearRegression()
linreg.fit(X_train, y_train)