Replacing count by percentage in R

I have the following code : mutate( bmi = Gewicht / (Körpergröße/100)^2 ) %>% filter( Lebensalter >= 18 )%>% filter(!is.na(bmi))%>% group_by(Geschlecht, Ethnie)%>% filter(!is.na(Ratio))%>% mutate (Poor = Ratio < 1.3)%>% mutate (Adipös= bmi>=30)%>% filter(!is.na(Poor))%>% ggplot+ geom_histogram(aes( y= Poor, fill=Adipös), stat = "count")+ facet_grid(Ethnie~Geschlecht) which gives me this table: How can I get the percentage for each true and false for poor and adipös? E.g. 20% of male poor African American are also "Adipös" (overweight)? So instead of the bars showing the …
Category: Data Science

making a contingency table with TRUE and FALSE values

I made the following contingency table already, however there should only be TRUE or FALSE and not all of them showing up on the table. How can I change that? my code is the following: library(tidyverse) library(haven) read_xpt("~/downloads/DEMO_J.XPT") -> demo17 demo17%>% select (subjectID= SEQN, Lebensalter=RIDAGEYR, Geschlecht=RIAGENDR, Ethnie = RIDRETH3, Einwohner=WTMEC2YR, Ratio=INDFMPIR)%>% mutate(Geschlecht=fct_recode(factor(Geschlecht), "Männlich"="1", "Weiblich"="2"))%>% mutate(Ethnie=fct_recode(factor (Ethnie), "Mexican American"="1", "Other Hispanic"="2", "NH White"="3", "NH Black"="4", "NH Asian"="6", "Other"="7")) -> D2 read_xpt("~/downloads/BMX_J.XPT") -> bmx17 bmx17%>% select (subjectID = SEQN, Körpergröße= BMXHT, Gewicht …
Category: Data Science

How to solve the gradient descent on a linear classification problem?

I have a problem which i have attached as an image. Problem is in image attached what I understand error function is given by: $e(y, \hat y)=0$ if $y \cdot a(x-b) \ge 1$ or $e(y, \hat y) = 1-y\cdot a\cdot (x-b)$ if $y a(x-b) < 1$. Gradient descent at current $t$ is (1,3). Gradient Descent($E_{in}(a,b)$) as per definition should be equal to partial derivative of the equation of $E_{in}(a,b)$ wrt $a$ and $b$. ($w$ is equivalent to $[a, b]$, according …
Category: Data Science

How do I determine if a neural network can be computed by a network that contains only an input layer and an output layer?

I have a homework problem where the neural network below is given with its description. We have been asked "Can the functions that the above network computes also be computed by a network that contains only an input layer and an output layer that has a single node?" If we can, we're to provide the network, weights, and activation function. And if not, we have to explain why. I am very unsure how to approach this problem as I am …
Category: Data Science

What is the problem with: the condition has length > 1 and only the first element will be used?

newbie to r. i have: > > age <- function(Age) { > + answer<-NULL > + if(Age<15) answer<-"under 15" > + else if(15<=Age&&Age<=50) answer<-"15 to 50" > + else answer<-"over 50" > + answer > + } > > titanic_3 <- titanic %>% > + select(Survived, Pclass, Age, Sex) %>% > + filter(!is.na(Age)) %>% > + mutate(agecat=age(Age)) Warning message: In if (Age < 15) answer <- "under 15" else if (15 <= Age && Age <= : the condition has …
Topic: homework r
Category: Data Science

Are application assignments in Datascience common practice?

this might seem off topic, but I hope this question will be tolerated. I was recently asked to help a friend with an assignment in the process of applying for a new job as data scientist. And honestly I had a lot of fun solving the assignment for me and giving him guidance on how to proceed However this got me wondering about a few things: is it common practice in Datascience to hand out assignments to applicants? is there …
Topic: homework data r
Category: Data Science

Train Naive Based Classifier

For (a) I have calculated $P(G)=\frac{5}{8}$, $P(O|G)=\frac{2}{5}$, $P(B|G)=\frac{1}{5}$, $P(C|G)=\frac{4}{5}$, and $P(A|G)=\frac{4}{5}$. Now how do I calculate the maximum likelihood estimate of these values? And how do I go about part (b)? I get that $O,B,C,A$ are independent so I can multiply them to get joint probability. But for values like $O_i$ for sample $i=9$, that is just $0$, since sample 9 doesn't have outdoor seating. And how am I supposed to calculate $P(G_i)$ if I don't know what $G_9$ is?
Category: Data Science

Coding Issues faced in Andrew Ng's course

I was going through Andrew's ML course on Coursera (Week 2). I attach with this post some snaps of my codes for the optional exercise part (of the programming assignment problems) for that week, namely, the codes for featureNormalize.m (4th image from top), computeCostMulti.m (2nd image from top), and gradientDescentMulti.m (3rd image from top), along with the outputs (1st image) that I obtained on submission, and a figure depicting the convergence of gradient descent (last image). Is something wrong with …
Category: Data Science

Problem on dataset skewness and deviation

This is the problem statement : Your data set has missing values and is positively skewed with skewness = 1. Further examination tells you that they are spread along 1.5 standard deviation from the median. How much data would remain in % and Why?
Category: Data Science

Can a single-layer ANN get XOR wrong?

I'm still pretty new to artificial neural networks. While I've played around with TensorFlow, I'm now trying to get the basics straight. Since I've stumbled upon a course which explains how to implement an ANN with back propagation in Unity, with C#, I did just that. While test-running the ANN with one hidden layer containing 2 neurons, I noticed, that it doesn't always get XOR right. No matter how many epochs it runs or how the learning rate was set. …
Category: Data Science

How do i convert a Named num [1:4] to a data frame in R?

newbie to r, taking The R Programming Environment from coursera. one of the assignments is to select some columns from a data frame and find the means. the code below seems to get the correct answer, but the answer should be a data frame. wc_2 <- worldcup %>% select(Time, Passes, Tackles, Saves) %>% colMeans() How do i convert this to a data frame? i tried: wc_2<-as.data.frame(wc_2) but that gets it column wise. i do not see any way to pass …
Topic: homework r
Category: Data Science

A binary classifier predicts only one type of class

This is an assignment question. Can someone someone give me some clue on how to get through: A generative approach is used for a binary classification problem and it turns out that the resulting classifier predicts positive at all points x in the input space. What can we conclude for sure? Check all that apply. There are no negative points in the training set. The positive points are spread out over the space, while the negative points are concentratd in …
Category: Data Science

How to calculate growth function for a threshold function

I'm working on a homework problem but don't fully understand it. The problem and solution: I don't understand the definition of the threshold function. Does it mean to pick one feature and classify the point based on that one feature? It's the only way I can think of to explain the solution, $N$ ways to pick a feature, for each feature there are $m+1$ ways to select the threshold.
Category: Data Science

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.