1. Home
  2. Subjects
  3. Data Science

Data Science MCQs · Page 22

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

Showing 526–550 of 1,613

make_pipeline(StandardScaler(), LogisticRegression()) is built. What keys does named_steps expose?

  1. step1 and step2, numbered in order
  2. scaler and clf, fixed default aliases
  3. It raises an error, because make_pipeline requires explicit names
  4. standardscaler and logisticregression, the lowercased class names 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

Why would you construct StandardScaler(with_mean=False)?

  1. Because without centring the transformed features are always positive and therefore easier to interpret
  2. Because with_mean=False switches to median and interquartile scaling instead of the ordinary mean
  3. Centring would densify a sparse matrix, so scaling by the standard deviation alone preserves sparsity Correct answer
  4. Sparse matrices cannot be divided by a scalar, so only centring is available for them in practice
MCQSEXAM Read explanation

What does train_test_split(X, y, stratify=y) guarantee?

  1. The training and test sets keep approximately the same class proportions as the full dataset Correct answer
  2. Only samples with non-missing labels are used, and rows with NaN labels are dropped
  3. Each class appears exactly once in the test set, regardless of how many samples it has
  4. The split is reproducible without setting random_state, because stratification fixes the seed
MCQSEXAM Read explanation

Why does putting StandardScaler and a classifier inside Pipeline prevent leakage during cross_val_score?

  1. Pipeline refits the scaler on every validation fold to check stability across the splits
  2. The pipeline scales the whole dataset once before splitting, which is equivalent and faster
  3. During each fold, fit runs on the training part only and transform is applied to the held-out part Correct answer
  4. Pipeline disables scaling during cross-validation entirely, so the scaler only runs on the final fit
MCQSEXAM Read explanation

A pipeline-free workflow calls scaler.fit_transform(X_test) before evaluating a model. What is the consequence?

  1. Test statistics leak into preprocessing, so the reported score is optimistically biased Correct answer
  2. No effect at all, because scaling cannot change model accuracy on any dataset
  3. It causes the model to underfit, lowering the reported score well below the true value
  4. The test set silently becomes the training set, so the model never sees genuinely new data
MCQSEXAM Read explanation

pd.concat([a, b], axis=1) is used on two frames whose indexes overlap only partially. What is the default result?

  1. Only labels present in both frames are kept, as an inner join on the index
  2. The frames are concatenated positionally and the index is ignored, so no alignment occurs
  3. The index union is used and missing labels produce NaN, as an outer join on the index Correct answer
  4. An error is raised because the indexes are not identical, and the frames must be reindexed
MCQSEXAM Read explanation

What caveat applies to df.copy(deep=True) for a column of dtype object holding Python lists?

  1. The data and index are copied, but the Python objects inside object columns are not recursively copied, so they remain shared Correct answer
  2. deep=True is not allowed for object dtype columns, because pandas cannot deep-copy arbitrary Python objects
  3. Every nested list is deep-copied, guaranteeing full independence, so mutating one frame never affects the contents of the other
  4. deep=True copies only the index and shares all of the column data, while deep=False copies the column arrays
MCQSEXAM Read explanation

What does converting a low-cardinality object column with astype('category') change?

  1. It converts every string to an interned string object, for faster hashing and lower memory use
  2. It stores integer codes plus a dictionary of categories, cutting memory and enabling ordered comparisons Correct answer
  3. It drops duplicate values from the column, keeping only the first occurrence of every distinct string value
  4. It permanently sorts the DataFrame by that column and rebuilds the row index in sorted order
MCQSEXAM Read explanation

What does pd.merge(left, right, how='outer', indicator=True) add to the result?

  1. A boolean column showing whether the join key was unique in both of the input frames
  2. It raises an error if any of the keys fail to match, instead of reporting them in the result
  3. It sorts the result by the join key automatically and resets the index of the output
  4. A _merge column whose values are left_only, right_only or both, showing each row's origin Correct answer
MCQSEXAM Read explanation

How does df.groupby('k')['x'].transform('mean') differ from .apply('mean')?

  1. Both return one row per group, differing only in the index name that the resulting object carries afterwards
  2. transform can only be used with user-defined functions, while apply also accepts built-in method strings
  3. transform returns a Series aligned to the original index with the same length, while apply returns one value per group Correct answer
  4. apply returns a column the same length as the input frame itself, while transform reduces the result to one row per group
MCQSEXAM Read explanation