Kaggle competition: Brain Cancer Classification
train.loc[:, train.isna().any() ]<rename_columns>
train = pd.read_csv('/kaggle/input/1056lab-brain-cancer-classification/train.csv')
 test = pd.read_csv('/kaggle/input/1056lab-brain-cancer-classification/test.csv')
 train['type'] = train['type'].map({'normal':0, 'ependymoma':1, 'glioblastoma':2, 'medulloblastoma':3, 'pilocytic_astrocytoma':4} )
train.rename(columns={'Province_State':'Province'}, inplace=True)
 train.rename(columns={'Country_Region':'Country'}, inplace=True)
 train.rename(columns={'ConfirmedCases':'Confirmed'}, inplace=True )<rename_columns>
Y = train['type'].values
X = train.drop('type',axis=1 ).values
test.rename(columns={'Province_State':'Province'}, inplace=True)
 test.rename(columns={'Country_Region':'Country'}, inplace=True )<data_type_conversions>
model = lgb.LGBMClassifier()
EMPTY_VAL = "EMPTY_VAL"
def fillState(state, country):
if Province == EMPTY_VAL: return country
return state
train['Province'].fillna(EMPTY_VAL, inplace=True)
 test['Province'].fillna(EMPTY_VAL, inplace=True )<categorify>
def met_f(y_test,y_pred):
return f1_score(y_test,y_pred,average='micro' )
bridge_types =('Date', 'Province', 'Country', 'Confirmed',
'Id')
 countries = pd.DataFrame(train, columns=['Country'])
 state = pd.DataFrame(train, columns=['Province'])
 labelencoder = LabelEncoder()
train['Countries'] = labelencoder.fit_transform(train['Country'])
 train['State']= labelencoder.fit_transform(train['Province'])
 train
test['Countries'] = labelencoder.fit_transform(test['Country'])
 test['State']= labelencoder.fit_transform(test['Province'])
 train['Countries'].head() 
<data_type_conversions>
selector = SelectFromModel(model, threshold="mean")
 selector.fit(X, Y)
 X_selected = selector.transform(X)
 test_selected = selector.transform(test.values )
train['Date']= pd.to_datetime(train['Date'])
 test['Date']= pd.to_datetime(test['Date'])
<drop_column>
model = lgb.LGBMClassifier()
stratifiedkfold = StratifiedKFold(n_splits=3)
 score_func = {'auc': make_scorer(met_f)}
scores = cross_validate(model, X_selected, Y, cv = stratifiedkfold, scoring=score_func)
 print('auc:', scores['test_auc'])
 print('auc:', scores['test_auc'].mean() )
train = train.set_index(['Date'])
 test = test.set_index(['Date'])
 train<feature_engineering>
model = lgb.LGBMClassifier()
model.fit(X_selected,Y)
 p = model.predict(test_selected)
 sample = pd.read_csv('/kaggle/input/1056lab-brain-cancer-classification/sampleSubmission.csv',index_col = 0)
 sample['type'] = p
sample.to_csv('predict_lgbm_sfm.csv',header = True )
def create_time_features(df):

 df['date'] = df.index
df['hour'] = df['date'].dt.hour
df['dayofweek'] = df['date'].dt.dayofweek
df['quarter'] = df['date'].dt.quarter
df['month'] = df['date'].dt.month
df['year'] = df['date'].dt.year
df['dayofyear'] = df['date'].dt.dayofyear
df['dayofmonth'] = df['date'].dt.day
df['weekofyear'] = df['date'].dt.weekofyear
X = df[['hour','dayofweek','quarter','month','year',
'dayofyear','dayofmonth','weekofyear']]
return X<drop_column>
selector = SelectPercentile(score_func=f_regression, percentile=100)
 selector.fit(X, Y)
 X_selected = selector.transform(X)
 test_selected = selector.transform(test.values )
train.drop("date", axis=1, inplace=True)
 test.drop("date", axis=1, inplace=True )<count_missing_values>
model = lgb.LGBMClassifier()
stratifiedkfold = StratifiedKFold(n_splits=3)
 score_func = {'auc': make_scorer(met_f)}
scores = cross_validate(model, X_selected, Y, cv = stratifiedkfold, scoring=score_func)
 print('auc:', scores['test_auc'])
 print('auc:', scores['test_auc'].mean() )
<count_missing_values><EOS> 
model = lgb.LGBMClassifier()
model.fit(X_selected,Y)
 p = model.predict(test_selected)
 sample = pd.read_csv('/kaggle/input/1056lab-brain-cancer-classification/sampleSubmission.csv',index_col = 0)
 sample['type'] = p
sample.to_csv('predict_lgbm_100.csv',header = True )