“Regresi Lasso” Kode Jawaban

Implementasi regresi laso python

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

Regresi 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

Jawaban yang mirip dengan “Regresi Lasso”

Pertanyaan yang mirip dengan “Regresi Lasso”

Lebih banyak jawaban terkait untuk “Regresi Lasso” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya