Appendix C: Sample problems and solutions
Instructions for customization
This section is optional and is intended for a collection of practice problems with detailed solutions to aid in understanding and application of complex concepts (the example question below is relevant to computer science).
Use the template structure provided to maintain consistency in your examples. After making your edits, save and review.
Once you have completed your sample problems and solutions section, delete this instruction box.
Practice Problem A
This practice problem and solution demonstrate the application of logistic regression, a fundamental AI concept, to solve a binary classification problem.
Consider a simple binary classification problem where you have a dataset containing information about student performance (features) and whether they passed or failed (label). You want to build a machine learning model to predict whether a student will pass or fail based on their performance features.
The dataset
Features:
- Hours spent studying (continuous)
- Previous test scores (continuous)
- Attendance percentage (continuous)
Label:
Pass (1) or Fail (0)
Your task is to build a logistic regression model to predict whether a student will pass or fail based on the provided features.
The solution
Step 1: Data preprocessing
- Load the dataset and split it into features (X) and labels (y).
- Split the dataset into training and testing sets (e.g., 80% for training, 20% for testing).
Step 2: Model training
- Import the logistic regression model from a machine learning library (e.g., scikit-learn).
- Initialize the logistic regression model.
- Fit the model to the training data (X_train, y_train) using the .fit() method.
Step 3: Model evaluation
- Predict the labels for the testing data (X_test) using the .predict() method.
- Evaluate the performance of the model using metrics such as accuracy, precision, recall, and F1-score.
- You can use classification_report from sklearn.metrics for a detailed performance evaluation.
Step 4: Interpretation
- Examine the coefficients of the logistic regression model to understand the importance of each feature in predicting student outcomes.
- Visualize the decision boundary to understand how the model separates pass and fail instances in the feature space.
Example Code (using Python and scikit-learn):