博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
cl.fe3.xyz index.php,2_FE_Diabetes.ipynb
阅读量:5171 次
发布时间:2019-06-13

本文共 37685 字,大约阅读时间需要 125 分钟。

{

"cells": [

{

"cell_type": "markdown",

"metadata": {},

"source": [

"# Diabetes Data Set特征工程"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"## 导入必要的工具包"

]

},

{

"cell_type": "code",

"execution_count": 1,

"metadata": {},

"outputs": [],

"source": [

"import numpy as np\n",

"import pandas as pd"

]

},

{

"cell_type": "code",

"execution_count": 2,

"metadata": {},

"outputs": [

{

"data": {

"text/html": [

"

\n",

"

" .dataframe tbody tr th:only-of-type {\n",

" vertical-align: middle;\n",

" }\n",

"\n",

" .dataframe tbody tr th {\n",

" vertical-align: top;\n",

" }\n",

"\n",

" .dataframe thead th {\n",

" text-align: right;\n",

" }\n",

"\n",

"

" \n",

"

\n",

"

\n",

"

pregnants\n",

"

Plasma_glucose_concentration\n",

"

blood_pressure\n",

"

Triceps_skin_fold_thickness\n",

"

serum_insulin\n",

"

BMI\n",

"

Diabetes_pedigree_function\n",

"

Age\n",

"

Target\n",

"

\n",

"

\n",

"

\n",

"

\n",

"

0\n",

"

6\n",

"

148\n",

"

72\n",

"

35\n",

"

0\n",

"

33.6\n",

"

0.627\n",

"

50\n",

"

1\n",

"

\n",

"

\n",

"

1\n",

"

1\n",

"

85\n",

"

66\n",

"

29\n",

"

0\n",

"

26.6\n",

"

0.351\n",

"

31\n",

"

0\n",

"

\n",

"

\n",

"

2\n",

"

8\n",

"

183\n",

"

64\n",

"

0\n",

"

0\n",

"

23.3\n",

"

0.672\n",

"

32\n",

"

1\n",

"

\n",

"

\n",

"

3\n",

"

1\n",

"

89\n",

"

66\n",

"

23\n",

"

94\n",

"

28.1\n",

"

0.167\n",

"

21\n",

"

0\n",

"

\n",

"

\n",

"

4\n",

"

0\n",

"

137\n",

"

40\n",

"

35\n",

"

168\n",

"

43.1\n",

"

2.288\n",

"

33\n",

"

1\n",

"

\n",

"

\n",

"

\n",

"

"

],

"text/plain": [

" pregnants Plasma_glucose_concentration blood_pressure \\\n",

"0 6 148 72 \n",

"1 1 85 66 \n",

"2 8 183 64 \n",

"3 1 89 66 \n",

"4 0 137 40 \n",

"\n",

" Triceps_skin_fold_thickness serum_insulin BMI \\\n",

"0 35 0 33.6 \n",

"1 29 0 26.6 \n",

"2 0 0 23.3 \n",

"3 23 94 28.1 \n",

"4 35 168 43.1 \n",

"\n",

" Diabetes_pedigree_function Age Target \n",

"0 0.627 50 1 \n",

"1 0.351 31 0 \n",

"2 0.672 32 1 \n",

"3 0.167 21 0 \n",

"4 2.288 33 1 "

]

},

"execution_count": 2,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"#读入数据\n",

"diabetes = pd.read_csv('pima-indians-diabetes.csv')\n",

"diabetes.head()"

]

},

{

"cell_type": "code",

"execution_count": 3,

"metadata": {},

"outputs": [

{

"name": "stdout",

"output_type": "stream",

"text": [

"\n",

"RangeIndex: 768 entries, 0 to 767\n",

"Data columns (total 9 columns):\n",

"pregnants 768 non-null int64\n",

"Plasma_glucose_concentration 768 non-null int64\n",

"blood_pressure 768 non-null int64\n",

"Triceps_skin_fold_thickness 768 non-null int64\n",

"serum_insulin 768 non-null int64\n",

"BMI 768 non-null float64\n",

"Diabetes_pedigree_function 768 non-null float64\n",

"Age 768 non-null int64\n",

"Target 768 non-null int64\n",

"dtypes: float64(2), int64(7)\n",

"memory usage: 54.1 KB\n"

]

}

],

"source": [

"diabetes.info()"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"表面上看数据没有缺失值,但实际上肯定有缺失值,只是被标记为0了。比如BMI和舒张压两列中的0作为指标数值来说毫无意义。"

]

},

{

"cell_type": "code",

"execution_count": 4,

"metadata": {},

"outputs": [

{

"data": {

"text/html": [

"

\n",

"

" .dataframe tbody tr th:only-of-type {\n",

" vertical-align: middle;\n",

" }\n",

"\n",

" .dataframe tbody tr th {\n",

" vertical-align: top;\n",

" }\n",

"\n",

" .dataframe thead th {\n",

" text-align: right;\n",

" }\n",

"\n",

"

" \n",

"

\n",

"

\n",

"

pregnants\n",

"

Plasma_glucose_concentration\n",

"

blood_pressure\n",

"

Triceps_skin_fold_thickness\n",

"

serum_insulin\n",

"

BMI\n",

"

Diabetes_pedigree_function\n",

"

Age\n",

"

Target\n",

"

\n",

"

\n",

"

\n",

"

\n",

"

count\n",

"

768.000000\n",

"

768.000000\n",

"

768.000000\n",

"

768.000000\n",

"

768.000000\n",

"

768.000000\n",

"

768.000000\n",

"

768.000000\n",

"

768.000000\n",

"

\n",

"

\n",

"

mean\n",

"

3.845052\n",

"

120.894531\n",

"

69.105469\n",

"

20.536458\n",

"

79.799479\n",

"

31.992578\n",

"

0.471876\n",

"

33.240885\n",

"

0.348958\n",

"

\n",

"

\n",

"

std\n",

"

3.369578\n",

"

31.972618\n",

"

19.355807\n",

"

15.952218\n",

"

115.244002\n",

"

7.884160\n",

"

0.331329\n",

"

11.760232\n",

"

0.476951\n",

"

\n",

"

\n",

"

min\n",

"

0.000000\n",

"

0.000000\n",

"

0.000000\n",

"

0.000000\n",

"

0.000000\n",

"

0.000000\n",

"

0.078000\n",

"

21.000000\n",

"

0.000000\n",

"

\n",

"

\n",

"

25%\n",

"

1.000000\n",

"

99.000000\n",

"

62.000000\n",

"

0.000000\n",

"

0.000000\n",

"

27.300000\n",

"

0.243750\n",

"

24.000000\n",

"

0.000000\n",

"

\n",

"

\n",

"

50%\n",

"

3.000000\n",

"

117.000000\n",

"

72.000000\n",

"

23.000000\n",

"

30.500000\n",

"

32.000000\n",

"

0.372500\n",

"

29.000000\n",

"

0.000000\n",

"

\n",

"

\n",

"

75%\n",

"

6.000000\n",

"

140.250000\n",

"

80.000000\n",

"

32.000000\n",

"

127.250000\n",

"

36.600000\n",

"

0.626250\n",

"

41.000000\n",

"

1.000000\n",

"

\n",

"

\n",

"

max\n",

"

17.000000\n",

"

199.000000\n",

"

122.000000\n",

"

99.000000\n",

"

846.000000\n",

"

67.100000\n",

"

2.420000\n",

"

81.000000\n",

"

1.000000\n",

"

\n",

"

\n",

"

\n",

"

"

],

"text/plain": [

" pregnants Plasma_glucose_concentration blood_pressure \\\n",

"count 768.000000 768.000000 768.000000 \n",

"mean 3.845052 120.894531 69.105469 \n",

"std 3.369578 31.972618 19.355807 \n",

"min 0.000000 0.000000 0.000000 \n",

"25% 1.000000 99.000000 62.000000 \n",

"50% 3.000000 117.000000 72.000000 \n",

"75% 6.000000 140.250000 80.000000 \n",

"max 17.000000 199.000000 122.000000 \n",

"\n",

" Triceps_skin_fold_thickness serum_insulin BMI \\\n",

"count 768.000000 768.000000 768.000000 \n",

"mean 20.536458 79.799479 31.992578 \n",

"std 15.952218 115.244002 7.884160 \n",

"min 0.000000 0.000000 0.000000 \n",

"25% 0.000000 0.000000 27.300000 \n",

"50% 23.000000 30.500000 32.000000 \n",

"75% 32.000000 127.250000 36.600000 \n",

"max 99.000000 846.000000 67.100000 \n",

"\n",

" Diabetes_pedigree_function Age Target \n",

"count 768.000000 768.000000 768.000000 \n",

"mean 0.471876 33.240885 0.348958 \n",

"std 0.331329 11.760232 0.476951 \n",

"min 0.078000 21.000000 0.000000 \n",

"25% 0.243750 24.000000 0.000000 \n",

"50% 0.372500 29.000000 0.000000 \n",

"75% 0.626250 41.000000 1.000000 \n",

"max 2.420000 81.000000 1.000000 "

]

},

"execution_count": 4,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"diabetes.describe()"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"从结果中我们可以看到很多列的最小值为0,而在一些特定列代表的变量中,0值并没有意义,这就表名该值无效或为缺失值。\n",

"\n",

"具体来说,下列变量的最小值为0时数据无意义: 1、血浆葡萄糖浓度 2、舒张压 3、肱三头肌皮褶厚度 4、餐后血清胰岛素 5、体重指数\n",

"\n",

"在Pandas的DataFrame中,通过replace()函数可以很方便的将我们感兴趣的数据子集的值标记为NaN。\n",

"\n",

"标记完缺失值之后,可以利用isnull()函数将数据集中所有的NaN值标记为True,然后就可以得到每一列中缺失值的数量了。"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"## 分开特征和标签"

]

},

{

"cell_type": "code",

"execution_count": 5,

"metadata": {},

"outputs": [],

"source": [

"#标签\n",

"y_diabetes = diabetes['Target']\n",

"\n",

"X_diabetes = diabetes.drop(['Target'], axis = 1)\n",

"#保存特征名字\n",

"columns_org = X_diabetes.columns"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"## 1.feat编码:log(x+1)\n",

"原始特征feat_x看起来像计数特征,取log运算更接近人对数字的敏感度,更适合线性模型。 同时也可以降低长维分布中大数值的影响,减弱长维分布的长尾性。"

]

},

{

"cell_type": "code",

"execution_count": 6,

"metadata": {

"scrolled": true

},

"outputs": [

{

"data": {

"text/html": [

"

\n",

"

" .dataframe tbody tr th:only-of-type {\n",

" vertical-align: middle;\n",

" }\n",

"\n",

" .dataframe tbody tr th {\n",

" vertical-align: top;\n",

" }\n",

"\n",

" .dataframe thead th {\n",

" text-align: right;\n",

" }\n",

"\n",

"

" \n",

"

\n",

"

\n",

"

pregnants_log\n",

"

Plasma_glucose_concentration_log\n",

"

blood_pressure_log\n",

"

Triceps_skin_fold_thickness_log\n",

"

serum_insulin_log\n",

"

BMI_log\n",

"

Diabetes_pedigree_function_log\n",

"

Age_log\n",

"

\n",

"

\n",

"

\n",

"

\n",

"

0\n",

"

1.945910\n",

"

5.003946\n",

"

4.290459\n",

"

3.583519\n",

"

0.000000\n",

"

3.543854\n",

"

0.486738\n",

"

3.931826\n",

"

\n",

"

\n",

"

1\n",

"

0.693147\n",

"

4.454347\n",

"

4.204693\n",

"

3.401197\n",

"

0.000000\n",

"

3.317816\n",

"

0.300845\n",

"

3.465736\n",

"

\n",

"

\n",

"

2\n",

"

2.197225\n",

"

5.214936\n",

"

4.174387\n",

"

0.000000\n",

"

0.000000\n",

"

3.190476\n",

"

0.514021\n",

"

3.496508\n",

"

\n",

"

\n",

"

3\n",

"

0.693147\n",

"

4.499810\n",

"

4.204693\n",

"

3.178054\n",

"

4.553877\n",

"

3.370738\n",

"

0.154436\n",

"

3.091042\n",

"

\n",

"

\n",

"

4\n",

"

0.000000\n",

"

4.927254\n",

"

3.713572\n",

"

3.583519\n",

"

5.129899\n",

"

3.786460\n",

"

1.190279\n",

"

3.526361\n",

"

\n",

"

\n",

"

\n",

"

"

],

"text/plain": [

" pregnants_log Plasma_glucose_concentration_log blood_pressure_log \\\n",

"0 1.945910 5.003946 4.290459 \n",

"1 0.693147 4.454347 4.204693 \n",

"2 2.197225 5.214936 4.174387 \n",

"3 0.693147 4.499810 4.204693 \n",

"4 0.000000 4.927254 3.713572 \n",

"\n",

" Triceps_skin_fold_thickness_log serum_insulin_log BMI_log \\\n",

"0 3.583519 0.000000 3.543854 \n",

"1 3.401197 0.000000 3.317816 \n",

"2 0.000000 0.000000 3.190476 \n",

"3 3.178054 4.553877 3.370738 \n",

"4 3.583519 5.129899 3.786460 \n",

"\n",

" Diabetes_pedigree_function_log Age_log \n",

"0 0.486738 3.931826 \n",

"1 0.300845 3.465736 \n",

"2 0.514021 3.496508 \n",

"3 0.154436 3.091042 \n",

"4 1.190279 3.526361 "

]

},

"execution_count": 6,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"X_log = np.log1p(X_diabetes)\n",

"\n",

"#重新组成DataFrame\n",

"feat_names = columns_org + '_log'\n",

"X_log = pd.DataFrame(columns = feat_names, data = X_log.values)\n",

"\n",

"X_log.head()"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"## 2.feat编码: TF-IDF\n",

"原始特征feat_x看起来像计数特征,类似文本分析中词频特征的处理,TF-IDF可以突出对特别类别有贡献的低频词。 这里原始特征已经是计数特征了,直接调用TfidfTransformer,将计数特征变成TF-IDF 如果输入是原始文本,需要将计数功能(TF)和IDF功能集中在一起,用TfidfVectorizer"

]

},

{

"cell_type": "code",

"execution_count": 7,

"metadata": {},

"outputs": [

{

"data": {

"text/html": [

"

\n",

"

" .dataframe tbody tr th:only-of-type {\n",

" vertical-align: middle;\n",

" }\n",

"\n",

" .dataframe tbody tr th {\n",

" vertical-align: top;\n",

" }\n",

"\n",

" .dataframe thead th {\n",

" text-align: right;\n",

" }\n",

"\n",

"

" \n",

"

\n",

"

\n",

"

pregnants_tfidf\n",

"

Plasma_glucose_concentration_tfidf\n",

"

blood_pressure_tfidf\n",

"

Triceps_skin_fold_thickness_tfidf\n",

"

serum_insulin_tfidf\n",

"

BMI_tfidf\n",

"

Diabetes_pedigree_function_tfidf\n",

"

Age_tfidf\n",

"

\n",

"

\n",

"

\n",

"

\n",

"

0\n",

"

0.037717\n",

"

0.810132\n",

"

0.409804\n",

"

0.256931\n",

"

0.000000\n",

"

0.185363\n",

"

0.003410\n",

"

0.271919\n",

"

\n",

"

\n",

"

1\n",

"

0.009341\n",

"

0.691357\n",

"

0.558183\n",

"

0.316326\n",

"

0.000000\n",

"

0.218049\n",

"

0.002836\n",

"

0.250508\n",

"

\n",

"

\n",

"

2\n",

"

0.046188\n",

"

0.920021\n",

"

0.334562\n",

"

0.000000\n",

"

0.000000\n",

"

0.118057\n",

"

0.003357\n",

"

0.159835\n",

"

\n",

"

\n",

"

3\n",

"

0.005813\n",

"

0.450469\n",

"

0.347351\n",

"

0.156119\n",

"

0.787603\n",

"

0.143341\n",

"

0.000840\n",

"

0.105602\n",

"

\n",

"

\n",

"

4\n",

"

0.000000\n",

"

0.426849\n",

"

0.129587\n",

"

0.146243\n",

"

0.866498\n",

"

0.135338\n",

"

0.007082\n",

"

0.102151\n",

"

\n",

"

\n",

"

\n",

"

"

],

"text/plain": [

" pregnants_tfidf Plasma_glucose_concentration_tfidf blood_pressure_tfidf \\\n",

"0 0.037717 0.810132 0.409804 \n",

"1 0.009341 0.691357 0.558183 \n",

"2 0.046188 0.920021 0.334562 \n",

"3 0.005813 0.450469 0.347351 \n",

"4 0.000000 0.426849 0.129587 \n",

"\n",

" Triceps_skin_fold_thickness_tfidf serum_insulin_tfidf BMI_tfidf \\\n",

"0 0.256931 0.000000 0.185363 \n",

"1 0.316326 0.000000 0.218049 \n",

"2 0.000000 0.000000 0.118057 \n",

"3 0.156119 0.787603 0.143341 \n",

"4 0.146243 0.866498 0.135338 \n",

"\n",

" Diabetes_pedigree_function_tfidf Age_tfidf \n",

"0 0.003410 0.271919 \n",

"1 0.002836 0.250508 \n",

"2 0.003357 0.159835 \n",

"3 0.000840 0.105602 \n",

"4 0.007082 0.102151 "

]

},

"execution_count": 7,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"# transform counts to TFIDF features\n",

"from sklearn.feature_extraction.text import TfidfTransformer\n",

"tfidf = TfidfTransformer()\n",

"\n",

"#输出稀疏矩阵\n",

"X_tfidf = tfidf.fit_transform(X_diabetes).toarray()\n",

"\n",

"#重新组成DataFrame,为了可视化\n",

"feat_names = columns_org + \"_tfidf\"\n",

"X_tfidf = pd.DataFrame(columns = feat_names, data = X_tfidf)\n",

"\n",

"X_tfidf.head()"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"## 3.其他特征工程"

]

},

{

"cell_type": "code",

"execution_count": 8,

"metadata": {

"scrolled": true

},

"outputs": [

{

"name": "stdout",

"output_type": "stream",

"text": [

"pregnants 0\n",

"Plasma_glucose_concentration 5\n",

"blood_pressure 35\n",

"Triceps_skin_fold_thickness 227\n",

"serum_insulin 374\n",

"BMI 11\n",

"Diabetes_pedigree_function 0\n",

"Age 0\n",

"Target 0\n",

"dtype: int64\n"

]

}

],

"source": [

"NaN_col_names = ['Plasma_glucose_concentration','blood_pressure','Triceps_skin_fold_thickness','serum_insulin','BMI']\n",

"diabetes[NaN_col_names] = diabetes[NaN_col_names].replace(0, np.NaN)\n",

"print(diabetes.isnull().sum())"

]

},

{

"cell_type": "code",

"execution_count": 9,

"metadata": {},

"outputs": [

{

"data": {

"text/html": [

"

\n",

"

" .dataframe tbody tr th:only-of-type {\n",

" vertical-align: middle;\n",

" }\n",

"\n",

" .dataframe tbody tr th {\n",

" vertical-align: top;\n",

" }\n",

"\n",

" .dataframe thead th {\n",

" text-align: right;\n",

" }\n",

"\n",

"

" \n",

"

\n",

"

\n",

"

Triceps_skin_fold_thickness\n",

"

Triceps_skin_fold_thickness_Missing\n",

"

\n",

"

\n",

"

\n",

"

\n",

"

0\n",

"

35.0\n",

"

0\n",

"

\n",

"

\n",

"

1\n",

"

29.0\n",

"

0\n",

"

\n",

"

\n",

"

2\n",

"

NaN\n",

"

1\n",

"

\n",

"

\n",

"

3\n",

"

23.0\n",

"

0\n",

"

\n",

"

\n",

"

4\n",

"

35.0\n",

"

0\n",

"

\n",

"

\n",

"

5\n",

"

NaN\n",

"

1\n",

"

\n",

"

\n",

"

6\n",

"

32.0\n",

"

0\n",

"

\n",

"

\n",

"

7\n",

"

NaN\n",

"

1\n",

"

\n",

"

\n",

"

8\n",

"

45.0\n",

"

0\n",

"

\n",

"

\n",

"

9\n",

"

NaN\n",

"

1\n",

"

\n",

"

\n",

"

\n",

"

"

],

"text/plain": [

" Triceps_skin_fold_thickness Triceps_skin_fold_thickness_Missing\n",

"0 35.0 0\n",

"1 29.0 0\n",

"2 NaN 1\n",

"3 23.0 0\n",

"4 35.0 0\n",

"5 NaN 1\n",

"6 32.0 0\n",

"7 NaN 1\n",

"8 45.0 0\n",

"9 NaN 1"

]

},

"execution_count": 9,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"#缺失值比较多,新增一个新的字段,表明是缺失值还是不是缺失值\n",

"diabetes['Triceps_skin_fold_thickness_Missing'] = diabetes['Triceps_skin_fold_thickness'].apply(lambda x: 1 if pd.isnull(x) else 0)\n",

"diabetes[['Triceps_skin_fold_thickness','Triceps_skin_fold_thickness_Missing']].head(10)"

]

},

{

"cell_type": "code",

"execution_count": 10,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

""

]

},

"execution_count": 10,

"metadata": {},

"output_type": "execute_result"

},

{

"data": {

"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAELCAYAAADD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kgqDKUZzVjIfg7BNiohFkn4CzJW0gWL3yOkU4XCZpFMp/i3dz8bAeBS4k+JmROdFxMsqDlZ/W9K7wJsUxyRyhgJXqtjJHhTHPyrr+YmkC4FrJJ3UQa9xnopLS7fsYrssHceo/D9yE3AExUHZZRSB0Z6ZwL2SVgDjqyzly8C/pdf3DvDFihpfVHFw/Y72Xneq+/y07e0oduV8jWKE0fp97Qn8TsVpwtsBP0672NoVEf+xiS6532F2Wy3HujbhRopdnS3v/SN8cNejlcCX+7YOJ+kC0sHfWtdi2w5JO0bEm2l08ghwUESsrnVd2zKPIMxsa3FnOrW2F8Wo1OFQMo8grKYkzefDf6j8Q0QszfXfwm1cDhzcqvnnEXFtB61/DsX3ASqdHRH35vp3dZLOoPiOSKW5EfHNXH/bdjkgzMwsy2cxmZlZlgPCzMyyHBBmZpblgDAzsywHhJmZZf1/ghDaRNNOWUIAAAAASUVORK5CYII=\n",

"text/plain": [

""

]

},

"metadata": {},

"output_type": "display_data"

}

],

"source": [

"import matplotlib.pyplot as plt\n",

"import seaborn as sns\n",

"\n",

"%matplotlib inline\n",

"sns.countplot(x = 'Triceps_skin_fold_thickness_Missing', hue = 'Target', data = diabetes)"

]

},

{

"cell_type": "code",

"execution_count": 11,

"metadata": {},

"outputs": [

{

"data": {

"text/plain": [

""

]

},

"execution_count": 11,

"metadata": {},

"output_type": "execute_result"

},

{

"data": {

"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAELCAYAAADDZxFQAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvNQv5yAAAFWVJREFUeJzt3XuwnHWd5/H311wmXLJAQmAIB0hAYCYRk8Ah6CquAjXEOHLxwpBaFQQJM4suTg3UMK4FMWN2nBoVZZhhC5AlzCKX9QKBTQUwNZjSFUPAGEIYBIUlh1tC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MtG4OqI+BiwYQtjS6/3/dV6ycyVwIoW6tROwoBQ22Tmr2h8In0A+Dvg48CDmTm1uh2RmX/SNOTfmx5vovr7jYgARjY993LT49eall9j+4679Y3r7RuXmd8FTgJeAu6IiOOaa6mMamHuV/ONC6G9Pv823EZji+iJzPx9qcPm72lEXFwdr5kOfJ9GuCzawvxveb2Ufy9EQ4QBobaJiPHAhsz8X8DXgWOAcRHx3ur5ERExeQvDH+eN3R0nAyNqLpeqpoOB32TmZTQui/5u4Flgn4gYGxF/APxpHeuutlb+mjfvdtu8vs3f0yMjYndgj8xcSGP30dTtWO1PgNOquSfR2G2nIcKzmNRORwD/EBGvAa8Cf0Hj0/hlEbEHjb/PbwGly49fBdwaEUuBxbx566JOfwZ8KiJeBZ4B5mbmqxExF/g58Bjwb3WtPDNv3EaX0ns6msZ7NYrGFsFfbscq/xmYHxErgF/Q2MW0frsL16Dk5b4lbVFEDANGZObG6gywxTQO+r/S5tI0ANyCkLQ1uwL/GhEjaGx9/IXhMHS4BaEhJyL+G/DJzZr/d2Zucd/+QOjUujR0GRCSpCLPYpIkFRkQkqQiA0KSVGRASJKKDAhJUtH/BzWoxajWghiZAAAAAElFTkSuQmCC\n",

"text/plain": [

""

]

},

"metadata": {},

"output_type": "display_data"

}

],

"source": [

"#缺失值比较多,新增一个新的字段,表明是缺失值还是不是缺失值\n",

"diabetes['serum_insulin_Missing'] = diabetes['serum_insulin'].apply(lambda x: 1 if pd.isnull(x) else 0)\n",

"sns.countplot(x = 'serum_insulin_Missing', hue = 'Target', data = diabetes)"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"特征是否缺失和目标也没什么关系"

]

},

{

"cell_type": "code",

"execution_count": 12,

"metadata": {},

"outputs": [

{

"name": "stdout",

"output_type": "stream",

"text": [

"pregnants 0\n",

"Plasma_glucose_concentration 0\n",

"blood_pressure 0\n",

"Triceps_skin_fold_thickness 0\n",

"serum_insulin 0\n",

"BMI 0\n",

"Diabetes_pedigree_function 0\n",

"Age 0\n",

"Target 0\n",

"dtype: int64\n"

]

}

],

"source": [

"#删除新增项\n",

"diabetes.drop(['Triceps_skin_fold_thickness_Missing','serum_insulin_Missing'],axis = 1, inplace = True)\n",

"\n",

"#用中值填补\n",

"medians = diabetes.median()\n",

"diabetes = diabetes.fillna(medians)\n",

"\n",

"print(diabetes.isnull().sum())"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"## 数据标准化"

]

},

{

"cell_type": "code",

"execution_count": 13,

"metadata": {},

"outputs": [],

"source": [

"# get labels\n",

"y_diabetes = diabetes['Target']\n",

"X_diabetes = diabetes.drop(['Target'], axis = 1)\n",

"\n",

"#用于保存特征工程之后的结果\n",

"feat_names = X_diabetes.columns\n",

"\n",

"#数据标准化\n",

"from sklearn.preprocessing import StandardScaler\n",

"\n",

"# 初始化特征的标准化器\n",

"ss_X = StandardScaler()\n",

"\n",

"#分别对训练和测试数据的特征进行标准化处理\n",

"X_diabetes = ss_X.fit_transform(X_diabetes)"

]

},

{

"cell_type": "code",

"execution_count": 14,

"metadata": {},

"outputs": [],

"source": [

"# 对log数据缩放\n",

"from sklearn.preprocessing import MinMaxScaler\n",

"# 构造输入特征的标准化器\n",

"ms_log = MinMaxScaler()\n",

"\n",

"#保存特征名字,用于结果保存为csv\n",

"feat_names_log = X_log.columns\n",

"\n",

"# 用训练模型训练好的缩放器对测试数据进行特征缩放:transform\n",

"X_log =ms_log.fit_transform(X_log)"

]

},

{

"cell_type": "code",

"execution_count": 15,

"metadata": {},

"outputs": [],

"source": [

"# 对tf-idf数据缩放\n",

"from sklearn.preprocessing import MinMaxScaler\n",

"# 构造输入特征的标准化器\n",

"ms_tfidf = MinMaxScaler()\n",

"\n",

"#保存特征名字,用于结果保存为csv\n",

"feat_names_tfidf = X_tfidf.columns\n",

"\n",

"# 用训练模型训练好的缩放器对测试数据进行特征缩放:transform\n",

"X_tfidf = ms_tfidf.fit_transform(X_tfidf)"

]

},

{

"cell_type": "markdown",

"metadata": {},

"source": [

"## 特征处理结果存为文件"

]

},

{

"cell_type": "code",

"execution_count": 16,

"metadata": {},

"outputs": [],

"source": [

"#保存原始特征\n",

"X_diabetes = pd.DataFrame(columns = feat_names, data = X_diabetes)\n",

"\n",

"diabetes = pd.concat([X_diabetes, y_diabetes], axis = 1)\n",

"\n",

"diabetes.to_csv('FE_pima_indians_diabetes.csv', index = False, header = True)"

]

},

{

"cell_type": "code",

"execution_count": 17,

"metadata": {},

"outputs": [

{

"data": {

"text/html": [

"

\n",

"

" .dataframe tbody tr th:only-of-type {\n",

" vertical-align: middle;\n",

" }\n",

"\n",

" .dataframe tbody tr th {\n",

" vertical-align: top;\n",

" }\n",

"\n",

" .dataframe thead th {\n",

" text-align: right;\n",

" }\n",

"\n",

"

" \n",

"

\n",

"

\n",

"

pregnants\n",

"

Plasma_glucose_concentration\n",

"

blood_pressure\n",

"

Triceps_skin_fold_thickness\n",

"

serum_insulin\n",

"

BMI\n",

"

Diabetes_pedigree_function\n",

"

Age\n",

"

Target\n",

"

\n",

"

\n",

"

\n",

"

\n",

"

0\n",

"

0.639947\n",

"

0.866045\n",

"

-0.031990\n",

"

0.670643\n",

"

-0.181541\n",

"

0.166619\n",

"

0.468492\n",

"

1.425995\n",

"

1\n",

"

\n",

"

\n",

"

1\n",

"

-0.844885\n",

"

-1.205066\n",

"

-0.528319\n",

"

-0.012301\n",

"

-0.181541\n",

"

-0.852200\n",

"

-0.365061\n",

"

-0.190672\n",

"

0\n",

"

\n",

"

\n",

"

2\n",

"

1.233880\n",

"

2.016662\n",

"

-0.693761\n",

"

-0.012301\n",

"

-0.181541\n",

"

-1.332500\n",

"

0.604397\n",

"

-0.105584\n",

"

1\n",

"

\n",

"

\n",

"

3\n",

"

-0.844885\n",

"

-1.073567\n",

"

-0.528319\n",

"

-0.695245\n",

"

-0.540642\n",

"

-0.633881\n",

"

-0.920763\n",

"

-1.041549\n",

"

0\n",

"

\n",

"

\n",

"

4\n",

"

-1.141852\n",

"

0.504422\n",

"

-2.679076\n",

"

0.670643\n",

"

0.316566\n",

"

1.549303\n",

"

5.484909\n",

"

-0.020496\n",

"

1\n",

"

\n",

"

\n",

"

\n",

"

"

],

"text/plain": [

" pregnants Plasma_glucose_concentration blood_pressure \\\n",

"0 0.639947 0.866045 -0.031990 \n",

"1 -0.844885 -1.205066 -0.528319 \n",

"2 1.233880 2.016662 -0.693761 \n",

"3 -0.844885 -1.073567 -0.528319 \n",

"4 -1.141852 0.504422 -2.679076 \n",

"\n",

" Triceps_skin_fold_thickness serum_insulin BMI \\\n",

"0 0.670643 -0.181541 0.166619 \n",

"1 -0.012301 -0.181541 -0.852200 \n",

"2 -0.012301 -0.181541 -1.332500 \n",

"3 -0.695245 -0.540642 -0.633881 \n",

"4 0.670643 0.316566 1.549303 \n",

"\n",

" Diabetes_pedigree_function Age Target \n",

"0 0.468492 1.425995 1 \n",

"1 -0.365061 -0.190672 0 \n",

"2 0.604397 -0.105584 1 \n",

"3 -0.920763 -1.041549 0 \n",

"4 5.484909 -0.020496 1 "

]

},

"execution_count": 17,

"metadata": {},

"output_type": "execute_result"

}

],

"source": [

"diabetes.head()"

]

},

{

"cell_type": "code",

"execution_count": 18,

"metadata": {},

"outputs": [],

"source": [

"#保存log特征变换结果\n",

"y = pd.Series(data = y_diabetes, name = 'Target')\n",

"test_log = pd.concat([pd.DataFrame(columns = feat_names_log, data = X_log),y], axis = 1)\n",

"test_log.to_csv('FE_diabetes_log.csv',index=False,header=True)"

]

},

{

"cell_type": "code",

"execution_count": 19,

"metadata": {},

"outputs": [],

"source": [

"#保存tf-idf特征变换结果\n",

"y = pd.Series(data = y_diabetes, name = 'Target')\n",

"test_tfidf = pd.concat([pd.DataFrame(columns = feat_names_tfidf, data = X_tfidf),y], axis = 1)\n",

"test_tfidf.to_csv('FE_diabetes_tfidf.csv',index=False,header=True)"

]

},

{

"cell_type": "code",

"execution_count": null,

"metadata": {},

"outputs": [],

"source": []

}

],

"metadata": {

"kernelspec": {

"display_name": "Python 3",

"language": "python",

"name": "python3"

},

"language_info": {

"codemirror_mode": {

"name": "ipython",

"version": 3

},

"file_extension": ".py",

"mimetype": "text/x-python",

"name": "python",

"nbconvert_exporter": "python",

"pygments_lexer": "ipython3",

"version": "3.6.4"

}

},

"nbformat": 4,

"nbformat_minor": 2

}

一键复制

编辑

Web IDE

原始数据

按行查看

历史

转载地址:http://uqhiv.baihongyu.com/

你可能感兴趣的文章
JavaScript---Promise
查看>>
暖暖的感动
查看>>
Java中的日期和时间
查看>>
Django基于admin的stark组件创建(一)
查看>>
C. Tanya and Toys_模拟
查看>>
springboot jar包运行中获取资源文件
查看>>
基于FPGA实现的高速串行交换模块实现方法研究
查看>>
Java Scala获取所有注解的类信息
查看>>
delphi ,安装插件
查看>>
case when then的用法-leetcode交换工资
查看>>
11.28.cookie
查看>>
BeanShell简介
查看>>
python字符串操作
查看>>
不同程序语言的注释和变量要求
查看>>
语言基础(9):static, extern 和 inline
查看>>
ES5_03_Object扩展
查看>>
bzoj 2600: [Ioi2011]ricehub
查看>>
创建数据库,表
查看>>
工厂模式
查看>>
计算机网络基础知识
查看>>