You are on page 1of 1

Practical No.

4 [Type here] 1

Program:-
import pandas as pd
import fsspec
import numpy as np
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
data = pd.read_csv("E://test1.csv")
X=data.iloc[:,1:20]
y = data.iloc[:,-1]
print(X,y)

bestfeatures = SelectKBest(score_func=chi2, k=13)


fit = bestfeatures.fit(X,y)
print(fit)
dfscores = pd.DataFrame(fit.scores_)
dfcolumns = pd.DataFrame(X.columns)
#concat two dataframes for better visualization
featureScores = pd.concat([dfcolumns,dfscores],axis=1)
featureScores.columns = ['Specs','Score'] #naming the dataframe
columns
print(featureScores.nlargest(10,'Score')) #print 10 best features

Output:-

SelectKBest(k=13, score_func=<function chi2 at 0x00000069DB063670>)

Specs Score

12 px_width 852.914979

13 ram 562.837207

11 px_height 46.347162

8 mobile_wt 42.328627

4 fc 15.793117

10 pc 11.148155

6 int_memory 1.372252

2 clock_speed 1.052762

15 sc_w 0.809077

16 talk_time 0.760553

Artificial Intelligence & Machine Learning Mechanical Engineering Department

You might also like