1. Home
  2. Explore
  3. Computer Science
  4. Linear Regression with Scikit-Learn

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Linear Regression with Scikit-Learn

  • 125Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Linear Regression
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is the main goal of the practical machine learning course?

Tap to flipClick to flipspace

To teach beginners how to build, train, evaluate, and deploy machine learning models in Python using Scikit-Learn.

Or swipe the card

125 cards

  1. What is the main goal of the practical machine learning course?

    To teach beginners how to build, train, evaluate, and deploy machine learning models in Python using Scikit-Learn.

  2. What real-world problem is used to introduce linear regression?

    Predicting a new customer's annual medical expenses from features such as age, sex, BMI, children, smoking status, and region.

  3. What is the structure of a single-variable linear regression model for medical charges?

    The model assumes charges=w×age+b\text{charges} = w \times \text{age} + bcharges=w×age+b.

  4. What are the geometric meanings of www and bbb in y=wx+by = wx + by=wx+b?

    www is the slope, and bbb is the intercept.

  5. What are the machine learning names for the slope and intercept?

    The slope is often called a weight or coefficient, and the intercept is often called a bias.

  6. What are inputs and targets in the medical-expense model?

    Age is the input feature, and medical charges are the target.

  7. What is linear regression?

    A technique that models a target as a linear combination or weighted sum of input features.

  8. How does a linear regression model make a prediction after fitting?

    It multiplies each input feature by its learned weight, adds the results and the bias, and returns the total.

  9. What is a residual in regression?

    The difference between an actual target and the model's prediction.

  10. What is root mean squared error (RMSE)?

    RMSE is the square root of the average squared difference between targets and predictions: RMSE=1n∑i=1n(yi−y^i)2\mathrm{RMSE}=\sqrt{\frac{1}{n}\sum_{i=1}^{n}(y_i-\hat{y}_i)^2}RMSE=n1​∑i=1n​(yi​−y^​i​)2​.

  11. Why can RMSE give outliers a large influence?

    Because large errors are squared before being averaged.

  12. How does mean absolute error differ from RMSE?

    Mean absolute error averages absolute residuals instead of squared residuals, so outliers have less influence.

  13. What does a loss function measure in machine learning?

    It measures how poorly a model's predictions match the actual targets.

  14. What is gradient descent?

    An iterative optimization strategy that changes model parameters in the direction that reduces the loss.

  15. How does ordinary least squares differ from gradient descent?

    Ordinary least squares directly computes the best parameters using matrix operations, while gradient descent iteratively improves parameters.

  16. How is linear regression trained with Scikit-Learn?

    Create a LinearRegression object, call .fit(X, y), and use .predict() to generate predictions.

  17. Where are the learned parameters stored in a Scikit-Learn linear regression model?

    Feature weights are stored in model.coef_, and the intercept is stored in model.intercept_.

  18. Why might adding BMI barely improve a non-smoker medical-charge model?

    BMI has a weak relationship with charges in that subset, so its learned coefficient contributes little.

  19. How are categorical features converted for linear regression?

    Binary categories can be mapped to 000 and 111, while multi-category features are commonly one-hot encoded.

  20. What is binary encoding for a categorical feature?

    It replaces two categories with numerical indicators, such as no = 0 and yes = 1.

  21. What is one-hot encoding?

    It creates one binary column per category, with one column set to 111 and the others set to 000 for each row.

  22. Why are standardized coefficients easier to compare?

    Standardization puts numeric features on comparable scales, so coefficient magnitude better reflects relative influence.

  23. How are numeric features standardized?

    Subtract the feature mean and divide by its standard deviation: z=x−μσz = \frac{x-\mu}{\sigma}z=σx−μ​.

  24. What is the general machine learning training cycle?

    Choose a model, make predictions, compute a loss, optimize the parameters, and repeat until the model improves.

  25. What is the difference between classification and regression?

    Classification predicts discrete classes; regression predicts continuous numerical values.

  26. What is logistic regression used for?

    It is commonly used for binary classification problems.

  27. What dataset is used for the logistic regression example?

    The Rain in Australia dataset, containing roughly ten years of daily weather observations from Australian weather stations.

  28. What is the target in the Rain in Australia problem?

    The RainTomorrow value, indicating whether rainfall occurs on the following day.

  29. What is the sigmoid function's role in logistic regression?

    It transforms a linear combination of features into a value between 000 and 111.

  30. What is the basic logistic regression computation?

    First compute z=w1x1+w2x2+⋯+bz = w_1x_1 + w_2x_2 + \cdots + bz=w1​x1​+w2​x2​+⋯+b, then apply the sigmoid function σ(z)\sigma(z)σ(z).

  31. How are logistic regression predictions interpreted?

    The sigmoid output is interpreted as the probability that the input belongs to the positive class.

  32. What loss function is commonly used for logistic regression?

    Cross-entropy loss, also called log loss.

  33. What is the difference between logistic regression predictions and targets?

    Targets are class labels such as yes or no, while predictions are probabilities between 000 and 111 or converted class labels.

  34. What is class imbalance?

    Class imbalance occurs when one class has substantially more observations than another.

  35. Why can class imbalance make accuracy misleading?

    A model can achieve high accuracy by always predicting the majority class while performing poorly on the minority class.

  36. What is a confusion matrix?

    A table that counts true positives, true negatives, false positives, and false negatives.

  37. What is a true positive?

    A case where the actual class is positive and the model correctly predicts positive.

  38. What is a true negative?

    A case where the actual class is negative and the model correctly predicts negative.

  39. What is a false positive?

    A case where the actual class is negative but the model predicts positive.

  40. What is a false negative?

    A case where the actual class is positive but the model predicts negative.

  41. Why might false negatives matter more than false positives for outdoor event planning?

    A false negative could cause an event to proceed even though rain is expected, creating major practical problems.

  42. What does predict_proba() return for a classification model?

    It returns the predicted probability for each class.

  43. What is supervised learning?

    Learning from labeled examples that contain inputs and known targets.

  44. What is unsupervised learning?

    Learning patterns or structure from data without labeled target values.

  45. What are the training, validation, and test sets used for?

    The training set fits the model, the validation set guides model and hyperparameter choices, and the test set provides a final unbiased evaluation.

  46. Why should the test set be used only at the end?

    Using it repeatedly during development can cause the model or the practitioner's choices to overfit to the test data.

  47. What is overfitting?

    Overfitting occurs when a model performs very well on training data but poorly on unseen data.

  48. What is regularization?

    Regularization is the use of constraints or techniques to reduce overfitting.

  49. What is a time-based data split?

    A split that uses earlier observations for training and later observations for validation and testing.

  50. Why should dates often be split chronologically instead of randomly?

    Chronological splitting better simulates real deployment, where a model trained on past data predicts future data.

  51. What is data leakage?

    Data leakage occurs when information unavailable at prediction time, especially target-derived information, enters the model inputs.

  52. What is imputation?

    Imputation is the process of replacing missing values with estimated or designated values.

  53. When might median imputation be preferable to mean imputation?

    Median imputation is often preferable when a feature contains outliers that would distort the mean.

  54. Why are numeric features scaled?

    Scaling prevents features with large numerical ranges from disproportionately affecting optimization.

  55. What is feature engineering?

    Feature engineering is creating, transforming, or combining features to make useful patterns easier for a model to learn.

  56. What is a baseline model?

    A simple model or rule used as a minimum benchmark for evaluating more sophisticated models.

  57. Why should machine learning models be compared with a dumb baseline?

    To verify that the model has learned something useful and is better than a simple alternative.

  58. What is a decision tree?

    A hierarchical sequence of binary decisions that leads an input to a prediction.

  59. How does a machine learning decision tree differ from a manually written decision process?

    The machine learning algorithm learns the decision features and thresholds from data instead of receiving them manually.

  60. When should a decision tree classifier be used?

    When the target is a discrete class, such as rain/no rain.

  61. Why can an unrestricted decision tree overfit?

    It can keep splitting until individual leaves represent specific training examples.

  62. What does the Gini score measure in a decision tree?

    It measures the impurity or quality of a split.

  63. How does a decision tree choose a split?

    It evaluates candidate features and thresholds and selects a split that produces a low impurity score.

  64. What is a leaf node?

    A terminal node of a decision tree that provides the final prediction.

  65. What does max_depth control in a decision tree?

    It limits the maximum number of decision levels in the tree.

  66. What does max_leaf_nodes control?

    It limits the number of terminal leaves that the decision tree may create.

  67. What are hyperparameters?

    Settings chosen before or during model training rather than learned directly as model parameters.

  68. How can the best decision-tree depth be selected?

    Train trees with different depths and choose a depth where validation error is minimized before overfitting begins.

  69. What is a random forest?

    An ensemble of decision trees whose predictions are combined.

  70. Why can a random forest outperform an individual decision tree?

    Different trees make different errors, and combining them can cancel out some errors.

  71. What is bagging in a random forest?

    Bagging trains models on bootstrap samples created by random sampling with replacement.

  72. What does n_estimators control in a random forest?

    It controls the number of decision trees in the forest.

  73. What does max_features control in a random forest?

    It controls how many features are considered when searching for each tree split.

  74. How are feature importances used in tree models?

    They indicate how much each feature contributes to making useful splits across the model.

  75. What is gradient boosting?

    An ensemble method that sequentially adds weak models to correct the errors of the current model.

  76. What is the initial prediction in a gradient boosting regressor?

    The initial prediction is usually the mean of the target values.

  77. What does the first tree in gradient boosting learn?

    It learns to predict the residuals or errors of the initial mean prediction.

  78. How are later trees used in gradient boosting?

    Each later tree predicts the remaining errors after combining the previous prediction with earlier trees.

  79. What is the learning rate in gradient boosting?

    It scales the contribution of each newly added tree.

  80. Why is gradient boosting called boosting?

    Because each new model improves or boosts an existing ensemble by correcting its errors.

  81. Why is gradient boosting called gradient boosting?

    Because the iterative error-reduction process is related to minimizing a loss through gradient-based optimization.

  82. What is XGBoost?

    A high-performance library that implements gradient-boosted tree models.

  83. What do max_depth, n_estimators, and learning_rate control in XGBoost?

    max_depth controls tree complexity, n_estimators controls the number of trees, and learning_rate controls each tree's contribution.

  84. What is K-fold cross-validation?

    A validation technique that divides data into KKK parts and trains KKK models, using a different part for validation each time.

  85. Why can K-fold cross-validation be unsuitable for time-series data?

    Random folds can allow future observations to influence evaluation of past observations.

  86. What is ensembling?

    Ensembling combines predictions from multiple models to produce a final prediction.

  87. What is stacking?

    Stacking trains a second model to combine the predictions of several first-level models.

  88. What is clustering?

    Clustering groups observations so that points within the same group are more similar to each other than to points in other groups.

  89. What is the key difference between classification and clustering?

    Classification assigns inputs to known labeled classes, while clustering discovers groups without predefined labels.

  90. What is K-means clustering?

    An algorithm that assigns observations to a predetermined number KKK of clusters based on proximity to cluster centers.

  91. What are the main steps of K-means clustering?

    Choose KKK, initialize centers, assign points to the nearest center, recompute centroids, reassign points, and repeat.

  92. What is a centroid in K-means?

    The mean position of all points assigned to a cluster.

  93. What is inertia in K-means clustering?

    The total within-cluster squared distance or variance from points to their assigned centroids.

  94. What is an elbow curve used for?

    It helps choose the number of K-means clusters by plotting inertia against KKK and locating the point where improvement begins to level off.

  95. What is DBSCAN?

    A density-based clustering algorithm that groups points in dense regions and identifies isolated points as noise.

  96. What do eps and min_samples control in DBSCAN?

    eps defines the neighborhood radius, and min_samples defines how many nearby points are needed for a core point.

  97. What are core, reachable, and noise points in DBSCAN?

    A core point has enough neighbors, a reachable point lies near a core point but may lack enough neighbors itself, and a noise point belongs to no cluster.

  98. What is hierarchical clustering?

    A method that builds a hierarchy of nested clusters by repeatedly combining the closest clusters.

  99. What is dimensionality reduction?

    Reducing the number of features while attempting to preserve important information or structure.

  100. What is principal component analysis (PCA)?

    A dimensionality-reduction technique that projects data onto new orthogonal directions chosen to preserve as much variance as possible.

  101. What does PCA maximize when selecting its first component?

    It maximizes the variance of the projected data.

  102. What is t-SNE mainly used for?

    Visualizing high-dimensional data in two or three dimensions while preserving local neighborhood relationships.

  103. How does PCA differ from t-SNE?

    PCA uses linear projections, whereas t-SNE performs nonlinear manifold learning focused on preserving local similarities.

  104. What are the main steps in a machine learning project?

    Understand the business problem, inspect the data, define the task and metric, clean and engineer features, split the data, build baselines, train and tune models, evaluate, interpret, deploy, and monitor.

  105. Why should business requirements be understood before modeling?

    They determine whether machine learning is appropriate, what kind of model is needed, which errors matter, and how success will be measured.

  106. What questions should be asked about the business problem?

    Ask what problem is being solved, why it matters, how it is currently solved, who uses the output, what impact is expected, and what level of accuracy is sufficient.

  107. Why must the evaluation metric be agreed upon with stakeholders?

    Different applications value different outcomes, such as low average error, high recall, or few false positives.

  108. What is the purpose of exploratory data analysis?

    To understand distributions, identify errors and missing values, discover relationships, and generate ideas for feature engineering.

  109. Why should input and target columns be explicitly separated?

    To prevent accidentally using the target or target-derived information as an input.

  110. Why should experiments be tracked systematically?

    Recording models, features, hyperparameters, metrics, and conclusions prevents confusion and makes results reproducible.

  111. Why should individual predictions and errors be inspected?

    They reveal patterns that aggregate metrics may hide, including systematic errors, unusual cases, and unintended correlations.

  112. What should be communicated when presenting a machine learning model?

    Explain the objective, relevant metrics, important features, strengths, limitations, representative predictions, and possible improvements.

  113. Why should deployed models be monitored?

    Data distributions, user behavior, and business conditions can change, causing model performance to deteriorate.

  114. What is the purpose of saving preprocessing objects along with a trained model?

    New inputs must undergo exactly the same imputation, scaling, encoding, and column ordering used during training.

  115. What is joblib used for in machine learning workflows?

    It saves and loads Python objects such as trained models, imputers, scalers, encoders, and column lists.

  116. What is Flask?

    A Python web framework used to create web applications and HTTP routes.

  117. What is a Flask route?

    A URL path associated with a Python function that handles requests.

  118. What is the difference between GET and POST requests?

    GET usually retrieves a resource, while POST sends data to the server for processing.

  119. What are HTML templates used for in Flask?

    They define the webpage structure that Flask renders and sends to the browser.

  120. How can a Flask app integrate a spam classifier?

    Receive the email text, apply the saved vectorizer, call the saved classifier, and render the predicted spam or non-spam result.

  121. What is an API route for a machine learning model?

    A route that accepts structured input, such as JSON, and returns a structured prediction, such as JSON.

  122. Why should a deployment environment be isolated?

    An isolated environment keeps project dependencies and versions separate from other projects.

  123. What is the purpose of a requirements.txt file?

    It lists the Python packages and versions required to install and run the application.

  124. What is the typical workflow for deploying a Flask model application?

    Create the application, test it locally, save dependencies, commit the code to GitHub, connect the repository to a cloud platform, deploy, and test the live URL.

  125. What is the difference between a model's training performance and its production performance?

    Training performance is measured on data the model has seen, while production performance is measured on new, potentially different data.

Card 1 of 125
Card 1 of 125

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent