Thursday, March 23, 2017

R: subsetting the data frame

# first 5 observations
newdata <- mydata[1:5,]

# based on variable values
newdata <- mydata[ which(mydata$gender=='F' 
& mydata$age > 65), ]



another example
Pakcities<-world.cities[which(world.cities$country.etc="Pakistan"),]

rest is for displaying Pakistan map with cities
--------------------------------------
 stat1<-map_data("world",country = "Pakistan")
stat1<-stat1[which(stat1$region =="Pakistan"),]
a4<-Pakcities[4]
a5<-Pakcities[5]
aaa<-data.frame(a4,a5)
gg <- ggplot(data=stat1, aes(x=long,y=lat))
gg <- gg + coord_map("mercator")
gg<- gg + geom_path(aes(group=group),colour="gray80")
gg <- gg + geom_point(data=aaa, aes(long, lat),
                      colour="#000099", alpha=1/40, size=1)
print(gg)

R: Error in plot.new() : figure margins are too large

Solution for error in R Studio

first execute
windows()
then your map
and when done

dev.off()

R: Map Pakistan

Pakistan <- data.frame(map("world", "Pakistan", plot=FALSE)[c("x","y")])
or



Link

windows()
map("world","Pakistan")
map.cities(country="Pakistan")
or

Pakcities<-world.cities[which(world.cities$country.etc="Pakistan"),]
rest is for displaying Pakistan map with cities
--------------------------------------
 stat1<-map_data("world",country = "Pakistan")
stat1<-stat1[which(stat1$region =="Pakistan"),]
a4<-Pakcities[4]
a5<-Pakcities[5]
aaa<-data.frame(a4,a5)
gg <- ggplot(data=stat1, aes(x=long,y=lat))
gg <- gg + coord_map("mercator")
gg<- gg + geom_path(aes(group=group),colour="gray80")
gg <- gg + geom_point(data=aaa, aes(long, lat), 
                      colour="#000099", alpha=1/40, size=1)
print(gg)

Tuesday, March 21, 2017

Keras 2.0: UnboundLocalError: local variable 'class_name' referenced before assignment

Error came due to two reasons

1. Used  nb_epochs of version 1 instead of  epochs in model.fit of version 2.0

2. Used the wrong name for loss (categorical-crossentroy instead of categorical_crossentropy) in model.compile

Monday, March 20, 2017

keras 2.0, Convulution2D : Negative dimension size

Change
model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=(1,28,28)))
to

1
2
model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=(1,28,28),
                        dim_ordering='th'))

Saturday, March 18, 2017

links for neural network

http://www.bogotobogo.com/python/scikit-learn/Artificial-Neural-Network-ANN-10-Deep-Learning-3-Theano-TensorFlow-Keras.php
http://www.bogotobogo.com/python/scikit-learn/Artificial-Neural-Network-ANN-9-Deep-Learning-2-Image-Recognition-Image-Classification.php
https://elitedatascience.com/keras-tutorial-deep-learning-in-python
http://machinelearningmastery.com/tutorial-first-neural-network-python-keras/

checking who is connected to internet sharing on mac

use
ifconfig command to check the name of the bridge, in my case it was bridge100

and then use
arp -i bridge100 -a