Skip to content

Instantly share code, notes, and snippets.

marks=[10,20,30,22,33,44,15,50,46,25,45,25,33,12,45,34,31,30,30,30]
import numpy as np
meanvalue=np.mean(marks)
print(meanvalue)
#Output: 30.5
#Taking sample from our data
sample_size=8
marks_sample=np.random.choice(marks,sample_size)
marks_sample
import scipy.stats as stats
import seaborn as sns
import pandas as pd
import numpy as np
dataset=sns.load_dataset("tips")
dataset.head()
# 2 categorical features
dataset_table=pd.crosstab(dataset['sex'],dataset['smoker'])
print(dataset_table)
import scipy.stats as stats
import seaborn as sns
import pandas as pd
import numpy as np
dataset=sns.load_dataset("tips")
dataset.head()
# 2 categorical features
dataset_table=pd.crosstab(dataset['sex'],dataset['smoker'])
print(dataset_table)
#Community detection
net <- graph.data.frame(y,directed=F)
cnet <- cluster_edge_betweenness(net)
plot(cnet,net)
@HeenaR17
HeenaR17 / Hubs.R
Last active February 7, 2021 21:08
#Hubs and authorities
hs <- hub_score(net)$vector
as <- authority.score(net)$vector
par(mfrow=c(1,2)) #to get one row, 2 columns and see 2 diagrams side by side
set.seed(123) #to get same configuration
plot(net,vertex.size=hs*30,main="Hubs",vertex.color=rainbow(52),edge.arrow.size=0.2,layout=layout.kamada.kawai)
plot(net,vertex.size=as*30,main="Authorities",vertex.color=rainbow(52),edge.arrow.size=0.2,layout=layout.kamada.kawai)
#Highlighting degrees and layouts
plot(net,vertex.color = rainbow(52), vertex.size=V(net)$degree*0.4,edge.arrow.size=0.2,layout=layout.fruchterman.reingold)
plot(net,vertex.color = rainbow(52), vertex.size=V(net)$degree*0.4,edge.arrow.size=0.2,layout=layout.graphopt)
plot(net,vertex.color = rainbow(52), vertex.size=V(net)$degree*0.4,edge.arrow.size=0.2,layout=layout.kamada.kawai)
#Network diagram
plot(net, vertex.color ="green", edge.arrow.size=0.3)
#Histogram of node degree
hist(V(net)$degree,
col="green",
main='Histogram of node degree',
ylab='Frequency',
xlab='Degree of vertices')
#Create network
net <- graph.data.frame(y, directed=T)
#Checking number of vertices and edges
V(net)
E(net)
V(net)$label <- V(net)$name
V(net)$degree <- degree(net)
data <- read.csv(file.choose(), header=T)
y <- data.frame(data$first, data$second)