0% found this document useful (0 votes)
29 views8 pages

dump

The document consists of a series of programming and data analysis questions, covering topics such as Python code outputs, data manipulation with pandas, and concepts in machine learning. Each question presents multiple-choice answers, requiring the reader to select the correct output or code snippet. The questions test knowledge on various programming concepts, data handling, and statistical principles.

Uploaded by

Sayon Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views8 pages

dump

The document consists of a series of programming and data analysis questions, covering topics such as Python code outputs, data manipulation with pandas, and concepts in machine learning. Each question presents multiple-choice answers, requiring the reader to select the correct output or code snippet. The questions test knowledge on various programming concepts, data handling, and statistical principles.

Uploaded by

Sayon Islam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

What will be the output of the below code:

def display(sentence):
words = sentence.split(' ')
reverse_sentence = ' '.join(reversed(words))
return reverse_sentence

input = 'Python is easy'


print(display(input))

a. easy is Python
b. [‘easy’, ‘is’, ‘Python’]
c. Python is easy
d. None of the options

2. For a machine learning project, Sara has given the client dataset named 'mydata.csv' having
millions of records with 50 columns to Allen, and asked him to work with the specific column
names l.e. "coulmn23", "column33", "column37", "column 12" in a given dataset.

Select the correct option that will help Allen to import the data with the specific column
names mentioned above.

Answer => pd.read_csv("mydata.csv", usecols= ["column23", "column33", "column37",


"column12"])

3. Given below the code snippet, what will be the output

test_dict = {'month' : [1,2,3], 'name' : ['Jan', 'Feb', 'March']}


res = dict(zip(test_dict['month'], test_dict['name']))
print(res)

answer => {1: 'Jan', 2: 'Feb', 3: 'March'}

4. # Initialize A and B
A = {1,2,3,4,5}
B = {4,5,6,7,8}
Print(A^B)

What will be the output


Answer => {1,2,3,6,7,8}

5. Select the code that will give the output

Input: [11, 5, 17, 18, 23, 50]


Output: [11, 50]

a. None of the option


b.
list1 = [11, 5, 17, 18, 23, 50]
unwanted_num = {11,50}
list1 = [ele for ele in list1 if ele in unwanted_num]
print(list1)

c.
import pandas as pd
a_list=[11, 5, 17, 18, 23, 50]
a_series = pd.Series(a_list)
accessed_series = a_series[[0,5]]
accessed_list = list(accessed_series)
print(accessed_list)

d.
import numpy as np
a_list = [11, 5, 17, 18, 23, 50]
n_array = np.array(a_list)
a_array = n_array[[0,5]]
a_list = list(a_array)
print(a_list)

6. Dave has been newly assigned as a manager in a large retail store. The first thing he wants to
store perform is to identify interesting association rules. He has identified itemsets above his
minimum support. He comes to you and enquires about how to choose minimum
confidence. Which of the following would be your correct response?

1.Depending on the question and distribution of confidence values for a sample decision is made
by the analyst

2.Depends on the minimum support of itemsets

3.Depending on the question and distribution of support values for itemsets made by the
analyst.

4.Depending on the question and distribution of values for a set of rules made by the analyst.
(not sure)

7. Does the decision boundary change with the addition/deletion of data points in SVM?

Yes
No

8.
No First Last Email Age
1. Sam Schafer [email protected] 33
2. Jane Doe [email protected] 55
3. Ben Doe [email protected] 63
4. Chris Morris None 36
5. NaN NaN NaN None
6. None NaN [email protected] None
7. NA Missing NA Missing

Sara wants to delete the rows where both the last name and email are missing. Select the
correct option that will help Sara to do that.

df.dropna(axis='index',how='all',subset=['last','email'])

df.dropna(axis='index',how='any',subset=['last','email'))

df.dropna(axis='index', subset=['last','email'])

None of the above

9. Given, is the two-dimensional array

arr1 = np.array( [53.75, 78.9, 88.87,33.45],


[22.34, 33.56, 65.43, 22.12],
[21.45, 6.98, 71.23, 88.67]).

John wants to flatten the 2D array in such a way that he should be able to change the 3rd
element value to 52. Select the right option for him.

A. arr1_flatten = arr1.flatten();arr1_flatten[2]=52

B. arr1_flatten = arr1.ravel();arr1_ravel[2]=52

C. arr1_flatten = arr1.ravel(); arr1_ravel[1]=52

D.arr1_flatten=arr1.flatten();arr1_flatten[1]=52

10.

No. Team Rank Year Points


1. AC-milan 1 2014 876
2. Barcelona 2 2015 789
3. Liverpool 2 2014 863
4. Man-city 3 2015 673
Ben wants to calculate the average of the Points column year-wise. Select the correct option

A.grouped = club_data.groupby("Year')

B.grouped = club_data.groupby("Year')

C. grouped = club_data.groupby('Year')

D.grouped =club_data.groupby('Points') grouped['Year'].agg(np.mean)

11.

No. Student_name Student_city Student_Age Student_percentage


1. Alex Mumbai 23 88.0
2. Ben Chennai 25 89.0
3. David New Delhi 33 83.0
4. Eva Kolkata 34 80.0
Select the code that will help Peter to reset the index to default.

df.reset_index(inplace=True)

df.set_index(inplace=True)
df.reset(inplace=True)
df.reset_index(('student_city', 'default'), inplace=True)

12. John wants to do data visualization for the dataset given by his client. Select the python
libraries that are used for data visualization.

A. Matplotlib
B. Seaborn.
C. Plotly
D. ggplot

13. Provide the correct output


def compare(A, B):
count = {}
for word in A.split():
count[word] = count.get(word, 0) + 1
for word in B.split():
count[word] = count.get(word, 0) + 1
return [word for word in count if count[word] == 1]
A = "apple for apple"
B = "Promise to give apple for apple"
print(compare(A, B))

a. ['Promise', 'to', 'give']


b. ['apple', 'for', 'apple']
c. ['for', 'Promise', 'to', 'give']
d. None of the options

14. What would be the output of the code


# Random sales dictionary
sales = {'apple': 2, 'orange': 3, 'grapes': 4}
element = sales.pop('guava', 'banana')
print('The popped element is:', element)

A. The popped element is: banana


B. KeyError: ‘guava’
C. The popped element is: None
D. None of the above.

15. Find the output of the below code:


def display(list1, n):
list1.sort()
Ist = list1[-n:]
new_lst = Ist[::-1]
return new Ist
list1 = [2, 6, 41, 85, 0, 3, 7, 6, 10] N = 2
# Calling the function
print(display(list1, N))
a. [85, 41]
b. [85]
c. [85, 41, 10]
d. 0

16. given the code below


a = np.array([
[1,2,3,4,5],
[6,7,8,9,10]
])

Select the correct option that will help john to reverse the array as shown in the output
array ([[10,9,8,7,6],
[5,4,3,2,1]])

A. a[::-1, :: -1]
B. a.reversed()
C. a[:: :-1]
D. np.flip(a,axis=0)

17. Create a new dictionary only with the students who have earned a passing grade greater
than or equal to 60:
grades = {"Nora": 78, "Gino": 100, "Talina": 56, "Elizabeth": 45, "Lulu": 67}

A. approved_students = {student: grade for (student, grade) in grades.items() if grade >=


60}
B. approved_students = {student: grade for (student, grade) in grades.items() if grade <=
60}
C. approved_students = {for (student, grade) in grades.items() if grade >= 60}
D. approved_students = {student: grade for (student, grade) in grades.values() if grade >=
60}

18. Select the correct output

def outer():
x = "local"
def inner():
nonlocal x
x ="nonlocal"
print("inner:", x)
inner()
print("outer:", x)
outer()

A. Inner: nonlocal
outer nonlocal
B. SyntaxError: invalid syntax, nonlocal
C. inner: nonlocal
outer: local
D. inner: local
outer: local

19. what will be the correct output


x = "global"
def foo():
x=x*2
print(x)

print(x)
foo()
print(x)

A. global
UnboundLocalError
B. global
globalglobal
globalglobal
C. global
globalglobal
global
D. None of the options

20. Naomi has been informed that the confidence for the association A=>B is 0.5 and that the
itemsets A and B together occur in 30% of the transactions. She is interested in finding support for A.
What value should she ger?

a. 0.6

b. 0.15

c. 1.67

d. 0.5

21. In ML and statistics, the learning rate is a hyperparameter for algorithm tuning that determines
the step size at each iteration while moving towards a minimum of a loss function. Which
among the following algorithms, the learning rate is not used as one of its hyperparameter?

a. Random forest
b. Decision tree
c. Gradient Learning

22. Which of the following statements is/are true regarding the bagging-based algorithms say a
random forest used in modal building?

Answer: Number of trees should be as large as possible.

23. What needed for constructing a confidence interval for a regression coefficient besides you
define the appropriate t statistics and regression coefficient.

Answer: The F statistics

24. for two itemsets A and B Lift(A=>B)<1, which of the following is the most correct inference?

A. If itemset A occurs, the probability of the occurrence of itemset B is less than what is
expected by chance store

B. The probability of both itemsets A and B co-occurring is less than 1

C. The probability of occurrence of A given the occurrence of B is less than 1

D. The probability of occurrence of B given the occurrence of A is less than 1


25. What will be the output of the given code snippet

sales = {'apple': 2, 'orange':3, 'grapes':4}


element = sales.pop('guava', 'banana')
print('the popped elemet is :',element)

a. The popped elernent is banana


b. KeyEron 'guavar
c. The popped element is: None
d. None of the option

26. What will be the output of the code

list1 = [{'Sam': 70, 'Joe': 80}, {'Sam': 60, 'Joe': 50}, {'Sam': 80, 'Joe': 50}]
s_total = sum(p['Sam'] for p in list1)
total = len(list1)
a = s_total / total
print(a)

a. 70 b. 60 c. 180 d. 210

27. Output of the below code

test_dict = {'you': [7, 6, 3], 'are': [2, 10, 3], 'best': [19, 4]}
res = dict()
for key in sorted(test_dict):
res[key] = sorted(test_dict[key])
print(res)

a. {‘are’: [2, 3, 10], 'best: [4, 19], ‘you’: [3, 5, 7]}

b. {‘you’: [3, 6, 7], 'are': [2, 3, 10], ‘best’ [4, 19]}

c. Error: Dictionary cannot be sorted

d. None of the options

You might also like