InterviewStack.io LogoInterviewStack.io

Linear and Logistic Regression Implementation Questions

Covers the fundamentals and implementation details of linear regression for continuous prediction and logistic regression for binary or multiclass classification. Candidates should understand model formulation, hypothesis functions, and the intuition behind fitting a line or hyperplane for regression and using a sigmoid or softmax function for classification. Include loss functions such as mean squared error for regression and cross entropy loss for classification, optimization methods including gradient descent and variants, regularization techniques, feature engineering and scaling, metrics for evaluation such as mean absolute error and accuracy and area under curve, and hyperparameter selection and validation strategies. Expect discussion of practical implementation using numerical libraries and machine learning toolkits, trade offs and limitations of each approach, numerical stability, and common pitfalls such as underfitting and overfitting.

MediumTechnical
54 practiced
You have a binary classification problem with 0.5% positive class. Discuss strategies for training and evaluating logistic regression under severe class imbalance: resampling (oversample, undersample, SMOTE), class weighting in loss, threshold adjustment, metrics to optimize, and specialized loss functions like focal loss. Explain operational trade-offs for each approach.
MediumTechnical
64 practiced
You have a loop-based Python implementation of logistic regression that is too slow on 1M samples. Describe how you would profile the code, identify hotspots, and optimize it for speed. Include concrete optimizations: vectorization, memory layout, using BLAS-backed operations, dtype choices, batching, and when to move to GPU or PyTorch for further performance gains.
MediumTechnical
53 practiced
Derive the gradient of the cross entropy loss for the softmax multinomial logistic regression model. Show the derivation from the log-likelihood and express the result in vectorized form for a batch: how the gradient reduces to X^T (P - Y) where P are predicted softmax probabilities and Y are one-hot labels.
HardTechnical
52 practiced
Prove that the logistic (cross-entropy) loss for binary classification is convex in the model parameters. Provide the Hessian form and show it is positive semidefinite, and discuss the practical implications of convexity for optimization and global optimality. Also explain how adding L2 regularization affects convexity.
EasyTechnical
61 practiced
Implement a numerically stable sigmoid function in Python accepting NumPy arrays. Your implementation should avoid overflow for large positive or negative inputs and return probabilities in [0,1]. Include quick checks for inputs like 1000 and -1000 to demonstrate stability.

Unlock Full Question Bank

Get access to hundreds of Linear and Logistic Regression Implementation interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.