1. Home
  2. MCQs by exam
  3. NTS
  4. Data Science

NTS MCQs – Data Science · Page 4

266 multiple choice questions typical of the NTS exam, with answers and explanations. Switch on practice mode to test yourself first.

Showing 76–100 of 266

A skewed income column must be split into four groups of equal count. Which function does that, and what does the other do instead?

  1. qcut, which uses sample quantiles, whereas cut splits on equal-width value ranges Correct answer
  2. cut, which uses sample quantiles, whereas qcut splits on equal-width value ranges
  3. cut, because both functions are identical except for the naming of their labels
  4. qcut, because it always produces equal-width bins regardless of the data distribution
MCQSEXAM Read explanation

df['city'].isin(['Lahore', 'Karachi']) is used as a row filter. What does it return, and how are NaN rows treated?

  1. A boolean Series aligned to the index, with NaN rows marked False unless NaN is listed Correct answer
  2. A boolean Series of identical length, with NaN rows marked True so every record is kept
  3. An integer array of row positions, because isin returns the matching row numbers
  4. A filtered DataFrame directly, since isin applies the mask as soon as it is called
MCQSEXAM Read explanation

A wide table with one column per month must become long, with month and value columns. Which call does that?

  1. df.transpose, which swaps rows and columns and therefore creates a long form table
  2. df.melt with id_vars, which turns the monthly columns into rows of key-value pairs Correct answer
  3. df.pivot with the month columns as index, which expands the columns into extra rows
  4. df.stack on axis=1, which returns a wide frame with the months kept as columns
MCQSEXAM Read explanation

df.pivot_table(index='dept', columns='month', values='sales') is called without aggfunc. What happens when several rows share a dept and month?

  1. The duplicate cells are averaged, because the default aggregation is the mean Correct answer
  2. A ValueError is raised, because duplicate entries need an explicit aggfunc
  3. The last row for each cell wins, because pivot_table keeps the final value
  4. The rows are concatenated into a list inside the cell, preserving every value
MCQSEXAM Read explanation

Which statement about TRUNCATE compared with DELETE is correct?

  1. TRUNCATE accepts a WHERE clause but is slower than DELETE, because it scans the whole table row by row
  2. Both fire row-level triggers once per removed row, so auditing behaves exactly the same for the two statements here
  3. DELETE cannot be rolled back in any database, while TRUNCATE always can, because it is DDL and not DML
  4. TRUNCATE removes all rows in one operation, cannot take a WHERE clause and fires no row-level delete triggers Correct answer
MCQSEXAM Read explanation

What does LAG(sales, 1, 0) OVER (PARTITION BY store ORDER BY month) return?

  1. The store's average sales, with 0 substituted wherever the partition is empty or has one row
  2. The next month's sales within the same store, with 0 substituted for the last row of each partition
  3. The running total of sales within each store, starting at 0 at the very first row of every partition here
  4. The previous month's sales within the same store, with 0 substituted for the first row of each partition Correct answer
MCQSEXAM Read explanation

Why can WHERE x NOT IN (SELECT y FROM t) return no rows when the subquery yields a NULL?

  1. Because NOT IN converts the NULL to zero and then compares numerically, matching every zero value
  2. Because x <> NULL is UNKNOWN, so the NOT IN predicate can never be TRUE; NOT EXISTS is null-safe Correct answer
  3. Because the subquery is executed only when it contains no NULL values, and otherwise the whole subquery is skipped
  4. Because NOT IN is not valid with a subquery at all, so the parser rejects the statement outright
MCQSEXAM Read explanation

Which statement contrasts UNION and UNION ALL correctly?

  1. UNION removes duplicate rows and therefore usually needs a sort or hash, while UNION ALL concatenates and keeps duplicates Correct answer
  2. Both remove duplicate rows, differing only in the column ordering they produce, so the choice between them is purely cosmetic
  3. UNION requires matching column names, while UNION ALL does not, which is why UNION ALL is faster to write
  4. UNION ALL removes duplicate rows, while UNION keeps them, so the two operators are exact opposites in effect
MCQSEXAM Read explanation

When GROUP BY runs on a column containing NULLs, how are those rows treated?

  1. The rows are excluded from the result entirely, because the grouping key is missing
  2. The query fails unless NULLs are filtered out first, since grouping needs a known key
  3. All NULLs form a single group, because GROUP BY treats them as equal to each other Correct answer
  4. Each NULL forms its own separate group, because NULL is never equal to another one
MCQSEXAM Read explanation

Counting customers by joining customers to orders and using COUNT(*) inflates the number. Why, and what fixes it?

  1. Because COUNT(*) ignores NULLs in the customer key, so rows with a missing key are never counted at all by the aggregate
  2. The one-to-many join repeats each customer row per order, so COUNT(DISTINCT customer_id) or a subquery gives the true count Correct answer
  3. Because the join sorts the rows and duplicates them during the sort, so the sort key must therefore be made distinct first of all
  4. Because COUNT(*) counts columns rather than rows, so it returns the width of the joined result instead of its height
MCQSEXAM Read explanation

A LEFT JOIN carries the right-table condition b.status = 'active' in the WHERE clause instead of the ON clause. What is the effect?

  1. Nothing changes, because the optimiser moves the predicate into the ON clause
  2. All inactive matches are kept while unmatched rows are duplicated
  3. The query fails because WHERE cannot reference the right table
  4. Rows with no matching b row are removed, turning the outer join into an effective inner join Correct answer
MCQSEXAM Read explanation

Values 100, 100, 90 are ranked in descending order. What do RANK, DENSE_RANK and ROW_NUMBER produce?

  1. 1,2,3 for all three functions, because every row receives a distinct sequential position
  2. 1,1,2 for RANK and 1,1,3 for DENSE_RANK, with 1,2,3 for ROW_NUMBER in the very same single query
  3. 1,1,3 for RANK; 1,1,2 for DENSE_RANK; and 1,2,3 for ROW_NUMBER with an arbitrary tie order Correct answer
  4. 1,1,3 for all three, since ties always skip a position whatever function is used
MCQSEXAM Read explanation

In SUM(x) OVER (ORDER BY d), the default window frame uses RANGE. What practical difference does that make compared with an explicit ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW?

  1. RANGE requires a PARTITION BY clause, whereas ROWS can be used over the whole table without one
  2. ROWS ignores the ORDER BY, whereas RANGE sorts the partition before summing
  3. Rows that tie on d are all included in the same running total under RANGE, while ROWS admits them one at a time Correct answer
  4. RANGE includes only the current row, whereas ROWS accumulates every preceding row in the partition
MCQSEXAM Read explanation

Which curve would you inspect to decide whether collecting more training data is likely to help?

  1. The precision-recall curve, which plots precision against recall at every threshold
  2. The validation curve, which plots scores against one hyperparameter value at a time
  3. The ROC curve, which plots the true positive rate against the false positive rate of the model
  4. The learning curve, which plots training and validation scores against training-set size Correct answer
MCQSEXAM Read explanation

What does passing sample_weight to fit() actually do?

  1. It multiplies each row's contribution to the loss by its weight, without resampling the data Correct answer
  2. It sorts the rows so that heavier samples are fitted first and influence the coefficients more
  3. It affects only predict, not the fitted coefficients, which are always learned unweighted
  4. It physically replicates rows in proportion to their weights before the fit begins to run
MCQSEXAM Read explanation

RandomForestClassifier(oob_score=True) requires which condition to produce a meaningful out-of-bag score?

  1. max_features must equal the total number of features, so that every split always sees the whole feature set
  2. The number of trees must be less than the number of samples, so that every tree sees fresh data
  3. criterion must be set to entropy, because the Gini criterion cannot track the out-of-bag error
  4. bootstrap=True, since out-of-bag samples exist only when each tree is trained on a bootstrap resample Correct answer
MCQSEXAM Read explanation

How does predict_proba differ from decision_function?

  1. predict_proba returns normalised class probabilities summing to one, while decision_function returns unbounded signed distances to the decision boundary Correct answer
  2. decision_function returns probabilities between zero and one, while predict_proba returns raw margins, so the two names are swapped in most of the documentation
  3. Both return probabilities, but predict_proba is only for regressors while decision_function is only for classifiers, so neither applies here
  4. predict_proba is available on every estimator, while decision_function is not, which is why predict_proba is the preferred interface for scoring
MCQSEXAM Read explanation

A modeller runs cross_val_predict(model, X, y, cv=5) and then computes accuracy on the returned predictions in order to select hyperparameters. What is the main objection?

  1. It requires a separate hold-out set and raises NotFittedError when none is supplied alongside cv
  2. The predictions are out-of-fold, but the same folds would also drive selection, so the resulting score is not a clean estimate Correct answer
  3. cross_val_predict refits on the full dataset first, so every prediction is in-sample and therefore over-optimistic
  4. It returns one aggregate score per fold instead of predictions, so accuracy cannot be computed from its output
MCQSEXAM Read explanation