application_vnd.jupyter.stderr_output_1.png
from sklearn import svm

from sklearn.ensemble import BaggingClassifier

from sklearn.ensemble import GradientBoostingClassifier

from sklearn.ensemble import RandomForestClassifier

from sklearn.metrics import log_loss

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

df = pd.read_json(open('../input/train.json', 'r'))

df['num_photos'] = df['photos'].apply(len)
df['num_features'] = df['features'].apply(len)
df['num_description_words'] = df['description'].apply(lambda x: len(x.split(' ')))
df['created'] = pd.to_datetime(df['created'])
df['created_year'] = df['created'].dt.year
df['created_month'] = df['created'].dt.month
df['created_day'] = df['created'].dt.day
df['price_per_bedroom'] = df['bedrooms'] / df['price']
df['price_per_bathroom'] = df['bathrooms'] / df['price']

df.columns

num_feats = ['bathrooms', 'bedrooms', 'latitude', 'longitude', 'price', 'num_photos', 'num_features', 'num_description_words', 'created_year', 'created_month', 'created_day', 'building_id', 'price_per_bedroom', 'price_per_bathroom']
X = df[num_feats]
y = df['interest_level']

clf = RandomForestClassifier(n_estimators=1500)
clf.fit(X_train, y_train)
y_val_pred = clf.predict_proba(X_val)
log_loss(y_val, y_val_pred)

from sklearn.ensemble import BaggingClassifier
b1 = BaggingClassifier(n_estimators=2000)
b1.fit(X_train, y_train)
y_val_pred = b1.predict_proba(X_val)
log_loss(y_val, y_val_pred)

from sklearn.ensemble import GradientBoostingClassifier
gbc = GradientBoostingClassifier()
gbc.fit(X_train, y_train)
y_val_pred = gbc.predict_proba(X_val)
log_loss(y_val, y_val_pred)

from sklearn import svm
clf = svm.SVC()
clf.fit(X_train, y_train)
y_val_pred = clf.predict_proba(X_val)
log_loss(y_val, y_val_pred)

df = pd.read_json(open('../input/test.json', 'r'))
df['num_photos'] = df['photos'].apply(len)
df['num_features'] = df['features'].apply(len)
df['num_description_words'] = df['description'].apply(lambda x: len(x.split(' ')))
df['created'] = pd.to_datetime(df['created'])
df['created_year'] = df['created'].dt.year
df['created_month'] = df['created'].dt.month
df['created_day'] = df['created'].dt.day
X = df[num_feats]
y = clf.predict_proba(X)

labels2idx = {label: i for i, label in enumerate(clf.classes_)}
labels2idx