-
-
Save sazio/62a8ba3a25de7fbed39ef071fa582004 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# linear regression feature importance | |
from sklearn.linear_model import LinearRegression | |
from matplotlib import pyplot as plt | |
# define the model | |
model = LinearRegression() | |
# fit the model | |
model.fit(X_reg, y_reg) | |
# get importance | |
importance = model.coef_ | |
# summarize feature importance | |
for i,v in enumerate(importance): | |
print('Feature: %0d, Score: %.5f' % (i,v)) | |
# plot feature importance | |
plt.figure(figsize = (10,6)) | |
plt.bar([x for x in range(len(importance))], importance) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment