Machine Learning Practice, Quiz 2
Consider the following code for Ridge Regression:
from sklearn.linear_model import Ridgeimport numpy as np
X = np.array([[1, 2], [2, 4], [3, 6], [4, 8]])y = np.array([1, 2, 3, 4])
model = Ridge(alpha=10)model.fit(X, y)coefficients = model.coef_print(np.round(coefficients,2))What will be the output for the coefficients?
Consider the following code for **Ridge Regression**: from sklearn.linear_model import Ridge import numpy as np X = np.array([[1, 2], [2, 4], [3, 6], [4, 8]]) y = np.array([1, 2, 3, 4]) model = Ridge(alpha=10) model.fit(X, y) coefficients = model.coef_ print(np.round(coefficients,2)) What will be the output for the coefficients? Consider the following code for **Stochastic Gradient Descent (SGD) Classifier**: from sklearn.linear_model import SGDClassifier from sklearn.datasets import make_classification X_train, y_train = make_classification(n_samples=1000, n_features=20, n_classes=2, random_state=42) model = SGDClassifier(penalty='elasticnet', l1_ratio=0.5, alpha=0.01) model.fit(X_train, y_train) What is the significance of $l1\_ratio = 0.5$ in this context? Given the following code for **Polynomial Regression**: from sklearn.preprocessing import PolynomialFeatures from sklearn.linear_model import LinearRegression import numpy as np X = np.array([1, 2, 3, 4, 5]).reshape(-1, 1) y = np.array([1, 4, 9, 16, 25]) poly = PolynomialFeatures(degree=2, interaction_only=False) X_poly = poly.fit_transform(X) model = LinearRegression() model.fit(X_poly, y) y_pred = model.predict(X_poly) print(y_pred) What will be the output of the code?