Question

In: Computer Science

Consider the Titanic data stored in a structure variable named T. Passenger ID Survived 1=Yes, 2=No...

Consider the Titanic data stored in a structure variable named T.
Passenger ID Survived
1=Yes, 2=No

Gender
1=Male, 2=Female

Age Fare ($)

T =

121 2 1 22 7.25
243 1 2 38 71.28
432 1 2 26 7.93
564 1 2 35 53.1
856 2 1 35 8.05

As a table of 6 students, complete the following – you may want to have a couple of students checking the syntax and
output on MATLAB.
1. Draw the table (Titanic data) on the whiteboard.
2. Annotate and provide the syntax to exact the:
a. 1
st column and assign it to the variable named id
b. 3
rd column and assign it to the variable named gender
c. 4
th column and assign it to a variable named age

3. Annotate and provide the output of:
a. index = age>30
b. old_age = age(index)
c. old_age_id = id(index)
4. Write syntax that will return a vector containing all female passenger IDs
5. Write syntax that will find the row number of the passenger aged 38
6. Write syntax to extract the 2nd and 3rd columns of information for the passenger aged 38, using the variable created
in step 5
7. Take a photo of your work for future reference. The entire table is to present the work to a demonstrator and
answer questions to get it marked off before moving onto the next task.

Solutions

Expert Solution

1)

Table of Titanic data
Passenger ID Survived Gender Age Fare($)
121 No Male 22 7.25
243 Yes Female 38 71.28
432 Yes Female 26 7.93
564 Yes Female 35 53.1
856 No Male 35 8.05


Passenger_ID=[121 243 432 564 856]'
Survived=[2 1 1 1 2]'
Gender=[1 2 2 2 1]'
Age=[22 38 26 35 35]'
Fare=[7.25 71.28 7.93 53.1 8.05]'
tab2=table(Passenger_ID,Survived,Gender,Age,Fare)

2)

a)

id=table2array(tab2(:,1)) % Selecting 1st column and assigning it to Id
id

b)

gender=table2array(tab2(:,3)) % Selecting 3rd column and assigning it to gender
gender

c)

age=table2array(tab2(:,3)) % Selecting 4th column and assigning it to age
age

3)

a)

index = find(age>30); % Index of age > 30
index

b)

old_age=age(index) %Ages >30
old_age

c)

old_age_id=id(index)
old_age_id

4)

female=find(gender==2) % we need to get thhe index details of females
female
female_id=id(female) % selecting female ID's according to index values
female_id

5)

row_38=find(age==38) % Selecting the row
row_38

6)

survive=table2array(tab2(:,2)) %select the second column
sec_col=survive(row_38) %selection of survival age 38
third_col=gender(row_38) %gender of age 38
sec_col,third_col

7)

The MATLAB CODE:-

%Loading the data
Passenger_ID=[121 243 432 564 856]'
Survived=[2 1 1 1 2]'
Gender=[1 2 2 2 1]'
Age=[22 38 26 35 35]'
Fare=[7.25 71.28 7.93 53.1 8.05]'
tab2=table(Passenger_ID,Survived,Gender,Age,Fare)

id=table2array(tab2(:,1))
id
gender=table2array(tab2(:,3)) %3rd column and assign it to the variable named gender
gender

age=table2array(tab2(:,4)) %4th column and assign it to a variable named age
age

index = find(age>30);
index

old_age=age(index)
old_age
%old_age id cal
old_age_id=id(index)
old_age_id
%finding the female
female=find(gender==2)
female
%female id
female_id=id(female)
female_id
%index of row having age 38
row_38=find(age==38)
row_38

survive=table2array(tab2(:,2)) %Survive table selection
sec_col=survive(row_38)
third_col=gender(row_38)
sec_col,third_col

Results:-


Related Solutions

Task 2 (1 mark) Transformation of data stored in the relational tables into data stored in...
Task 2 (1 mark) Transformation of data stored in the relational tables into data stored in BSON collection.
Consider the following three variables. Variable Coding Label DRINK 1 = yes 2 = no Regular...
Consider the following three variables. Variable Coding Label DRINK 1 = yes 2 = no Regular Drinker SEX 1 = male 2 = female CASES 0 = Normal 1 = Case of Depression Depressed is cesd > 16s: Α logistic regression model using DRINK as the dependent variable and CASES and SEX as independent variables and the the appropriate interaction term was fit to the data. Logistic regression output is as follows: Logistic regression Number of obs = 294 LR...
#data structure 1.Implement the generic PriorityQueueInterface in a class named PriorityQueue. Note: it must be named...
#data structure 1.Implement the generic PriorityQueueInterface in a class named PriorityQueue. Note: it must be named PriorityQueue The priority queue MUST be implemented using a linked list. 2 test program checks that a newly constructed priority queue is empty o checks that a queue with one item in it is not empty o checks that items are correctly entered that would go at the front of the queue o checks that items are correctly entered that would go at the...
Consider a Pokemon card production facility with the following cost structure: t=0: $70,000, t=1: $10000, t=2:...
Consider a Pokemon card production facility with the following cost structure: t=0: $70,000, t=1: $10000, t=2: $40,000, t=3: $–10,000 (a negative cost constitutes a revenue) Suppose the facility can produce 10,000 packages in year 1, 15,000 packages in year 2 and 30,000 packages in year 3, but must charge the same price for the packages in each year of operation. What is the break-even selling price in this case? MARR= 8%. Question 2 options: a) 2-2.20 b) 2.20-2.40 c) 2.40-2.60...
True/False 1. An automatic storage class variable is stored in the runtime stack 2. When a...
True/False 1. An automatic storage class variable is stored in the runtime stack 2. When a value parameter is passed to a function, the function called utilizes a copy of that parameter which is internal to the function called 3. When a reference parameter is passed to a function, the function called receives the memory address of that parameter and does not make a copy of it 4. Debug flags often control extra output to be printed conditionally Multiple choice...
Student ID Student ACT Score (Independent Variable) Student            GPA     (Dependent Variable) 1 24 3.25 2 21...
Student ID Student ACT Score (Independent Variable) Student            GPA     (Dependent Variable) 1 24 3.25 2 21 2.87 3 18 2.66 4 22 3.33 5 22 2.87 6 22 3.21 7 18 2.76 8 28 3.91 9 29 3.55 10 18 2.55 11 20 2.44 12 24 3.22 13 25 3.22 14 24 3.44 15 21 3.01 Instructions: Generate on a separate worksheet a standard set of SUMMARY OUTPUT for two-variable regression, and label the worksheet "Simple Regression Output". Then, using...
In C++ ============================================================EXERCISE 2 PROBLEM SET============================================================ 1) Declare a structure named TempScale , with the following...
In C++ ============================================================EXERCISE 2 PROBLEM SET============================================================ 1) Declare a structure named TempScale , with the following members:fahrenheit: a doublecentigrade: a doubleNext, declare a structure named Reading , with the following members:windSpeed: an inthumidity: a doubletemperature: a TempScale str ucture variableNext define a Reading structure variable. ------------------------------------------------------------ 2) Write statements that will store the following data inthe variable you defined in Problem 1:Wind Speed: 37 mphHumidity: 32%Fahrenheit temperature: 32 degreesCentigrade temperature: 0 degrees ------------------------------------------------------------ 3) Write a function called showReading. It...
Student ID Student ACT Score  (Independent Variable) Student            GPA     (Dependent Variable) 1 24 3.25 2 21 2.87
Student ID Student ACT Score  (Independent Variable) Student            GPA     (Dependent Variable) 1 24 3.25 2 21 2.87 3 18 2.66 4 22 3.33 5 22 2.87 6 22 3.21 7 18 2.76 8 28 3.91 9 29 3.55 10 18 2.55 11 20 2.44 12 24 3.22 13 25 3.22 14 24 3.44 15 21 3.01 Instructions:  Generate  on a separate worksheet a standard set of SUMMARY OUTPUT for two-variable regression, and label the worksheet "Simple Regression Output".  Then, using the information in this output 1)...
ID Documents 1 I love data mining 2 The seven dwarves love mining 3 Data science...
ID Documents 1 I love data mining 2 The seven dwarves love mining 3 Data science is a hot new career 4 I don't love my major or career Use the corpus of documents shown in the above table to answer the quiz questions below. What is the inverse document frequency (IDF) of the term "love"? (Round your answer to 2 decimal places). What is the TF-IDF value (importance) of the term "data" to document 1? (Round your answer to...
1. Consider the initial value problem y′ =1+y/t, y(1)=3 for1≤t≤2. • Show that y(t) = t...
1. Consider the initial value problem y′ =1+y/t, y(1)=3 for1≤t≤2. • Show that y(t) = t ln t + 3t is the solution to the initial value problem. • Write a program that implements Euler’s method and the 4th order Runke-Kutta method for the above initial value problem. Use your program to solve with h = 0.1 for Euler’s and h = 0.2 for R-K. • Include a printout of your code and a printout of the results at each...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT