# Recursive feature elimination

# Load libraries
from sklearn.datasets import make_regression
from sklearn.feature_selection import RFECV
from sklearn import datasets, linear_model
import warnings

# Suppress an annoying but harmless warning
warnings.filterwarnings(action="ignore", module="scipy", message="^internal gelsd")
 
# Generate features matrix, target vector, and the true coefficients
X, y = make_regression(n_samples = 10000,
                       n_features = 100,
                       n_informative = 2,
                       random_state = 1)
 
# Create a linear regression
ols = linear_model.LinearRegression()
 
# Create recursive feature eliminator that scores features by mean squared errors
rfecv = RFECV(estimator=ols, step=1, scoring='neg_mean_squared_error')

# Fit recursive feature eliminator 
rfecv.fit(X, y)

# Recursive feature elimination
rfecv.transform(X)

# Number of best features
rfecv.n_features_
cde075c531e235a9193c52fea4e1fc8867b4cb3f
<mask token>

<mask token>
warnings.filterwarnings(action='ignore', module='scipy', message=
    '^internal gelsd')
<mask token>
rfecv.fit(X, y)
rfecv.transform(X)
rfecv.n_features_

<mask token>
warnings.filterwarnings(action='ignore', module='scipy', message=
    '^internal gelsd')
X, y = make_regression(n_samples=10000, n_features=100, n_informative=2,
    random_state=1)
ols = linear_model.LinearRegression()
rfecv = RFECV(estimator=ols, step=1, scoring='neg_mean_squared_error')
rfecv.fit(X, y)
rfecv.transform(X)
rfecv.n_features_

from sklearn.datasets import make_regression
from sklearn.feature_selection import RFECV
from sklearn import datasets, linear_model
import warnings
warnings.filterwarnings(action='ignore', module='scipy', message=
    '^internal gelsd')
X, y = make_regression(n_samples=10000, n_features=100, n_informative=2,
    random_state=1)
ols = linear_model.LinearRegression()
rfecv = RFECV(estimator=ols, step=1, scoring='neg_mean_squared_error')
rfecv.fit(X, y)
rfecv.transform(X)
rfecv.n_features_

# Recursive feature elimination

# Load libraries
from sklearn.datasets import make_regression
from sklearn.feature_selection import RFECV
from sklearn import datasets, linear_model
import warnings

# Suppress an annoying but harmless warning
warnings.filterwarnings(action="ignore", module="scipy", message="^internal gelsd")
 
# Generate features matrix, target vector, and the true coefficients
X, y = make_regression(n_samples = 10000,
                       n_features = 100,
                       n_informative = 2,
                       random_state = 1)
 
# Create a linear regression
ols = linear_model.LinearRegression()
 
# Create recursive feature eliminator that scores features by mean squared errors
rfecv = RFECV(estimator=ols, step=1, scoring='neg_mean_squared_error')

# Fit recursive feature eliminator 
rfecv.fit(X, y)

# Recursive feature elimination
rfecv.transform(X)

# Number of best features
rfecv.n_features_