All Projects → girishkuniyal → Predict-housing-prices-in-Portland

girishkuniyal / Predict-housing-prices-in-Portland

Licence: other
Predict housing prices in Portland, Oregon for selling or buying house

Programming Languages

Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to Predict-housing-prices-in-Portland

Machine-learning
This repository will contain all the stuffs required for beginners in ML and DL do follow and star this repo for regular updates
Stars: ✭ 27 (+80%)
Mutual labels:  linear-regression, prediction-model
machine-learning-course
Machine Learning Course @ Santa Clara University
Stars: ✭ 17 (+13.33%)
Mutual labels:  linear-regression
machine learning
A gentle introduction to machine learning: data handling, linear regression, naive bayes, clustering
Stars: ✭ 22 (+46.67%)
Mutual labels:  linear-regression
models-by-example
By-hand code for models and algorithms. An update to the 'Miscellaneous-R-Code' repo.
Stars: ✭ 43 (+186.67%)
Mutual labels:  linear-regression
SGDLibrary
MATLAB/Octave library for stochastic optimization algorithms: Version 1.0.20
Stars: ✭ 165 (+1000%)
Mutual labels:  linear-regression
MachineLearning
โค้ดประกอบเนื้อหา Python Machine Learning เบื้องต้น [2020]
Stars: ✭ 28 (+86.67%)
Mutual labels:  linear-regression
bitcoin-prediction
bitcoin prediction algorithms
Stars: ✭ 21 (+40%)
Mutual labels:  linear-regression
Lecture-3-Linear-Models
ICDSS Machine Learning Workshop Series: Linear Models
Stars: ✭ 19 (+26.67%)
Mutual labels:  linear-regression
VBLinLogit
Variational Bayes linear and logistic regression
Stars: ✭ 25 (+66.67%)
Mutual labels:  linear-regression
abess
Fast Best-Subset Selection Library
Stars: ✭ 266 (+1673.33%)
Mutual labels:  linear-regression
TotalLeastSquares.jl
Solve many kinds of least-squares and matrix-recovery problems
Stars: ✭ 23 (+53.33%)
Mutual labels:  linear-regression
BasisFunctionExpansions.jl
Basis Function Expansions for Julia
Stars: ✭ 19 (+26.67%)
Mutual labels:  linear-regression
Machine-Learning-Andrew-Ng
机器学习-Coursera-吴恩达- python+Matlab代码实现
Stars: ✭ 127 (+746.67%)
Mutual labels:  linear-regression
Undergraduate-in-Statistics
Using Computer with your Statistics Major Course
Stars: ✭ 57 (+280%)
Mutual labels:  linear-regression
rmi
A learned index structure
Stars: ✭ 51 (+240%)
Mutual labels:  linear-regression
stock-prediction-with-DL
深度学习与股票分析预测
Stars: ✭ 13 (-13.33%)
Mutual labels:  prediction-model
cobra
A Python package to build predictive linear and logistic regression models focused on performance and interpretation
Stars: ✭ 23 (+53.33%)
Mutual labels:  linear-regression
stats
📈 Useful notes and personal collections on statistics.
Stars: ✭ 16 (+6.67%)
Mutual labels:  linear-regression
interactive-simple-linear-regression
A PureScript, browser-based implementation of simple linear regression.
Stars: ✭ 15 (+0%)
Mutual labels:  linear-regression
RPIN
Learning Long-term Visual Dynamics with Region Proposal Interaction Networks (ICLR 2021)
Stars: ✭ 104 (+593.33%)
Mutual labels:  prediction-model

Predict housing prices in Portland, Oregon.

Python 2.7 Problem Regression

Problem statement :

Suppose you are selling your house and you want to know what a good market price would be. One way to do this is to first collect information on recent houses sold and make a model of housing prices. The file ex1data2.txt contains a training set of housing prices in Portland,Oregon. The first column is the size of the house (in square feet), the second column is the number of bedrooms and the third column is the price of the house. Dataset is like below :

Size of the house (in square feet) Number of bedrooms Price of the house
2104 3 399900
1600 3 329900
2400 3 369000

Now we have to predict housing prices in Portland, Oregon.(including which is not mention in our example dataset).

Note:This problem statement and dataset is from coursera Andrew ng machine learning Coursework

Dependencies

  • jupyter
  • numpy
  • matplotlib

Install dependencies using pip

import numpy as np
import matplotlib.pyplot as plt
#supressing the scientific output
np.set_printoptions(suppress=True) 
data = np.loadtxt("ex1data2.txt",dtype=np.float64,delimiter=",")
data[:5,::] #dataset loaded demonstration
array([[   2104.,       3.,  399900.],
       [   1600.,       3.,  329900.],
       [   2400.,       3.,  369000.],
       [   1416.,       2.,  232000.],
       [   3000.,       4.,  539900.]])
# Break datasets into X and Y.
X = data[::,0:2]
Y = data[::,-1:]
# Plotting example dataset
plt.figure(figsize = (15,4),dpi=100)
plt.subplot(121)
plt.scatter(X[::,0:1],Y)
plt.xlabel("Size of house (X1)")
plt.ylabel("Price (Y)")
plt.subplot(122)
plt.scatter(X[::,-1:],Y)
plt.xlabel("Number of Bedrooms (X2)")
plt.ylabel("Price (Y)")
plt.show()

png

# introduce weights of hypothesis (randomly initialize)
Theta = np.random.rand(1,3)
# m is total example set , n is number of features
m,n = X.shape
# add bias to input matrix by simple make X0 = 1 for all
X_bias = np.ones((m,n+1))
X_bias[::,1:] = X
# output first 5 X_bias examples
print "X_bias = \n",X_bias[0:5,:]
print "Y = \n",Y[0:5,::]
X_bias = 
[[    1.  2104.     3.]
 [    1.  1600.     3.]
 [    1.  2400.     3.]
 [    1.  1416.     2.]
 [    1.  3000.     4.]]
Y = 
[[ 399900.]
 [ 329900.]
 [ 369000.]
 [ 232000.]
 [ 539900.]]
#feature scaling
# it also protect program from overflow error
mean_size = np.mean(X_bias[::,1:2])
mean_bedroom = np.mean(X_bias[::,2:])
size_std = np.std(X_bias[::,1:2])
bedroom_std = np.std(X_bias[::,2:])
X_bias[::,1:2] = (X_bias[::,1:2] - mean_size)/ (size_std) 
X_bias[::,2:] = (X_bias[::,2:] - mean_bedroom)/ (bedroom_std)
X_bias[0:5,::]
array([[ 1.        ,  0.13141542, -0.22609337],
       [ 1.        , -0.5096407 , -0.22609337],
       [ 1.        ,  0.5079087 , -0.22609337],
       [ 1.        , -0.74367706, -1.5543919 ],
       [ 1.        ,  1.27107075,  1.10220517]])
#define function to find cost
def cost(X_bias,Y,Theta):
    np.seterr(over='raise')
    m,n = X.shape
    hypothesis = X_bias.dot(Theta.transpose())
    return (1/(2.0*m))*((np.square(hypothesis-Y)).sum(axis=0))
#function gradient descent algorithm from minimizing theta
def gradientDescent(X_bias,Y,Theta,iterations,alpha):
    count = 1
    cost_log = np.array([])
    while(count <= iterations):
        hypothesis = X_bias.dot(Theta.transpose())
        temp0 = Theta[0,0] - alpha*(1.0/m)*((hypothesis-Y)*(X_bias[::,0:1])).sum(axis=0)
        temp1 = Theta[0,1] - alpha*(1.0/m)*((hypothesis-Y)*(X_bias[::,1:2])).sum(axis=0)
        temp2 = Theta[0,2] - alpha*(1.0/m)*((hypothesis-Y)*(X_bias[::,-1:])).sum(axis=0)
        Theta[0,0] = temp0
        Theta[0,1] = temp1
        Theta[0,2] = temp2
        cost_log = np.append(cost_log,cost(X_bias,Y,Theta))
        count = count + 1
    plt.plot(np.linspace(1,iterations,iterations,endpoint=True),cost_log)
    plt.title("Iteration vs Cost graph ")
    plt.xlabel("Number of iteration")
    plt.ylabel("Cost of Theta")
    plt.show()
    return Theta
alpha = 0.3
iterations = 100
Theta = gradientDescent(X_bias,Y,Theta,iterations,alpha)
print Theta

png

[[ 340412.65957447   72655.84621595   59125.40416724]]
# predict the price of a house with 1650 square feet and 3 bedrooms
# add bias unit 1.0
X_predict = np.array([1.0,1650.0,3]) 
#feature scaling the data first
X_predict[1] = (X_predict[1] - mean_size)/ (size_std) 
X_predict[2] = (X_predict[2]- mean_bedroom)/ (bedroom_std)
hypothesis = X_predict.dot(Theta.transpose())
print "Cost of house with 1650 sq ft and 3 bedroom is ",hypothesis
Cost of house with 1650 sq ft and 3 bedroom is  [ 294637.10371537]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].