1. Home
  2. Subjects
  3. Data Science
  4. Scikit-learn

Scikit-learn MCQs · Page 2

73 multiple choice questions with answers in Data Science.

Showing 26–50 of 73

What does setting random_state in train_test_split guarantee?

  1. The rows are shuffled in place, so the original DataFrame's order is permanently changed
  2. The same split is produced on repeated runs with the same inputs and library version Correct answer
  3. Every run is statistically independent, so no split pattern can ever repeat itself
  4. The split is stratified automatically, keeping class proportions in both partitions
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

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