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
""" Zoopla scraping project """ | |
# Import libraries | |
import requests, re, os | |
import pandas as pd | |
from bs4 import BeautifulSoup | |
""" Generate the list of URLs : Start""" | |
def generateURLs(pages): | |
listURLs = [] |
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
# 01 Calculate ECDF for Zoopla distribution model | |
def ecdf(data): | |
"""Compute ECDF for a one-dimensional array of measurements.""" | |
# Number of data points: n | |
n = len(data) | |
# x-data for the ECDF: x | |
x = np.sort(data) |
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
# Plot the ECDF | |
_ = plt.plot(x_vers, y_vers, '.') | |
plt.margins(0.02) | |
_ = plt.xlabel('petal length (cm)') | |
_ = plt.ylabel('ECDF') | |
# Overlay percentiles as red diamonds. | |
_ = plt.plot(ptiles_vers, percentiles/100, marker='D', color='red', | |
linestyle='none') |
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 pearson_r(x, y): | |
"""Compute Pearson correlation coefficient between two arrays.""" | |
# Compute correlation matrix: corr_mat | |
corr_mat = np.corrcoef(x, y) | |
# Return entry [0,1] | |
return corr_mat[0,1] | |
# Compute Pearson correlation coefficient for I. versicolor: r | |
r = pearson_r(versicolor_petal_length, versicolor_petal_width) |
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
# Draw 10,000 samples out of Poisson distribution: samples_poisson | |
samples_poisson = np.random.poisson(10, size = 10000) | |
# Print the mean and standard deviation | |
print('Poisson: ', np.mean(samples_poisson), | |
np.std(samples_poisson)) | |
# Specify values of n and p to consider for Binomial: n, p | |
n = [20, 100, 1000] | |
p = [0.5, 0.1, 0.01] |
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 Table | |
from sqlalchemy import Table | |
# Reflect census table from the engine: census | |
census = Table('census', metadata, autoload=True, autoload_with=engine) | |
# Print census table metadata | |
print(repr(census)) |
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
# Reflect the census table from the engine: census | |
census = Table('census', metadata, autoload=True, autoload_with=engine) | |
# Print the column names | |
print(census.columns.keys()) | |
# Print full table metadata | |
print(repr(metadata.tables['census'])) |
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
# Build select statement for census table: stmt | |
stmt = 'SELECT * FROM census' | |
# Execute the statement and fetch the results: results | |
results = connection.execute(stmt).fetchall() | |
# Print Results | |
print(results) |
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 -*- | |
# Full instructions at: https://cambridgespark.com/content/tutorials/getting-started-with-xgboost/index.html | |
# Date: 20180620 | |
#------------------------------------------------------------------------------ | |
# Use Pandas to load the data in a dataframe | |
import pandas as pd | |
df = pd.read_excel('default of credit card clients.xls', header = 1, index_col = 0) | |
print('The shape of dataframe is {}.'.format(df.shape)) |
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 -*- | |
""" | |
Created on Thu Jun 21 14:26:09 2018 | |
@author: Vytautas.Bielinskas | |
Definitions: | |
JN - Jupyter Notebook | |
ML - Machine learning | |
BOG - Bag Of Words |