Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Document preview thumbnail
Preview 4 out of 34 pages
Exam (elaborations)

MACHINE LEARNING |COMPLETE STUDY GUIDE WITH 100% ACCURATE QUESTIONS & ANSWERS | ACE EVERY TEST | GUARANTEED EXCELLENCE.

Document preview thumbnail
Preview 4 out of 34 pages

MACHINE LEARNING |COMPLETE STUDY GUIDE WITH 100% ACCURATE QUESTIONS & ANSWERS | ACE EVERY TEST | GUARANTEED EXCELLENCE.

Content preview

MACHINE LEARNING |COMPLETE STUDY GUIDE WITH
100% ACCURATE QUESTIONS & ANSWERS | ACE EVERY
TEST | GUARANTEED EXCELLENCE.
Clean the Data. Most machine learning algorithms cannot work with missing features. We have
3 options to fix this. One of them to - set the missing values to some value (zero, the mean, the
median, etc.). How is it called? Answer: imputation
We can fit the imputer instance to the training data using which methond?
imputer.___(housing_num) Answer: fit
The imputer has simply computed the median of each attribute and stored the result in which
instance variable? Answer: statistics_
Which strategies of SimpleImputer can be used to fill missing values in numerical data?
Answer: mean, median,most_frequent,constant
Which strategies of SimpleImputer can be used to fill missing values in non-numerical
(categorical) data? Answer: most_frequent, constant
Since the median can only be computed on numerical attributes, you then need to create a copy
of the data with only the numerical attributes.
housing_num = housing.select_dtypes(include = [_____]) Answer: np.number
In scikit-learn, there are objects designed specifically to modify or preprocess data before
feeding it into a predictive model, such as scaling numerical features, encoding categorical
variables, or filling missing values. What are these objects called? Answer: Transformers
If you want to first learn the necessary statistics from your dataset and then immediately apply
a transformation in scikit-learn, which method would you use? Answer: fit_transform
Which two scikit-learn transformers would you use to fill missing values, one with a simple
statistical approach and another with a more advanced method using regression models or
nearest neighbors? Answer: SimpleImputer and IterativeImputer / KNNImputer




APPHIA – Crafted with Care and Precision for Academic Excellence.

1

,After applying a transformer to a DataFrame and obtaining a NumPy array, how can you
restore the original column names and indices in the transformed data? Answer: Wrap it in a
DataFrame with the original columns and index
What is the purpose of the Python library pandas and what are its main data structures for
handling tabular data? Answer: Pandas is used for storing, analyzing, and processing tabular
data. Its main data structures are DataFrame (table) and Series (one-dimensional array with an
index).
What is NumPy for? Answer: For fast numerical computations and working with arrays in
Python.
Most machine learning algorithms prefer to work with numbers, so to convert these categories
from text to numbers while preserving meaning we can use which two common methods?
Answer: One hot Encoding & Ordinal Encoding
What is the purpose of Ordinal Encoding? Answer: It assigns integer values to categorical
data.
Give an example of Ordinal Encoding. Answer: "low" → 0, "medium" → 1, "high" → 2.
How can you access the categories used in Ordinal Encoding? Answer: Using the categories_
instance variable.
What does the categories_ variable contain? Answer: A list of 1D arrays of categories for each
categorical attribute.
Что должно быть в пропущенном месте:
from sklearn.impute import SimpleImputer
imputer = SimpleImputer(_____= 'median') Answer: strategy
What is a binary column in the context of encoding? Answer: A column that can only take two
values: 0 or 1.
Which encoding technique creates binary columns for each category? Answer: One-hot
encoding.
What are the new attributes created by one-hot encoding sometimes called? Answer: Dummy
attributes.


APPHIA – Crafted with Care and Precision for Academic Excellence.

2

,Which Scikit-Learn class is used for one-hot encoding? Answer: OneHotEncoder
What type of values does OneHotEncoder produce? Answer: One-hot vectors (binary 0 or 1
columns).
What is a sparse matrix? Answer: A matrix that stores only non-zero elements and their
positions, saving memory.
How does a sparse matrix differ from a NumPy array? Answer: A NumPy array stores all
elements including zeros, while a sparse matrix stores only non-zero values.
How can you see the full contents of a sparse matrix? Answer: By converting it to a NumPy
array using .toarray().
Why use sparse matrices after one-hot encoding? Answer: Because one-hot encoding
produces many zeros, and sparse matrices save memory.
What does "dense" mean in the context of a NumPy array? Answer: It means the array stores
all elements, including zeros, unlike a sparse matrix that stores only non-zero values.
What does fit() do in machine learning? Answer: It learns parameters or rules from the data.
What does transform() do? Answer: It applies the learned parameters to transform the data.
What does setting sparse=False do when creating a OneHotEncoder in scikit-learn? Answer: It
makes the transform() method return a dense NumPy array instead of a sparse matrix.
Alternatively, you can set _____ when creating the OneHotEncoder, in which case the
transform() method will return a regular (dense) NumPy array directly. Answer: sparse = False
How to set sparse=False when creating the OneHotEncoder
cat_encoder = OneHotEncoder(___ = False) Answer: sparse_output
As with the OrdinalEncoder, you can get the list of categories using the encoder's which
instance variable? Answer: categories_
Advantages of using One-Hot Encoding? Answer: No assumption of order.
Works well for nominal categories (no natural ranking).
Prevents misleading relationships.
Disadvantages of using One-Hot Encoding? Answer: Increases dimensionality (many columns
if category has many unique values).


APPHIA – Crafted with Care and Precision for Academic Excellence.

3

, What does pandas.get_dummies() do? Answer: Converts categorical columns into binary (0/1)
columns.
Write the pandas function that automatically converts categorical columns into dummy
variables (binary 0/1 columns). It is similar to a one-hot representation. Answer:
pandas.get_dummies()
from sklearn.preprocessing import OneHotEncoder
import pandas as pd
df_train = pd.DataFrame({"ocean_proximity": ["NEAR BAY", "INLAND", "NEAR BAY"]})
df_test = pd.DataFrame({"ocean_proximity": ["NEAR BAY", "INLAND", "<2H OCEAN"]})
encoder = OneHotEncoder()
encoder.fit(df_train)
encoder.transform(df_test).toarray()
Will this code throw an error? Why or why not? Answer: Yes, it will throw an error. The
reason is that df_test contains a category ("<2H OCEAN") that was not seen during training
(df_train). By default, OneHotEncoder raises an error for unknown categories. To avoid this,
you can set handle_unknown="ignore".
By default, the output of a OneHotEncoder is a SciPy sparse matrix, instead of a NumPy array
. A sparse matrix is a very efficient representation for matrices that contain mostly zeros. You
can use a sparse matrix mostly like a normal 2D array,⁠ but if you want to convert it to a (dense)
NumPy array, just call the which method? Answer: toarray()
The advantage of OneHotEncoder from pandas.get_dummies() ? Answer: It remembers which
categories it was trained on.
OneHotEncoder is smarter: it will detect the unknown category and raise an exception. . If you
prefer, you can set what ? In which case it will just represent the unknown category with zero .
Answer: handle_unknown hyperparameter to "ignore
What's the difference between feature_names_in_ and categories_ in OneHotEncoder?
Answer: feature_names_in_ = column names; categories_ = unique values in each column.



APPHIA – Crafted with Care and Precision for Academic Excellence.

4

Document information

Uploaded on
August 3, 2026
Number of pages
34
Written in
2026/2027
Type
Exam (elaborations)
Contains
Questions & answers
$14.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Seller avatar
Apphia
3.0
(2)
Sold
5
Followers
0
Items
3652
Last sold
2 weeks ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions