<jupyter_start><jupyter_text>DescriptionFor Each Attribute: (all numeric-valued)   1. Number of times pregnant   2. Plasma glucose concentration a 2 hours in an oral glucose tolerance test   3. Diastolic blood pressure (mm Hg)   4. Triceps skin fold thickness (mm)   5. 2-Hour serum insulin (mu U/ml)   6. Body mass index (weight in kg/(height in m)^2)   7. Diabetes pedigree function   8. Age (years)   9. Class variable (0 or 1)  Univariate selection<jupyter_code>from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2

array = dataframe.values
X = array[:,0:8]
Y = array[:,8]
# feature extraction
test = SelectKBest(score_func=chi2, k=4)
fit = test.fit(X, Y)
# summarize scores
np.set_printoptions(precision=3)

print(fit.scores_)
features = fit.transform(X)
# summarize selected features
print(features[0:5,:])<jupyter_output>[  111.52   1411.887    17.605    53.108  2175.565   127.669     5.393
   181.304]
[[ 148.     0.    33.6   50. ]
 [  85.     0.    26.6   31. ]
 [ 183.     0.    23.3   32. ]
 [  89.    94.    28.1   21. ]
 [ 137.   168.    43.1   33. ]]<jupyter_text>Recursive feature elimination<jupyter_code>from sklearn.feature_selection import RFE
from sklearn.linear_model import LogisticRegression
X = array[:,0:8]
Y = array[:,8]
# feature extraction
model = LogisticRegression()
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_

print(fit.n_features_)
print(fit.support_)
print(fit.ranking_)
print(dataframe.columns)

print("According to that algo, most important ones are: preg, mass, pedi")<jupyter_output>3
[ True False False False False  True  True False]
[1 2 3 5 6 1 1 4]
Index(['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class'], dtype='object')
According to that algo, most important ones are: preg, mass, pedi<jupyter_text>PCA<jupyter_code>from sklearn.decomposition import PCA

array = dataframe.values
X = array[:,0:8]
Y = array[:,8]
# feature extraction
pca = PCA(n_components=3)
fit = pca.fit(X)
# summarize components
print("Explained Variance: %s" % fit.explained_variance_ratio_)
print(fit.components_)<jupyter_output>Explained Variance: [ 0.889  0.062  0.026]
[[ -2.022e-03   9.781e-02   1.609e-02   6.076e-02   9.931e-01   1.401e-02
    5.372e-04  -3.565e-03]
 [ -2.265e-02  -9.722e-01  -1.419e-01   5.786e-02   9.463e-02  -4.697e-02
   -8.168e-04  -1.402e-01]
 [ -2.246e-02   1.434e-01  -9.225e-01  -3.070e-01   2.098e-02  -1.324e-01
   -6.400e-04  -1.255e-01]]<jupyter_text>Feature importance<jupyter_code>from sklearn.ensemble import ExtraTreesClassifier

X = array[:,0:8]
Y = array[:,8]
# feature extraction
model = ExtraTreesClassifier()
model.fit(X, Y)
print(model.feature_importances_)
print(dataframe.columns)

#construct df to rate feature importance
names = dataframe.drop(['class'],axis = 1)
df = pd.DataFrame({"values":model.feature_importances_,"names":names.columns.values})
df = df.sort_values(by = 'values', ascending=False)
df<jupyter_output>[ 0.116  0.246  0.103  0.071  0.075  0.129  0.123  0.136]
Index(['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class'], dtype='object')
{'fraction_non_alphanumeric': 0.1475764124729855, 'fraction_numerical': 0.09972213646187095, 'mean_word_length': 3.9846153846153847, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '316454', 'license': 'MIT', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1240, 'n_words': 312, 'path': 'Indians diabetes dataset for feature selection.ipynb', 'repo_name': 'fadeetch/Exercises', 'size': '3239'}