Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
COMM5007 Coding for business
3Copyright
• There are some file-sharing websites that specialise in buying and selling
academic work to and from university students.
• If you upload your original work to these websites, and if another student
downloads and presents it as their own either wholly or partially, you
might be found guilty of collusion — even years after graduation.
• These file-sharing websites may also accept purchase of course
materials, such as copies of lecture slides and tutorial handouts. By law,
the copyright on course materials, developed by UNSW staff in the
course of their employment, belongs to UNSW. It constitutes copyright
infringement, if not academic misconduct, to trade these materials.
4Country
• UNSW Business School acknowledges the
Bidjigal (Kensington campus) and Gadigal
(City campus) the traditional custodians of
the lands where each campus is located.
• We acknowledge all Aboriginal and Torres
Strait Islander Elders, past and present and
their communities who have shared and
practiced their teachings over thousands of
years including business practices.
• We recognize Aboriginal and Torres Strait
Islander people’s ongoing leadership and
contributions, including to business,
education and industry.
UNSW Business School. (2022, August 18). Acknowledgement of Country [online video].
Retrieved from https://vimeo.com/369229957/d995d8087f
5
6Predictive Modelling on Classification
7Revision
•Regression Analysis using Python – An Example
8Simple Linear Regression Example
•A real estate agent wishes to examine the relationship
between the selling price of a home and its size (measured in
square feet)
• "kc_house_data.csv" dataset
9Simple Linear Regression Example:
Regression Line
•House price vs living area: regression line
10Simple Linear Regression Example:
Regression Line
•House price vs living area: regression line
import pandas as pd
import numpy as np
from sklearn import linear_model
import matplotlib.pyplot as plt
df = pd.read_csv("kc_house_data.csv")
regr = linear_model.LinearRegression()
df['price_inMillion'] = df["price"]/1000000
price = df[['price_inMillion']]
livingArea = df[['sqft_living']]
regr.fit(livingArea, price)
predictPrice = regr.coef_[0][0]*livingArea + regr.intercept_[0]
plt.plot(np.array(livingArea), np.array(predictPrice), '-r')
plt.xlabel("Living Area-Square Footage of the Room")
plt.ylabel("Price (in Million)")
plt.title('Price vs Living Area', fontsize = 14)
Estimated_Price = 0.00028 * sqft_living – 0.04358
11Simple Linear Regression Example:
Regression Line
•House price vs living area: scatter plot and regression line
12Simple Linear Regression Example:
Regression Line
•House price vs living area: scatter plot and regression line
import pandas as pd
import numpy as np
from sklearn import linear_model
import matplotlib.pyplot as plt
df = pd.read_csv("kc_house_data.csv")
regr = linear_model.LinearRegression()
df['price_inMillion'] = df["price"]/1000000
price = df[['price_inMillion']]
livingArea = df[['sqft_living']]
regr.fit(livingArea, price)
predictPrice = regr.coef_[0][0]*livingArea + regr.intercept_[0]
plt.plot(np.array(livingArea), np.array(predictPrice), '-r')
plt.scatter(df.sqft_living, df.price_inMillion, color = 'Black')
plt.xlabel("Living Area-Square Footage of the Room")
plt.ylabel("Price (in Million)")
plt.title('Price vs Living Area', fontsize = 14)