# R Squared Regression Analysis with Practical

In this ML Algorithms course tutorial, we are going to learn ” R-Squared in detail in Hindi. we covered it by practically and theoretically.

1. What is R-Squared?
2. Why should we use it?
3. How to calculate r2_score?
4. How to implement it using Python?
```# -*- coding: utf-8 -*-
"""R-Squared -Bangalore House Price Prediction.ipynb

Automatically generated by Colaboratory.

Original file is located at

# Business Problem - Predict the Price of Bangalore House
Using Linear Regression - Supervised Machine Learning Algorithm

"""

import pandas as pd

"""### Split Data"""

X = df.drop('price', axis=1)
y = df['price']

print('Shape of X = ', X.shape)
print('Shape of y = ', y.shape)

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=51)

print('Shape of X_train = ', X_train.shape)
print('Shape of y_train = ', y_train.shape)
print('Shape of X_test = ', X_test.shape)
print('Shape of y_test = ', y_test.shape)

"""### Feature Scaling"""

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
sc.fit(X_train)
X_train = sc.transform(X_train)
X_test = sc.transform(X_test)

"""## Linear Regression - ML Model Training"""

from sklearn.linear_model import LinearRegression
lr = LinearRegression()

lr.fit(X_train, y_train)

lr.coef_

lr.intercept_

"""## Predict the value of Home and Test"""

X_test[0, :]

lr.predict([X_test[0, :]])

lr.predict(X_test)

y_test

lr.score(X_test, y_test,)

y_pred = lr.predict(X_test)

"""# R-sqaure"""

from sklearn.metrics import r2_score

r2_score(y_test, y_pred)
```

#### 2 Replies to “R Squared Regression Analysis with Practical”

1. AKSHAY DASARI says:

Sir Please more video on statistics

1. Indian AI Production says:

Sure

Top