machine learning in coding(python):根據關鍵字合并feature,刪除無用feature,轉化為numpy數組

來源:互聯網
上載者:User

標籤:scikit-learn   機器學習   根據關鍵字合并feature   刪除feature   

import pandas as pdimport numpy as npfrom sklearn import preprocessingfrom keras.models import Sequentialfrom keras.layers.core import Dense, Activation, Dropout# load training and test datasetstrain = pd.read_csv('../input/train_set.csv', parse_dates=[2,])test = pd.read_csv('../input/test_set.csv', parse_dates=[3,])tubes = pd.read_csv('../input/tube.csv')# create some new featurestrain['year'] = train.quote_date.dt.yeartrain['month'] = train.quote_date.dt.monthtrain['dayofyear'] = train.quote_date.dt.dayofyeartrain['dayofweek'] = train.quote_date.dt.dayofweektrain['day'] = train.quote_date.dt.daytest['year'] = test.quote_date.dt.yeartest['month'] = test.quote_date.dt.monthtest['dayofyear'] = test.quote_date.dt.dayofyeartest['dayofweek'] = test.quote_date.dt.dayofweektest['day'] = test.quote_date.dt.daytrain = pd.merge(train,tubes,on='tube_assembly_id',how='inner')test = pd.merge(test,tubes,on='tube_assembly_id',how='inner')train['material_id'].fillna('SP-9999',inplace=True)test['material_id'].fillna('SP-9999',inplace=True)# drop useless columns and create labelsidx = test.id.values.astype(int)test = test.drop(['id', 'tube_assembly_id', 'quote_date'], axis = 1)labels = train.cost.valuestrain = train.drop(['quote_date', 'cost', 'tube_assembly_id'], axis = 1)# convert data to numpy arraytrain = np.array(train)test = np.array(test)


from:kaggle


著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

machine learning in coding(python):根據關鍵字合并feature,刪除無用feature,轉化為numpy數組

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.