#!/usr/bin/python

import matplotlib.pyplot as plt
from prep_terrain_data import makeTerrainData
from class_vis import prettyPicture

features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow"
### points mixed together--separate them so we can give them different colors
### in the scatterplot and identify them visually
grade_fast = [features_train[ii][0] for ii in range(0, len(features_train)) if labels_train[ii] == 0]
bumpy_fast = [features_train[ii][1] for ii in range(0, len(features_train)) if labels_train[ii] == 0]
grade_slow = [features_train[ii][0] for ii in range(0, len(features_train)) if labels_train[ii] == 1]
bumpy_slow = [features_train[ii][1] for ii in range(0, len(features_train)) if labels_train[ii] == 1]

#### initial visualization
plt.xlim(0.0, 1.0)
plt.ylim(0.0, 1.0)
plt.scatter(bumpy_fast, grade_fast, color="b", label="fast")
plt.scatter(grade_slow, bumpy_slow, color="r", label="slow")
plt.legend()
plt.xlabel("bumpiness")
plt.ylabel("grade")
plt.show()
################################################################################


### your code here!  name your classifier object clf if you want the
### visualization code (prettyPicture) to show you the decision boundary

from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import AdaBoostRegressor
from sklearn.metrics import accuracy_score
from sklearn.metrics import r2_score


# abc = AdaBoostClassifier(base_estimator=None, n_estimators=50, learning_rate=1.0,
#                         algorithm='SAMME.R', random_state=None)
#
# abc.fit(features_train, labels_train)
# predicted = abc.predict(features_test)
# accuracy = accuracy_score(labels_test, predicted)
# print accuracy


abr = AdaBoostRegressor(base_estimator=None, n_estimators=500, learning_rate=1.0,
                  loss='linear', random_state=None)
abr.fit(features_train, labels_train)
predicted_test = abr.predict(features_test)
test_score = r2_score(labels_test, predicted_test)


print test_score


try:
    prettyPicture(abr, features_test, labels_test)
except NameError:
    pass
c05db033b7c57e3d6b0d6936b4c6fffed6b078d9
#!/usr/bin/python

import matplotlib.pyplot as plt
from prep_terrain_data import makeTerrainData
from class_vis import prettyPicture

features_train, labels_train, features_test, labels_test = makeTerrainData()

### the training data (features_train, labels_train) have both "fast" and "slow"
### points mixed together--separate them so we can give them different colors
### in the scatterplot and identify them visually
grade_fast = [features_train[ii][0] for ii in range(0, len(features_train)) if labels_train[ii] == 0]
bumpy_fast = [features_train[ii][1] for ii in range(0, len(features_train)) if labels_train[ii] == 0]
grade_slow = [features_train[ii][0] for ii in range(0, len(features_train)) if labels_train[ii] == 1]
bumpy_slow = [features_train[ii][1] for ii in range(0, len(features_train)) if labels_train[ii] == 1]

#### initial visualization
plt.xlim(0.0, 1.0)
plt.ylim(0.0, 1.0)
plt.scatter(bumpy_fast, grade_fast, color="b", label="fast")
plt.scatter(grade_slow, bumpy_slow, color="r", label="slow")
plt.legend()
plt.xlabel("bumpiness")
plt.ylabel("grade")
plt.show()
################################################################################


### your code here!  name your classifier object clf if you want the
### visualization code (prettyPicture) to show you the decision boundary

from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import AdaBoostRegressor
from sklearn.metrics import accuracy_score
from sklearn.metrics import r2_score


# abc = AdaBoostClassifier(base_estimator=None, n_estimators=50, learning_rate=1.0,
#                         algorithm='SAMME.R', random_state=None)
#
# abc.fit(features_train, labels_train)
# predicted = abc.predict(features_test)
# accuracy = accuracy_score(labels_test, predicted)
# print accuracy


abr = AdaBoostRegressor(base_estimator=None, n_estimators=500, learning_rate=1.0,
                  loss='linear', random_state=None)
abr.fit(features_train, labels_train)
predicted_test = abr.predict(features_test)
test_score = r2_score(labels_test, predicted_test)


print test_score


try:
    prettyPicture(abr, features_test, labels_test)
except NameError:
    pass