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

Linear Regression - Colab

The document demonstrates the use of Python libraries for data analysis, specifically using a dataset on age and premium. It employs linear regression to model the relationship between age and premium, achieving a high score of 0.988. The model predicts a premium of approximately 24271.09 for an age of 26, with a coefficient and intercept calculated for the regression equation.

Uploaded by

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

Linear Regression - Colab

The document demonstrates the use of Python libraries for data analysis, specifically using a dataset on age and premium. It employs linear regression to model the relationship between age and premium, achieving a high score of 0.988. The model predicts a premium of approximately 24271.09 for an age of 26, with a coefficient and intercept calculated for the regression equation.

Uploaded by

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

import numpy as np #handle matrices and vectors in python

import pandas as pd #handle big data and make conclusions based on statistical theories
import seaborn as sns #visualize data
from sklearn import linear_model #provides tools for machine learning and statistical model

df = pd.read_csv('lrrr.csv')

df

Unnamed: 0 age premium


0 0 20 21000

1 1 22 21500

2 2 24 22800

3 3 25 23100

4 4 27 24800

5 5 29 26000

6 6 31 27500

7 7 32 28200

8 8 36 31000

9 9 37 32500

sns.lmplot(x='age',y='premium',data=df)

<seaborn.axisgrid.FacetGrid at 0x799f6fd58610>

model=linear_model.LinearRegression()
model.fit(df[['age']],df[['premium']])

▾ LinearRegression i ?

LinearRegression()

model.score(df[['age']],df[['premium']])

0.9881907630657503

model.predict([[26]])

/usr/local/lib/python3.11/dist-packages/sklearn/utils/validation.py:2739: UserWa
warnings.warn(
array([[24271.09084769]])

#y=mx+c

model.coef_

array([[682.13441405]])

model.intercept_

array([6535.5960824])

y=682.13441405*26+6535.5960824

24271.0908477

You might also like