Kaggle competition: Eval Lab 2 F464
ts = time.time()
matrix["item_shop_first_sale"] = matrix["date_block_num"] - matrix.groupby(["item_id","shop_id"])["date_block_num"].transform('min')
 matrix["item_first_sale"] = matrix["date_block_num"] - matrix.groupby(["item_id"])["date_block_num"].transform('min')
 time.time() - ts<feature_engineering>
df = pd.read_csv('/kaggle/input/eval-lab-2-f464/train.csv')
 t = pd.read_csv('/kaggle/input/eval-lab-2-f464/test.csv' )
ts = time.time()
matrix = matrix[matrix["date_block_num"] > 3]
time.time() - ts<set_options>
y = df['class']
params = [ 'chem_1','chem_2', 'chem_4', 'chem_6', 'attribute']
x = df[params]
df
rcParams['figure.figsize'] = 12, 4<drop_column>
import xgboost as xgb
import matplotlib.pyplot as plt
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import ExtraTreesClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.tree import DecisionTreeClassifier
from sklearn.linear_model import LogisticRegression
from xgboost import XGBClassifier
from sklearn.model_selection import train_test_split
data = matrix.copy()
del matrix
gc.collect()<prepare_x_and_y>
from sklearn.model_selection import GridSearchCV
from sklearn.metrics import make_scorer
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
X_train = data[data.date_block_num < 33].drop(['item_cnt_month'], axis=1)
 Y_train = data[data.date_block_num < 33]['item_cnt_month']
X_valid = data[data.date_block_num == 33].drop(['item_cnt_month'], axis=1)
 Y_valid = data[data.date_block_num == 33]['item_cnt_month']
X_test = data[data.date_block_num == 34].drop(['item_cnt_month'], axis=1 )<set_options>
model = RandomForestClassifier(n_estimators = 1000)
 model.fit(x,y )
del data
gc.collect() ;<train_model>
y_pred = model.predict(x_test[params])
 y_pred = pd.DataFrame(data = y_pred)
 answer = pd.concat([x_test['id'], y_pred], axis = 1)
 answer.columns = ['id', 'class']
answer.to_csv('lab2_9.csv', index = False )