application_vnd.jupyter.stderr_output_1.png
from pathlib import Path

from sklearn.ensemble import RandomForestClassifier

import os

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

input_path = Path('../input')
train_path = input_path / 'train'
test_path = input_path / 'test'

cameras = os.listdir(train_path)
train_images = []
for camera in cameras:
    for fname in sorted(os.listdir(train_path / camera)):
        train_images.append((camera, fname))
train = pd.DataFrame(train_images, columns=['camera', 'fname'])
train.sample(5)

test_images = []
for fname in sorted(os.listdir(test_path)):
    test_images.append(fname)
test = pd.DataFrame(test_images, columns=['fname'])

random_images = train.sample(100)
random_images[:5]

cols = ['pca1', 'pca2']
for col in cols:
    train[col] = None
    test[col] = None

train.sample(5)

test.sample(5)

def get_random_forest_clf(df_train, cols):
    y = df_train['camera'].values
    X_train = df_train[cols].values
    return RandomForestClassifier(n_estimators=200).fit(train, y)

y = train['camera'].values
X_train = train[cols].values
X_test = test[cols].values
clf = RandomForestClassifier(n_estimators=5)
clf.fit(X_train, y)