plt.boxplot(x=train_data.values,labels=train_data.columns) 3 plt.hlines([-7.5, 7.5], 0, 40, colors='r') 4 plt.show() 5 6 train_data = train_data[train_data['V9']>-7.5] 7 train_data.describe() 8 9 from sklearn import preprocessing 10 11 features_columns = [col for col in train_data.columns if col not in ['target']] 12 13 min_max_scaler = preprocessing.MinMaxScaler() 14 15 min_max_scaler = min_max_scaler.fit(train_data[features_columns]) 16 17 train_data_scaler = min_max_scaler.transform(train_data[features_columns]) 18 test_data_scaler = min_max_scaler.transform(test_data[features_columns]) 19 20 train_data_scaler = pd.DataFrame(train_data_scaler) 21 train_data_scaler.columns = features_columns 22 23 test_data_scaler = pd.DataFrame(test_data_scaler) 24 test_data_scaler.columns = features_columns 25 26 train_data_scaler['target'] = train_data['target'] 27 28 train_data 29 30 mcorr=mcorr.abs() 31 numerical_corr=mcorr[mcorr['target']>0.1]['target'] 32 print(numerical_corr.sort_values(ascending=False)) 33 34 index0 = numerical_corr.sort_values(ascending=False).index 35 print(train_data_scaler[index0].corr('spearman')) 36 37 new_numerical=['V0', 'V2', 'V3', 'V4', 'V5', 'V6', 'V10','V11', 38 'V13', 'V15', 'V16', 'V18', 'V19', 'V20', 'V22','V24','V30', 'V31', 'V37'] 39 X=np.matrix(train_data_scaler[new_numerical]) 40 VIF_list=[variance_inflation_factor(X, i) for i in range(X.shape[1])] 41 VIF_list 42 43 44 pca = PCA(n_components=0.9) 45 new_train_pca_90 = pca.fit_transform(train_data_scaler.iloc[:,0:-1]) 46 new_test_pca_90 = pca.transform(test_data_scaler) 47 new_train_pca_90 = pd.DataFrame(new_train_pca_90) 48 new_test_pca_90 = pd.DataFrame(new_test_pca_90) 49 new_train_pca_90['target'] = train_data_scaler['target'] 50 new_train_pca_90.describe()
时间: 2024-03-30 07:37:10 浏览: 53
cSharp-and-plt.rar_C# plt_PLT_PLT 解析_c#解析plt_plt文件
5星 · 资源好评率100%
这段代码涉及到数据预处理和特征工程的内容。具体来说,它做了以下几件事情:
1. 使用箱线图和阈值来去除异常值;
2. 对特征进行归一化处理;
3. 计算特征之间的相关性,并筛选出与目标变量相关性大于0.1的特征;
4. 使用方差膨胀因子(VIF)来检查特征之间的多重共线性;
5. 使用主成分分析(PCA)来降维,使得保留90%的方差。
阅读全文