This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import numpy as np | |
import pandas as pd | |
from sklearn.cross_validation import ShuffleSplit | |
from sklearn.cross_validation import train_test_split | |
from sklearn.metrics import r2_score | |
from sklearn.metrics import make_scorer | |
from sklearn.grid_search import GridSearchCV | |
from sklearn.tree import DecisionTreeRegressor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
O conjunto de dados de imóveis tem 489 pontos com 4 variáveis em cada. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Extraindo estatísticas | |
minimum_price = np.amin(prices) | |
maximum_price = np.amax(prices) | |
mean_price = np.average(prices) | |
median_price = np.median(prices) | |
std_price = np.std(prices) | |
print "Estatísticas para os dados dos imóveis:\n" | |
print "Preço mínimo: ${:,.2f}".format(minimum_price) | |
print "Preço máximo: ${:,.2f}".format(maximum_price) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Estatísticas para os dados dos imóveis: | |
Preço mínimo: $105,000.00 | |
Preço máximo: $1,024,800.00 | |
Preço médio: $454,342.94 | |
Preço mediano: $438,900.00 | |
Desvio padrão dos preços: $165,171.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Definindo função de avaliação utilizando métrica Rˆ2. Melhor score = 1.0 | |
def performance_metric(y_true, y_predict): | |
return r2_score(y_true, y_predict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Misturando e separando os dados em conjuntos de treinamento e teste | |
X_train, X_test, y_train, y_test = train_test_split(features, prices, test_size = 0.2, random_state = 123) | |
print "\nSeparação entre treinamento e teste feita com êxito.\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fit_model(X, y): | |
# Gera conjuntos de validação-cruzada para o treinamento de dados | |
cv_sets = ShuffleSplit(X.shape[0] # qt total elementos | |
, n_iter = 10 # qt vezes embaralhar e dividir | |
, test_size = 0.2 | |
, random_state = 123) | |
grid = GridSearchCV(DecisionTreeRegressor() | |
, dict(max_depth = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) | |
, make_scorer(performance_metric) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Cria um regressor (DecisionTree) com o parâmetro 'max_depth | |
# otimizado para os dados de treinamento | |
regressor = fit_model(X_train, y_train) | |
print "O parâmetro 'max_depth' otimizado " \ | |
"para o modelo é {}.\n".format(regressor.get_params()['max_depth']) | |
client_data = [[5, 17, 15], # Imóvel 1 | |
[4, 32, 22], # Imóvel 2 | |
[8, 3, 12]] # Imóvel 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
O parâmetro 'max_depth' otimizado para o modelo é 4. | |
Preço estimado para o imóvel 1: $408,870.00 | |
Preço estimado para o imóvel 2: $232,662.50 | |
Preço estimado para o imóvel 3: $892,850.00 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class OnboardingCollectionViewController: UICollectionViewController { | |
} | |
extension OnboardingCollectionViewController: UICollectionViewDelegateFlowLayout { | |
} |
OlderNewer