Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Before training a model or feed a model, first priority is on data,not in model. The more data is preprocessed and engineered the more model will learn. Feature selectio one of the methods processing data before feeding the model. Various feature selection techniques is shown here.

NotificationsYou must be signed in to change notification settings

rakibhhridoy/MachineLearning-FeatureSelection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Step By step

  1. importing libraries & functions
importpandasaspdimportnumpyasnpimportmatplotlib.pyplotaspltfromsklearn.linear_modelimportLassofromsklearn.model_selectionimportGridSearchCVfromsklearn.feature_selectionimportSelectKBestfromsklearn.feature_selectionimportf_classiffromsklearn.ensembleimportExtraTreesClassifierfromsklearn.decompositionimportPCAimportosfromsklearn.feature_selectionimportRFEfromsklearn.linear_modelimportLogisticRegression
  1. loading datasets
file=os.getcwd()+"/datasets_228_482_diabetes.csv"names= ['preg','plas','pres','skin','test','mass','pedi','age','class']df=pd.read_csv(file,names=names)array=df.valuesX=array[:,0:8]y=array[:,8]
  1. Different feature selection techniques:

SelectKBest

test=SelectKBest(score_func=f_classif,k=4)fit=test.fit(X,y)features=fit.transform(X)corr_p=df['skin'].corr(df['class'])print(corr_p)print(features[0:5,:])model=LogisticRegression(solver='lbfgs')rfe=RFE(model,3)fit=rfe.fit(X,y)print('Num features: %d'%fit.n_features_)print('Selected features: %s'%fit.support_)print('feature ranking: %s'%fit.ranking_)

ExtraTreeClasssifier

model=ExtraTreesClassifier(n_estimators=10)model.fit(X,y)print(model.feature_importances_)

Dimensionality Reduction- PCA

pca=PCA(n_components=3)fit=pca.fit(X,y)print('Explained Variance: %s'%fit.explained_variance_ratio_)print(fit.components_)

best params and score findings

lasso=Lasso()parameters= {'alpha': [1e-15,1e-10,1e-8,1e-4,1e-3,1e-2,1,5,10,20]}lasso_regressor=GridSearchCV(lasso,parameters,scoring='neg_mean_squared_error',cv=5)lasso_regressor.fit(X,y)print(lasso_regressor.best_params_)print(lasso_regressor.best_score_)

Get Touch With Me

Connect-Linkedin
Website-RakibHHridoy

About

Before training a model or feed a model, first priority is on data,not in model. The more data is preprocessed and engineered the more model will learn. Feature selectio one of the methods processing data before feeding the model. Various feature selection techniques is shown here.

Topics

Resources

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp