Machine Learning Practice, End Term
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?
import numpy as npfrom sklearn.preprocessing import MinMaxScaler, OneHotEncoderfrom sklearn.compose import ColumnTransformer
X = np.array([[2.0, 'apple'], [5.0, 'banana'], [1.0, 'apple'], [4.0, 'cherry']])
preprocessor = ColumnTransformer( transformers=[('num', MinMaxScaler(), [0]), ('cat', OneHotEncoder(), [1])])
X_transformed = preprocessor.fit_transform(X)print(X_transformed[0])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? import numpy as np from sklearn.preprocessing import MinMaxScaler, OneHotEncoder from sklearn.compose import ColumnTransformer X = np.array([[2.0, 'apple'], [5.0, 'banana'], [1.0, 'apple'], [4.0, 'cherry']]) preprocessor = ColumnTransformer( transformers=[('num', MinMaxScaler(), [0]), ('cat', OneHotEncoder(), [1])]) X_transformed = preprocessor.fit_transform(X) print(X_transformed[0]) Consider the following code snippet: from sklearn.datasets import fetch_california_housing from sklearn.decomposition import PCA from sklearn.preprocessing import StandardScaler, PolynomialFeatures from sklearn.pipeline import Pipeline, FeatureUnion data = fetch_california_housing() X = data.data polynomial_transform = PolynomialFeatures(degree=2, include_bias=False) pca_transform = PCA(n_components=5) scaler = StandardScaler() combined_features = FeatureUnion([ ('poly', polynomial_transform), ('pca', pca_transform)]) pipeline = Pipeline([ ('features', combined_features), ('scaler', scaler)]) X_transformed = pipeline.fit_transform(X) print(X_transformed.shape) If the shape of `X` is $(20640, 8)$, what will be the shape of `X_transformed`? Consider you are using a Dummy Regression with `strategy=mean`. Consider the following dataset. | S.No | $X_1$ | $X_2$ | $X_3$ | $Y$ | |---|---|---|---|---| | 1 | 3.1 | 5.2 | 4.0 | 14.2 | | 2 | 2.7 | 4.8 | 3.5 | 13.7 | | 3 | 3.3 | 5.0 | 4.2 | 15.1 | | 4 | 2.9 | 4.5 | 3.8 | 12.9 | | 5 | 3.0 | 4.7 | 3.9 | 13.5 | | 6 | 3.2 | 5.1 | 4.1 | 14.5 | What will be the predicted output for an input $X = [3.0, 4.9, 3.9]$ ?