1. Home
  2. Subjects
  3. Data Science

Data Science MCQs · Page 20

1,613 multiple choice questions with answers across 28 topics.

Showing 476–500 of 1,613

Table a has 12 rows and table b has 7 rows. SELECT * FROM a CROSS JOIN b; is run. How many rows come back?

  1. 84, because a cross join returns every possible pairing of the two row sets Correct answer
  2. 19, because a cross join appends the second table's rows directly onto the first
  3. 12, because only rows of the first table drive the result of the join
  4. 7, because the smaller table determines the number of output rows
MCQSEXAM Read explanation

SELECT dept, AVG(salary) FROM staff WHERE AVG(salary) > 50000 GROUP BY dept; fails. Why?

  1. AVG cannot appear in both the select list and the filter of the same query
  2. The GROUP BY clause must also list AVG(salary) explicitly so the aggregate has a name
  3. Aggregates are only permitted in the select list and in the ORDER BY clause
  4. WHERE runs before grouping, so no aggregate exists yet; HAVING must filter instead Correct answer
MCQSEXAM Read explanation

SELECT COUNT(CASE WHEN status = 'late' THEN 1 END) AS late FROM loans; is executed. How does the result differ from COUNT(*)?

  1. It counts every row, because COUNT ignores the NULL result of the CASE expression
  2. It counts late rows twice, since the CASE duplicates every row that matches
  3. It fails, because COUNT cannot accept a CASE expression as its only argument
  4. It counts only late rows, because the CASE yields NULL for all other statuses Correct answer
MCQSEXAM Read explanation

An expression computes revenue / items and items may be zero. Which construct prevents a division-by-zero error, and how?

  1. NULLIF(items, 0), which returns NULL for a zero divisor so the result becomes NULL Correct answer
  2. COALESCE(items, 0), which substitutes a zero divisor so that the division stays exact
  3. NULLIF(items, 0), which replaces NULL divisors with zero and skips those rows
  4. COALESCE(items, 0), which converts a zero divisor into a NULL before dividing
MCQSEXAM Read explanation

A subquery used with NOT IN returns a NULL among its values. What happens to the outer query's result?

  1. It returns the same rows as NOT EXISTS would, since NULLs are ignored by NOT IN
  2. It raises an error, because NOT IN refuses subqueries that can produce NULL
  3. It returns only the rows whose key is itself NULL, treating NULL as a match
  4. It returns no rows at all, because every comparison with NULL yields unknown Correct answer
MCQSEXAM Read explanation

SELECT price * qty AS total FROM items ORDER BY total DESC; works in PostgreSQL. What is total referring to?

  1. The original column named total, since aliases are never visible to ORDER BY
  2. A positional reference, because total is parsed as the second select expression
  3. A re-evaluated expression, since ORDER BY recomputes price times qty again
  4. The output column alias, which ORDER BY accepts even though WHERE does not Correct answer
MCQSEXAM Read explanation

SELECT * FROM events LIMIT 10; is run repeatedly on a large table. Why can the returned rows differ between executions?

  1. LIMIT samples rows randomly unless a repeatable seed is supplied with the statement
  2. Without ORDER BY no row order is guaranteed, so the plan may return any ten rows Correct answer
  3. LIMIT is applied before the WHERE clause, so different rows qualify on each run
  4. The table's primary key is used implicitly, and keys are regenerated on each read
MCQSEXAM Read explanation

SELECT DISTINCT city, country FROM customers; is executed. What exactly is deduplicated?

  1. Only the city column, because DISTINCT applies to the first selected expression only
  2. Only the country column, since the last expression in the list takes precedence
  3. Both columns independently, producing the cross product of unique values
  4. Whole (city, country) pairs, so a city may still appear once per distinct country Correct answer
MCQSEXAM Read explanation

SELECT COUNT(*) FROM orders HAVING COUNT(*) > 100; is valid in PostgreSQL. What does HAVING do when no GROUP BY is written?

  1. It forms implicit groups from every selected column of the query output
  2. It filters the single implicit group, returning either one row or no rows at all Correct answer
  3. It is a syntax error, because HAVING always requires an explicit GROUP BY clause
  4. It filters individual rows before aggregation, exactly as a WHERE clause would
MCQSEXAM Read explanation

LogisticRegression(class_weight='balanced') is fitted on 1000 rows with 100 positives. What weight does the positive class receive?

  1. 1.0, because balanced weighting only rescales the intercept term of the model
  2. 0.1, because the minority class is down-weighted to match the majority count
  3. 5.0, computed as n_samples divided by the product of classes and positives Correct answer
  4. 10.0, computed as the ratio of negatives to positives in the training data
MCQSEXAM Read explanation

A ColumnTransformer applies OneHotEncoder to two columns with remainder='passthrough'. What does the fitted output contain?

  1. Only numeric columns, since passthrough drops anything it cannot encode
  2. Encoded columns followed by every unlisted column appended unchanged in order Correct answer
  3. Only the encoded columns, because remainder='passthrough' keeps no other column at all
  4. The encoded columns plus a copy of the input frame, so all columns appear twice
MCQSEXAM Read explanation

A Pipeline is built as Pipeline([('scale', StandardScaler()), ('model', LogisticRegression())]). How is C changed through set_params?

  1. pipeline.set_params(model.C=0.1), using dotted attribute notation for the step
  2. pipeline.set_params('model__C'=0.1), passing the parameter name as a quoted string
  3. pipeline.set_params(model__C=0.1), using the step name and a double underscore Correct answer
  4. pipeline.set_params(C=0.1), because parameters are flattened onto the pipeline itself
MCQSEXAM Read explanation

GridSearchCV(scoring='f1') is used with a classifier and cv left at its default. Which splitter is applied?

  1. StratifiedKFold with 5 splits, which preserves each class ratio inside every fold Correct answer
  2. KFold with 5 splits and no shuffling, which keeps the original row ordering fully intact
  3. LeaveOneOut, because grid search always maximises the number of fitted models
  4. TimeSeriesSplit, because f1 scoring requires chronologically ordered folds here
MCQSEXAM Read explanation

For a binary SVC, predict uses decision_function internally. What decision rule is applied by default?

  1. The score is compared with the training mean, which recentres the decision boundary
  2. The sign of the score decides the class, with positive scores mapped to classes_[1] here Correct answer
  3. The score is thresholded at 0.5, exactly mirroring a probability cut-off on a calibrated model
  4. The class with the larger absolute score wins, regardless of the score's overall sign
MCQSEXAM Read explanation

A column in the training data is entirely NaN. What does SimpleImputer(strategy='mean') do with it by default?

  1. It fills the column with zeros, because an undefined mean is replaced by zero
  2. It raises a ValueError, since no statistic at all can be computed from an empty column
  3. It keeps the column and fills it with NaN, preserving the missing-value marker
  4. It drops the column from the transformed output and ignores it during transform Correct answer
MCQSEXAM Read explanation

KMeans is run with n_init=10. What does that parameter control, and why does the default matter?

  1. The number of clusters tested, since n_init is simply an alias for n_clusters in the API
  2. The number of bootstrap samples used to estimate cluster stability scores
  3. The number of independent initialisations, with the lowest-inertia run being kept Correct answer
  4. The number of iterations allowed inside a single Lloyd run before it stops
MCQSEXAM Read explanation

Why is LabelEncoder unsuitable for encoding a categorical feature column before fitting a linear model?

  1. It imposes an arbitrary ordinal order, which the model then treats as numeric distance Correct answer
  2. It fails on columns that contain more than two distinct categories at once
  3. It returns one-hot columns, which cause perfect multicollinearity in the design matrix
  4. It only works on the target vector, so calling it on a feature column raises an error
MCQSEXAM Read explanation

What does n_jobs=-1 change about a scikit-learn estimator such as RandomForestClassifier?

  1. It sets the number of trees to the core count, overriding n_estimators entirely
  2. It spreads independent fits over all available cores, without changing the results Correct answer
  3. It repeats the fit once per available core and averages the resulting forests together
  4. It disables parallel execution, because -1 means a single worker thread here
MCQSEXAM Read explanation

Why is scaler.fit_transform(X_train) followed by scaler.transform(X_test) correct, while scaler.fit_transform(X_test) is not?

  1. The scaler requires the test set to be a subset of the training rows it was fitted on
  2. Fitting on the test set leaks its statistics into preprocessing and inflates scores Correct answer
  3. transform must be called before fit on the training set to establish the column order
  4. fit_transform on the test set is slower, yet returns an identical result
MCQSEXAM Read explanation

A fraud classifier labels 99 of 100 test transactions as legitimate and reports accuracy 0.99. Which metric exposes the problem fastest?

  1. The confusion matrix sum, which grows whenever accuracy is artificially high
  2. R-squared, which measures how much variance the fraud labels explain overall
  3. Balanced accuracy, which averages recall across both classes and lands near 0.50 Correct answer
  4. Precision, which stays high because most of the predicted negatives are truly negative
MCQSEXAM Read explanation

df.query('price > @limit') is evaluated inside a function that holds limit as a local variable. Why does this work?

  1. The @ prefix escapes the name, allowing identifiers that are not valid Python
  2. The @ prefix resolves the name in the caller's scope instead of as a column label Correct answer
  3. The @ prefix marks the referenced name as a pandas Series, so query can broadcast it
  4. The @ prefix disables parsing of the expression, passing it to Python's eval directly
MCQSEXAM Read explanation

What does groupby(...).apply(f) do with the grouping columns when f returns a DataFrame in pandas 2.x?

  1. It drops the grouping columns entirely, since apply only ever sees the remaining value columns
  2. It raises an error, because apply callbacks returning DataFrames are no longer supported
  3. It duplicates the keys as columns and as index levels, producing redundant result fields
  4. It prepends the group keys to the result index, so include_groups=False changes the output Correct answer
MCQSEXAM Read explanation

Under the copy-on-write semantics of pandas 2.x, df[df.a > 0]['b'] = 1 is executed. What is the effect?

  1. The whole column b is set to 1 for every row, since the mask is ignored here
  2. Nothing changes in df, because the chained assignment writes to a temporary copy Correct answer
  3. Column b is updated for the matching rows, exactly as an equivalent .loc assignment would
  4. A SettingWithCopyWarning is raised and the assignment is then silently applied
MCQSEXAM Read explanation