0% found this document useful (0 votes)
3 views1 page

Automobile Linear Regression

Python

Uploaded by

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

Automobile Linear Regression

Python

Uploaded by

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

import numpy as np

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from sklearn.cluster import KMeans
from google.colab import drive

drive.mount("/content/drive")

from sklearn.linear_model import LinearRegression

auto=pd.read_csv("/content/drive/MyDrive/Automobile_data.csv")

for col in auto.columns:


auto[col].replace({'?':np.nan}, inplace=True)

num_col=['normalized-losses','bore','stroke','horsepower','peak-rpm','price']
for col in num_col:
auto[col]=pd.to_numeric(auto[col])
auto[col].fillna(auto[col].mean(),inplace=True)
auto.isnull().sum()

final_data = auto[['engine-size', 'price']]


predictor = auto['engine-size']
target = auto['price']

# Assuming 'predictor' is a pandas Series


predictor = predictor.values.reshape(-1, 1) # Reshape to a 2D array

# Assuming 'target' is a pandas Series


target = target.values.reshape(-1, 1)
model = LinearRegression()
print("\nThe parameters of the model are\n\n", model.get_params())

reg=model.fit(predictor, target)
plt.scatter(predictor, target, color = 'red')
plt.plot(predictor, model.predict(predictor), color = 'yellow')
plt.xlabel('engine_size')
plt.ylabel('price')
plt.show()

You might also like