This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Community detection | |
net <- graph.data.frame(y,directed=F) | |
cnet <- cluster_edge_betweenness(net) | |
plot(cnet,net) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Network diagram | |
plot(net, vertex.color ="green", edge.arrow.size=0.3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Histogram of node degree | |
hist(V(net)$degree, | |
col="green", | |
main='Histogram of node degree', | |
ylab='Frequency', | |
xlab='Degree of vertices') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data <- read.csv(file.choose(), header=T) | |
y <- data.frame(data$first, data$second) |