Kaggle competition: NBA Rookies
<SOS> metric: categorizationaccuracy Kaggle data source: nba-rookies<set_options>
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.naive_bayes import GaussianNB
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.svm import SVC
from sklearn.ensemble import GradientBoostingClassifier
from sklearn import ensemble
from sklearn.preprocessing import Imputer
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import accuracy_score
from sklearn.metrics import f1_score
from sklearn.cross_validation import train_test_split
gc.collect()<compute_test_metric>
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 all_X = train.iloc[:, 2:-1].values
all_y = train.iloc[:, 21].values
holdout = test
fi = rf_feat_importance(m, df); fi<train_model>
imputer = Imputer(missing_values = 'NaN', strategy = 'mean', axis = 0)
 imputer = imputer.fit(all_X)
 all_X = imputer.transform(all_X)
 train_X, test_X, train_y, test_y = train_test_split(all_X, all_y, test_size=0.2, random_state=0)
 sc = StandardScaler()
train_X = sc.fit_transform(train_X)
 test_X = sc.transform(test_X)
%%time
m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1, oob_score=True)
 m.fit(X_train, y_train)
 print_score(m )<import_modules>
lr = LogisticRegression()
lr.fit(all_X, all_y)
 columns = [ 'GP', 'MIN', 'PTS', 'FGM',
'FGA','FG%',
'3P Made', '3PA',
'3P%', 'FTM',
'FTA', 'FT%' , 'OREB' , 'DREB' , 'REB' , 'AST' , 'STL'
,'BLK' , 'TOV']
holdout_predictions = lr.predict(holdout[columns])
 holdout_ids = holdout["PlayerID"]
from scipy.cluster import hierarchy as hc<train_model>
GBC = ensemble.GradientBoostingClassifier(n_estimators = 2000, learning_rate = 0.001)
 GBC.fit(all_X, all_y)
 GBCpredictions = GBC.predict(test_X)
 f1_score(test_y, GBCpredictions, average='binary')
def get_oob(X):
m = RandomForestRegressor(n_estimators=120, max_features=0.5, min_samples_leaf=3, n_jobs=-1, oob_score=True)
 m.fit(X, y_train)
 return m.oob_score_<feature_engineering>
GBC_predictions = GBC.predict(holdout[columns])
 holdout_ids = holdout["PlayerID"]
submission_df = {"PlayerID": holdout_ids,
"TARGET_5Yrs": GBC_predictions}
submission = pd.DataFrame(submission_df)
 submission.to_csv("submission2GBC.csv", index=False)
 print(submission)
<drop_column><EOS> 
GBC = ensemble.GradientBoostingClassifier(n_estimators = 2000, learning_rate = 0.001)
 GBC.fit(all_X, all_y)
 GBCpredictions = GBC.predict(test_X)
 f1_score(test_y, GBCpredictions, average='binary')