0% found this document useful (0 votes)
29 views2 pages

Vridhi Gupta A2305218276 Machine Learning Practical File Aim

The document discusses implementing a machine learning classification model to predict whether students are suitable for an activity based on features like head size and brain weight. Code is provided to perform linear regression analysis on a dataset, calculate the regression coefficients and error, and output an R^2 value.

Uploaded by

buddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views2 pages

Vridhi Gupta A2305218276 Machine Learning Practical File Aim

The document discusses implementing a machine learning classification model to predict whether students are suitable for an activity based on features like head size and brain weight. Code is provided to perform linear regression analysis on a dataset, calculate the regression coefficients and error, and output an R^2 value.

Uploaded by

buddy
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

VRIDHI GUPTA

A2305218276
MACHINE LEARNING
PRACTICAL FILE
Aim: Implement a classification/logistic regression problem. For example, based on different features
of student’s data, classify, whether a student is suitable for a particular activity.

Software Used: spyder python 3.7


CODE:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize']=(20.0,10.0)
data=pd.read_csv(r'C:\Users\DELL\Desktop\college\headbrain.csv')
print(data.shape)
data.head()
X=data['Head Size(cm^3)'].values
Y=data['Brain Weight(grams)'].values
mean_x=np.mean(X)
mean_y=np.mean(Y)
m=len(X)
number=0
denom=0
for i in range(m):
number+=(X[i]-mean_x)*(Y[i]-mean_y)
denom+=(X[i]-mean_x)**2
b1=number/denom
b0=mean_y-(b1*mean_x)
print(b1,b0)
max_x=np.max(X)+100
min_x=np.min(X)-100
x=np.linespace(min_x,max_x,1000)
y=b0+b1*x
plt.plot(x,y,color='#ef5423',label='Scatter Plot')
plt.xlabel("Head Size(cm^3)")
plt.ylabel("Brain Weight(grams)")
plt.legend()
plt.show()
rmse=0
for i in range(m):
y_pred=b0+b1*X[i]
rmse+=(Y[i]-y_pred)**2
rmse=np.sqrt(rmse/m)
print(rmse)
ss_t=0
ss_r=0
for i in range(m):
y_pred=b0+b1*X[i]
ss_t+=(Y[i]-mean_y)**2
ss_r+=(Y[i]-y_pred)**2
r2=1-(ss_r/ss_t)
print(r2)

OUTPUT:

You might also like