0% found this document useful (0 votes)
40 views3 pages

Untitled4.ipynb - Colab

The document outlines a Python script using pandas and scikit-learn to analyze a dataset containing income, expenses, and car ownership status. It demonstrates data loading, preprocessing, and the application of a linear regression model to predict car ownership based on income and expenses. The script includes steps for splitting the dataset into training and testing sets, fitting the model, and predicting outcomes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

Untitled4.ipynb - Colab

The document outlines a Python script using pandas and scikit-learn to analyze a dataset containing income, expenses, and car ownership status. It demonstrates data loading, preprocessing, and the application of a linear regression model to predict car ownership based on income and expenses. The script includes steps for splitting the dataset into training and testing sets, fitting the model, and predicting outcomes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

11/7/24, 4:05 PM Untitled4.

ipynb - Colab

import pandas as pd

df=pd.read_csv('[Link]

df

income expence car or not

0 66155.93 8106.532 0

1 34415.15 6564.745 0

2 57317.17 8020.953 0

3 42709.53 6103.642 0

4 66952.69 8770.099 1

... ... ... ...

1549 25358.90 2220.226 0

1550 29993.56 2749.586 0

1551 64675.78 4628.603 0

1552 56256.04 5452.245 0

1553 31702.33 3587.722 0

1554 rows × 3 columns

Next steps: Generate code with df


toggle_off View recommended plots New interactive sheet

x=[Link](columns='car or not')

income expence

0 66155.93 8106.532

1 34415.15 6564.745

2 57317.17 8020.953

3 42709.53 6103.642

4 66952.69 8770.099

... ... ...

1549 25358.90 2220.226

1550 29993.56 2749.586

1551 64675.78 4628.603

1552 56256.04 5452.245

1553 31702.33 3587.722

1554 rows × 2 columns

Next steps: Generate code with x


toggle_off View recommended plots New interactive sheet

y=df['car or not']

[Link] 1/3
11/7/24, 4:05 PM [Link] - Colab

car or not

0 0

1 0

2 0

3 0

4 1

... ...

1549 0

1550 0

1551 0

1552 0

1553 0

1554 rows × 1 columns

dtype: int64

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)

from sklearn.linear_model import LinearRegression

mymodel=LinearRegression()

[Link](x_train,y_train)

▾ LinearRegression i ?
LinearRegression()

mymodel.coef_

array([-4.90433057e-06, 5.30318268e-05])

mymodel.intercept_

0.12741173242967252

y_pred=[Link](x_test)

y_pred

array([ 5.92640941e-02, -5.69283473e-02, 2.13453272e-01, -7.86650143e-02,


2.70288125e-01, 1.08781087e-01, 5.56836002e-02, 1.31856026e-01,
1.22155858e-01, 8.88618259e-02, -8.02465116e-02, 2.01288057e-01,
-2.66792737e-03, 3.47815426e-01, -1.11109103e-01, -1.31401482e-02,
2.82399710e-01, -2.17385529e-02, 2.13569782e-01, 2.40096577e-01,
1.85192569e-01, 2.59247475e-01, -4.99835551e-02, 1.19619500e-01,
5.75098229e-02, 2.64839050e-01, 1.46231377e-01, 2.68914461e-01,
-2.44822684e-02, 1.99685194e-01, -8.37365173e-02, 2.16016797e-01,
4.18012057e-01, 1.03773418e-01, 4.13333351e-01, 1.26169489e-01,
-8.90385982e-02, 1.72945214e-01, 1.37227604e-01, 1.10549118e-02,
-2.24772459e-04, -1.61099558e-01, 3.44948838e-01, 1.33143539e-01,
2.74663459e-02, 7.22591397e-02, 3.79121907e-01, 1.36379121e-01,
2.68132203e-01, 1.66351620e-01, 1.71422828e-01, 1.05605943e-01,
1.94434313e-01, 3.37214711e-01, -5.40934716e-03, 1.46434844e-01,
5.88389624e-02, 5.91158079e-03, 3.39261078e-02, 2.33631352e-01,
2.33613156e-01, 9.15597657e-02, 8.03285805e-02, 7.25737990e-02,
3.25886713e-01, 4.36330653e-02, 1.74362538e-01, 1.30397261e-01,
-8.56577080e-02, 9.92175770e-02, 1.52530870e-01, 2.48327882e-01,
2.21152040e-01, 1.04665620e-01, 2.24285519e-01, 1.82134536e-01,
1.94993036e-01, 2.52570881e-01, 5.28660128e-02, 3.62092800e-01,
5.22055186e-03, 2.18796728e-01, -6.83246397e-02, 2.70996176e-01,
2.34259610e-01, 3.53290539e-01, 5.82274579e-02, 2.04689045e-01,
2.13503457e-01, -9.86001303e-03, 3.00365780e-02, -1.90732669e-02,
-1.07863151e-01, -1.39300270e-01, 1.72828395e-01, 1.33853186e-01,
1.50062893e-01, 4.01627773e-01, -1.39177369e-01, 3.25257919e-01,
2.96083587e-01, 1.21840284e-01, 1.99834977e-01, 3.26683290e-01,
2.78996457e-01, 2.14173875e-01, 1.16933912e-01, 2.53243861e-02,
2.22677099e-01, 2.88940756e-02, 1.60004677e-01, 1.10430600e-01,

[Link] 2/3
11/7/24, 4:05 PM [Link] - Colab
2.57792627e-01, 3.93500695e-01, -4.63765493e-02, 4.32016940e-01,
1.48618818e-02, 3.23427620e-01, 1.69835061e-01, 1.81445891e-01,
-1.05332268e-01, 8.00540817e-02, -4.15267097e-02, 2.00151648e-02,
1.86272077e-01, 2.40166990e-01, 1.13170618e-01, 2.72857394e-01,
1.41445704e-01, 3.15441532e-01, 4.16269436e-01, 9.22363968e-02,
2.40229029e-01, 2.41751893e-01, 3.81710722e-01, 8.65864039e-02,
1.54697817e-01, 1.96103323e-01, 2.63598139e-01, 2.14446888e-02,
-1.12555647e-01, 1.72831884e-01, 3.10789461e-01, -1.15917821e-01,
2.21440001e-01, 2.78160576e-01, 2.00638106e-01, 3.97968332e-01,
9.23194572e-03, 2.40368567e-02, 2.94158583e-01, 3.98060693e-01,
8.30259339e-02, 1.29002135e-01, 2.35475940e-01, 2.07779839e-01,
7.62779432e-02, 3.08132335e-01, -1.63563420e-02, 3.15029251e-02,
5.51149999e-02, 2.01462150e-01, 2.15209056e-01, 3.72365475e-03,
1.81377975e-01, 1.97650174e-01, 2.92043994e-01, -8.41127203e-02,
-3.71912574e-02, 6.41763751e-02, 2.46302798e-01, 9.02225960e-02,
2.15862734e-01, 2.05720877e-01, -1.80127909e-01, 3.27924647e-03,
1.11703404e-01, -8.87584654e-03, -1.14179085e-01, 3.24110035e-01,
2.94871800e-01, 9.26098883e-02, 1.01145079e-01, 1.28267343e-01,
-9.86890358e-02, 1.60061432e-01, -1.89827244e-02, 4.54317009e-01,
6.37059344e-02, 4.45160412e-02, 1.99511621e-01, -2.26968361e-02,
-3.52482167e-02, 1.91668473e-01, 2.74039274e-01, -1.43544949e-01,
2.37272787e-01, -4.32021633e-02, 4.90542837e-04, 3.37753563e-02,
5.02052326e-01, 2.88037551e-01, 1.80236800e-01, 2.28465397e-01,
2.80405675e-01, 1.94273535e-02, 2.20832171e-01, 3.00238736e-01,
2.54770653e-01, 1.33680563e-02, 2.77624937e-01, 1.24709006e-01,
3.65920812e-01, -6.14672009e-02, 1.82449713e-01, 1.07885523e-01,
2.24234840e-01, 1.02163374e-01, -2.04636811e-02, 4.03592833e-01,
-1.01925196e-02, 2.09575209e-01, -6.15050382e-02, -1.22311171e-01,
9.55657047e-02, 7.60788156e-03, 2.73705358e-01, 2.51086406e-01,
1.03057549e-03, 2.41787857e-01, 1.87843308e-01, 7.27971371e-02,

y_test

car or not

1170 0

694 0

850 0

1062 0

801 0

... ...

364 0

1035 0

1425 0

547 0

1196 0

311 rows × 1 columns

dtype: int64

Suggested code may be subject to a license | Hamza-Jamil121/Deep-Learning-With-Python-Programming


from [Link] import classification_report

[Link] 3/3

You might also like