You are on page 1of 6

FACULTY OF ENGINEERING SCIENCES & TECHNOLOGY

Department of Computing
Program: BSCS

COURSE TITLE ARTIFICIAL INTELLIGENCE


SEMESTER/YEAR 7TH SEMESTER-2023

COURSE INSTRUCTOR DR SHAHEER MUHAMMAD


ASSIGNMENT NO 01
ASSIGNMENT TITLE REGRESSION (Python implementation)

NAME TAYYABA AROOJ


CMS ID 1603-2020
SIGNATURE TAYYABA
*By signing above you attest that you have contributed to this submission and confirm that all
work you have contributed to this submission is your own work. Any suspicion of copying or
plagiarism in this work will result in an investigation of Academic Misconduct and may result in a
“0” on the work, an “F” in the course, or possibly more severe penalties.

1603-2020
LINEAR REGRESSION
Code:
import matplotlib.pyplot as plt
import numpy as np
from scipy import stats

area = [140,150,160,170,180,190,200]
price = [25000,27000,29000,31000,33000,35000,37000]
slope, intercept, r_value, p_value, std_err = stats.linregress(x=area,y=price)

def myfunc(x):
return slope * x + intercept
plt.scatter(x=area, y=price)
plt.plot(area, price)
plt.title("house pricing prediction")
plt.xlabel("house area")
plt.ylabel("house price")
plt.show()
price = myfunc(100)
print(price)

1603-2020
Output:

POLYNOMIAL REGRESSION
CODE:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import r2_score

x = [0,20,40,60,80,100]
y = [0.002,0.0012,0.0060,0.0300,0.0900,0.2700]

mymodel = np.poly1d(np.polyfit(x, y,4))

myline = np.linspace(0, 100, 100)


print(r2_score(y, mymodel(x)))

1603-2020
plt.scatter(x, y)
plt.plot(myline, mymodel(myline))

plt.xlabel("temperature")
plt.ylabel("pressure")
plt.show()
pressure = mymodel(85)
print(pressure)

OUTPUT:

1603-2020
MULTIPLE REGRESSION
DATA (multipleregr.csv):

CODE:
import pandas as pd
from sklearn import linear_model

df = pd.read_csv("multipleregr.csv")

X = df[['experience', 'test_score(out of 10)', 'interview_score(out of 10)']]


y = df['salary($)']

regr = linear_model.LinearRegression()
regr.fit(X, y)

predictedsalary = regr.predict([[9, 4, 8]])

print(predictedsalary)

1603-2020
OUTPUT:

1603-2020

You might also like