Home / Past papers / MLP End Term / this paper
What will be the output of the following code:
What will be the numerical value in the output array of the following code: 












Given the following code snippet that preprocesses a dataset with both continuous and categorical features using sklearn.preprocessing tools, what will be the first row of the X transformed array after preprocessing? 





















You’re working on a binary classification task using the ‘MLPClassifier’ to predict whether a customer will make a purchase based on their browsing behavior.You’re concerned about overfitting due to the complexity of the model. You decide to increase the ‘alpha’ parameter to control overfitting. The following code snippet shows the application of ‘MLPClassifier’: 
Using the confusion matrix given below. What is the precision score for the label (class) 1 ? 

Fill in the missing parameter value in the following estimator that can be used to classify the data 






















You’re working with a dataset of customer purchase behavior, including attributes “Total Amount Spent” and “Number of Items Purchased.” You decide to use K-means clustering to segment customers into groups based on these features. The following code snippet demonstrates the K-means clustering process: Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here’s a structured summary of core topics, concepts, principles, and equations essential for the Diploma Level: Machine Learning Practice (Computer-Based Exam). The exam covers data preprocessing, supervised/unsupervised learning, model evaluation, and neural networks, with a focus on scikit-learn implementations.
Scaling/Normalization
Standardization (StandardScaler): Transforms data to have mean = 0 and variance = 1.
Max-Abs Scaling (MaxAbsScaler): Scales data to [-1, 1] by dividing by the maximum absolute value.
Min-Max Scaling: Scales data to [0, 1].
Handling Missing Data
SimpleImputer: Replaces missing values with mean, median, or mode.
SimpleImputer(strategy='mean')Categorical Encoding
LabelEncoder: Converts categorical labels to numeric (0, 1, 2, ...).
encoder.fit_transform(["cat", "dog", "fish"]) → [0, 1, 2]MultiLabelBinarizer: Converts categorical labels to binary vectors.
Example:
mlb = MultiLabelBinarizer(classes=['cold', 'hot', 'large', 'small'])
mlb.fit_transform([['large', 'cold'], ['small', 'hot']])
Output:
[[1, 0, 1, 0], [0, 1, 0, 1]]Polynomial Features
PolynomialFeatures: Generates interaction terms and polynomial features.
PolynomialFeatures(degree=2, interaction_only=True)[a, b], output includes [a, b, a*b] (if interaction_only=True).Pipelines & Feature Unions
Pipeline: Chains multiple preprocessing steps.
Example:
pipe = Pipeline([
('impute', SimpleImputer(strategy='mean')),
('scale', StandardScaler())
])FeatureUnion: Combines multiple feature transformations.
Example:
combined = FeatureUnion([
('poly', PolynomialFeatures(degree=2)),
('pca', PCA(n_components=2))
])Linear Models
Linear Regression:
fit_intercept=False → No bias term ().
predict_proba() → Returns class probabilities.Regularization:
C (inverse of regularization strength): Smaller C → stronger regularization.penalty='l1' (Lasso) or 'l2' (Ridge).Solvers:
liblinear: Good for small datasets + L1/L2.sag, saga: Good for large datasets.lbfgs, newton-cg: Default for multiclass.Naive Bayes
GaussianNB: Assumes features follow a normal distribution.
predict_proba() → Returns posterior probabilities.k-Nearest Neighbors (KNN)
Hyperparameters:
n_neighbors: Low value → complex boundaries (prone to overfitting).weights='uniform' (all neighbors equal) or 'distance' (weight by inverse distance).metric='euclidean' (default) or 'manhattan'.StandardScaler).Support Vector Machines (SVM)
Kernel Trick: Transforms data into higher dimensions.
kernel='linear', 'rbf', 'poly'.C controls margin strictness.Neural Networks (MLP)
MLPClassifier:
hidden_layer_sizes=(n1, n2): Number of neurons in hidden layers.activation='relu', 'tanh', 'logistic'.alpha: L2 regularization (higher → more regularization).solver='adam' (default), 'sgd', 'lbfgs'.Overfitting Control:
alpha → stronger regularization.Clustering
K-Means:
n_clusters=K: Number of clusters.labels_: Cluster assignments for each point.cluster_centers_: Coordinates of centroids.Hierarchical Clustering:
Linkage Methods:
complete (max distance), average, single (min distance), ward (min variance).Dimensionality Reduction
PCA (Principal Component Analysis):
PCA(n_components=2)Confusion Matrix
Regularization
Bias-Variance Tradeoff
Bagging (Bootstrap Aggregating)
BaggingClassifier: Trains multiple models on random subsets of data.Example:
BaggingClassifier(base_estimator=KNeighborsClassifier(), n_estimators=10)max_samples=0.5: Each estimator uses 50% of samples.Random Forest
RandomForestClassifier:
n_estimators: Number of trees.max_features: Features considered for splits (default=sqrt(n_features)).CountVectorizer
fit_transform(corpus) → Returns (n_documents, n_unique_words) matrix.TF-IDF (Term Frequency-Inverse Document Frequency)
| Concept | Equation |
|---|---|
| Standard Scaling | |
| Max-Abs Scaling | |
| Min-Max Scaling | |
| Linear Regression | |
| Logistic Regression (Sigmoid) | |
| Precision | |
| Recall | |
| F1-Score | |
| L1 Regularization (Lasso) | |
| L2 Regularization (Ridge) | |
| Polynomial Features (Degree 2) |
Focus Areas:
Common Pitfalls:
C in LogisticRegression/SVM = stronger regularization.n_clusters and check labels_/cluster_centers_.interaction_only=True excludes higher-degree terms for single features.# K-Means kmeans = KMeans(n_clusters=3) kmeans.fit(data) labels = kmeans.labels_
# Logistic Regression with L1 model = LogisticRegression(penalty='l1', solver='liblinear')
# Pipeline pipe = Pipeline([ ('impute', SimpleImputer()), ('scale', StandardScaler()), ('model', LogisticRegression()) ]) ```
This summary covers 90% of the exam content. Focus on scikit-learn implementations, preprocessing steps, and model evaluation metrics for high scores!