Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 国产在线观看91精品不卡,日韩一区二区三区中文字幕,国产精品日本一区二区在线播放

          整合營銷服務(wù)商

          電腦端+手機(jī)端+微信端=數(shù)據(jù)同步管理

          免費(fèi)咨詢熱線:

          特征篩選的幾種方法,附代碼(百分百有用)

          方差對(duì)于單變量選擇

          # 計(jì)算變量的方差
          # 如果方差接近于0,也就是該特征的特征值之間基本上沒有差異,這個(gè)特征對(duì)于樣本的區(qū)分并沒有什么用,剔除
          from sklearn.feature_selection import VarianceThreshold
          selector = VarianceThreshold(threshold=0.1) #默認(rèn)threshold=0.0
          selector.fit_transform(df[numerical_features])
          
          # 查看各個(gè)特征的方差,
          selector.variances_ ,len(selector.variances_)
          
          # 特征對(duì)應(yīng)方差
          all_used_features_dict = dict(zip(numerical_features,selector.variances_ ))
          all_used_features_dict

          數(shù)值特征和目標(biāo)值之間的相關(guān)性

          協(xié)方差

          ?如果協(xié)方差為正,說明X,Y同向變化,協(xié)方差越大說明同向程度越高;

          ?如果協(xié)方差維負(fù),說明X,Y反向運(yùn)動(dòng),協(xié)方差越小說明反向程度越高;

          ?如果兩個(gè)變量相互獨(dú)立,那么協(xié)方差就是0,說明兩個(gè)變量不相關(guān)。

          pearson系數(shù)

          (1) 相關(guān)概念和值大小含義

          相關(guān)系數(shù)也可以看成協(xié)方差:一種剔除了兩個(gè)變量量綱影響、標(biāo)準(zhǔn)化后的特殊協(xié)方差。

          可以反映兩個(gè)變量變化時(shí)是同向還是反向,如果同向變化就為正,反向變化就為負(fù)。由于它是標(biāo)準(zhǔn)化后的協(xié)方差,因此更重要的特性來了,它消除了兩個(gè)變量變化幅度的影響,而只是單純反應(yīng)兩個(gè)變量每單位變化時(shí)的相似程度。

          假設(shè)對(duì)于Pearson r相關(guān)性,兩個(gè)變量都應(yīng)該是正態(tài)分布的

          pearson數(shù)值大小衡量相關(guān)性:

          0.8-1.0 極強(qiáng)相關(guān) | 0.6-0.8 強(qiáng)相關(guān) | 0.4-0.6 中等程度相關(guān) | 0.2-0.4 弱相關(guān) | 0.0-0.2 極弱相關(guān)或無相關(guān)

          (2) pearson 系數(shù)的優(yōu)缺點(diǎn):

          ?優(yōu)點(diǎn): 可以通過數(shù)值對(duì)變量之間相關(guān)性衡量,正值代表正相關(guān)、負(fù)值代表負(fù)相關(guān)、0代表不相關(guān)

          ?缺點(diǎn): 沒有對(duì)變量之間的關(guān)系進(jìn)行提煉和學(xué)習(xí),預(yù)測其實(shí)是學(xué)習(xí)不同特征之間的組合既關(guān)系。只能判別特征之間的線性相關(guān)性,如果是非線性相關(guān)就不可取。

          (3) 適用場景

          兩個(gè)變量之間是線性關(guān)系,都是連續(xù)數(shù)據(jù)。

          兩個(gè)變量的總體是正態(tài)分布,或接近正態(tài)的單峰分布。

          兩個(gè)變量的觀測值是成對(duì)的,每對(duì)觀測值之間相互獨(dú)立

          (4) 相關(guān)代碼

          通過numpy

          import numpy as np
          np.corrcoef([a,b,c,d])

          pandas中corr()函數(shù)

          import matplotlib.pyplot as plt
          plt.figure(figsize = (25,25))
          #### 傳入相關(guān)特征即可,輸出為所有特征之間相關(guān)性
          corr_values1 = data[features].corr()
          sns.heatmap(corr_values1, annot=True,vmax=1, square=True, cmap="Blues",fmt='.2f')
          plt.tight_layout()
          plt.savefig('**.png',dpi=600)
          plt.show()

          利用scipy,輸出兩個(gè)值,第一個(gè)值為相關(guān)系數(shù),第二個(gè)值越小代表兩個(gè)之間相關(guān)性越高

          import numpy as np
          from scipy.stats import pearsonr
          ### 計(jì)算兩個(gè)特征之間相關(guān)性,同時(shí)也可以計(jì)算特征和標(biāo)簽之間相關(guān)性
          print("Lower noise", df(x, x1))

          (5) 通過pearson系數(shù)刪選特征

          ? 5.1 通過和label之間的相關(guān)性之間,通過設(shè)置閾值刪選

          def del_corr_fea(df,cor_df):
              """
              df是原始數(shù)據(jù),cor_df為通過pd.corr()獲得特征間相關(guān)性矩陣,
              """
              cor_df = cor_df.reset_index()
              feature_col = [col for col in df.columns if col not in drop_fea_list]
              drop_fea = []
              for i,f in enumerate(feature_col):
                  if f not in drop_fea:
                      cor_df1 = cor_df[i+1:][[f,'index']]
                      cor_df_sel = cor_df1[cor_df1[f]>=0.8]
                      cor_df_sel.sort_values(by=[f],ascending = False,inplace = True)
                      del_name = cor_df_sel['index'].values.tolist()[1:]
                      drop_fea = del_name + drop_fea
              return drop_fea
          drop_list_no_p = del_corr_fea(data_end,corr_values_fea_fea)

          5.2 首先計(jì)算不同特征之間相關(guān)性,然后通過相關(guān)性取出相似性最高的幾個(gè)特征,并保留和label間系數(shù)最高的特征

           def del_corr_fea(df,cor_df,cor_df_with_label):
              """
              df是原始數(shù)據(jù),cor_df為通過pd.corr()獲得特征間相關(guān)性矩陣,cor_df_with_label和標(biāo)簽之間相關(guān)性
              """
              cor_df = cor_df.reset_index()
              cor_df = cor_df.rename(columns = {'index':'feature'})
              feature_col = [col for col in df.columns if col not in drop_fea_list]
              drop_fea = []
              for i,f in enumerate(feature_col):
                  if f not in drop_fea:
                      print(len(drop_fea))
                      cor_df1 = cor_df[i:][[f,'feature']]
                      cor_df_sel = cor_df1[cor_df1[f]>=0.8]
                      sort_corr_df = cor_df_sel.merge(cor_df_with_label,on = 'feature',how = 'left')
                      ## p 更改為相關(guān)性矩陣的列名
                      sort_corr_df.sort_values(by=['p'],ascending = False,inplace = True)
                      del_name = sort_corr_df['feature'].values.tolist()[1:]
                      drop_fea = del_name + drop_fea
              return drop_fea
          drop_feature_list = del_corr_fea(data_end,corr_values_fea_fea,d_df)
          len(drop_feature_list)

          通過模型輸出特征重要性(包括數(shù)值型和類別)

          (1) 最簡單方式(回歸模型,分類可以去官網(wǎng)查 https://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.SelectKBest.html#sklearn.feature_selection.SelectKBest.set_params)

          from sklearn.feature_selection import SelectKBest,f_regression
          
          print(data_end.shape)
          
          sk=SelectKBest(f_regression,k=300)
          # drop_columns 為不需要判別的列名
          new_train=sk.fit_transform(data_end.drop(drop_columns,axis = 1),data_end['label'].astype('int'))
          print(new_train.shape)
          
          # 獲取對(duì)應(yīng)列索引
          select_columns=sk.get_support(indices = True)
          print(select_columns)
          print(data_end.columns[select_columns])

          (2) 通過樹模型輸出特征重要性,一般選用Xgboost、Lightgbm等,這里采用lightgbm示例。

           今天這篇文章跟大家分享的主題是關(guān)于篩選頁面的設(shè)計(jì)。作為一個(gè)有逼格的設(shè)計(jì)師,你不但要知道怎么做,還要知道為什么這么做。以免被甲方、老板、運(yùn)營等問的啞口無言、冒頭苦改設(shè)計(jì),經(jīng)歷身心的摧殘后,一句“還是第一版最好”內(nèi)心崩潰。

          過javascript獲取日期方法封裝一些年月日期篩選,方便日后調(diào)用!

          具體集合了以下幾種方法

          效果如下:

          主要代碼:

          html:

          javascript:


          主站蜘蛛池模板: 日韩精品无码一区二区三区| 亚洲一区AV无码少妇电影| 午夜影院一区二区| 国产免费av一区二区三区| 丰满人妻一区二区三区视频53 | 一区二区三区视频在线| 中文乱码人妻系列一区二区| 日韩精品无码视频一区二区蜜桃| 国产精品电影一区二区三区| 亚洲一区二区三区在线观看蜜桃 | 一区二区国产在线观看| 亚洲av无码一区二区三区天堂古代 | 亚洲AV成人一区二区三区AV| 国产成人一区在线不卡| 性色AV 一区二区三区| 国产一区二区三区视频在线观看| 99久久人妻精品免费一区| 国产精品毛片一区二区三区| 波多野结衣高清一区二区三区| 蜜桃视频一区二区| 日韩一区二区精品观看| 三级韩国一区久久二区综合| 丰满岳乱妇一区二区三区| 无码人妻一区二区三区精品视频| 国产一区二区三区视频在线观看| 日韩在线视频一区| 日韩毛片一区视频免费| 亚洲国产成人久久一区WWW| 国产综合无码一区二区三区| 国产精品一区二区av不卡| 国产午夜毛片一区二区三区| 精品日韩在线视频一区二区三区| 国产一区二区四区在线观看| 麻豆精品一区二区综合av| 日韩经典精品无码一区| 亚洲国产精品乱码一区二区| 蜜桃无码AV一区二区| 无码中文字幕人妻在线一区二区三区| 男人的天堂av亚洲一区2区| 日本一区二区三区在线网| 亚洲日韩国产精品第一页一区|