0% found this document useful (0 votes)
11 views

Machine Learning

This document describes a linear regression program that takes in data points, calculates the slope and y-intercept of the linear regression line, and outputs the equation of the line and a predicted y value for a new x value. The program prompts the user to input the number of data points and then the x and y values, calculates the mean and variance of x and y, and uses those to determine the slope and y-intercept.

Uploaded by

Chairman AR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Machine Learning

This document describes a linear regression program that takes in data points, calculates the slope and y-intercept of the linear regression line, and outputs the equation of the line and a predicted y value for a new x value. The program prompts the user to input the number of data points and then the x and y values, calculates the mean and variance of x and y, and uses those to determine the slope and y-intercept.

Uploaded by

Chairman AR
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Linear Regression Program

DataSet=int(input("Enter Data Set length:"))

x=[]

y=[]

var= 0.0

covar= 0.0

for m in range(DataSet):

x.insert(m,float(input("Enter the value of x:")))

y.insert(m,float(input("Enter the value of y:")))

xmean=sum(x)/len(x)

ymean=sum(y)/len(y)

for n in range(DataSet):

var=var+pow((x[n]-xmean),2)

covar=covar+((x[n]-xmean)*(y[n]-ymean))

var=var/(DataSet-1)

covar=covar/(DataSet-1)

beta=covar/var

alpha=ymean-(beta*xmean)

print('Equation={}(x)+{}'.format(beta,alpha))

NewData=float(input("Enter value of x:"))


yanswer=(beta*NewData)+alpha

print('y=',yanswer)

You might also like