“Regresja Lasso” Kod odpowiedzi

Python wdrażania regresji Lasso

from sklearn.linear_model import Lasso
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()

X_train, X_test, y_train, y_test = train_test_split(X_data, y_data,
                                                   random_state = 0)

X_train_scaled = scaler.fit_transform(X_train)
X_test_scaled = scaler.transform(X_test)

linlasso = Lasso(alpha=2.0, max_iter = 10000).fit(X_train_scaled, y_train)
Fantastic Ferret

Regresja Lasso

# Import Lasso
from sklearn.linear_model import Lasso

# Instantiate a lasso regressor: lasso
lasso = Lasso(alpha=0.4, normalize=True)

# Fit the regressor to the data
lasso.fit(X, y)

# Compute and print the coefficients
lasso_coef = lasso.coef_
print(lasso_coef)

# Plot the coefficients
plt.plot(range(len(df_columns)), lasso_coef)
plt.xticks(range(len(df_columns)), df_columns.values, rotation=60)
plt.margins(0.02)
plt.show()
josh.ipynb

Odpowiedzi podobne do “Regresja Lasso”

Pytania podobne do “Regresja Lasso”

Więcej pokrewnych odpowiedzi na “Regresja Lasso” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu