text_plain_output_1.png
from sklearn.ensemble        import RandomForestRegressor

from sklearn.metrics         import mean_squared_error

from sklearn.neighbors       import KNeighborsRegressor

from sklearn.tree            import DecisionTreeRegressor

import numpy as np

def run_model(model, X_train, X_test, y_train, y_test):
    model.fit(X_train, y_train)
    y_pred = model.predict(X_test)
    train_accuracy = model.score(X_train, y_train)
    test_accuracy = model.score(X_test, y_test)
    rmse = np.sqrt(mean_squared_error(y_test, y_pred))

k_values = [1, 5, 10]
for n in k_values:
    model = KNeighborsRegressor(n_neighbors=n)
    run_model(model, X_train, X_test, y_train, y_test)

model = DecisionTreeRegressor()
run_model(model, X_train, X_test, y_train, y_test)

trees = [10, 50, 100, 200, 500]
for n in trees:
    model = RandomForestRegressor(n_estimators=n)
    run_model(model, X_train, X_test, y_train, y_test)
    print()
    print('The Number of estimators is : {}'.format(n))
    print()
    print('--------------------------------')
    print()