標籤: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數組