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

Scikit-learn MCQs

73 multiple choice questions with answers in Data Science.

Scikit-learn MCQs covering model training, pipelines, preprocessing, cross-validation, metrics and common estimators, with the correct answer and a brief explanation for each question. Suitable for students, job tests and technical interviews.

Showing 1–25 of 73

SelectKBest is configured with score_func=chi2 and fitted on a design matrix that contains negative values. What happens?

  1. It raises an error, because chi-squared scoring needs non-negative features Correct answer
  2. It silently takes absolute values before computing the chi-squared scores
  3. It works but ranks the negative features last regardless of their true signal
  4. It standardises the features first, which makes every value non-negative
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

Teacher or blogger? Put this quiz on your website

Free Scikit-learn MCQs quiz with answers for your school site, academy page or blog. Copy one line of code – works on WordPress and Blogger.

Get the quiz widget

All 73 Scikit-learn questions

Show the full list of questions in this topic