text_plain_output_1.png
from sklearn import linear_model

from sklearn.preprocessing import RobustScaler

from word2number import w2n

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df = pd.read_csv('../input/car-price-prediction/CarPrice_Assignment.csv', sep=',', encoding='utf-8')

pd.set_option('display.max_columns', None)

df.isna().sum()

from word2number import w2n
df.doornumber = df.doornumber.apply(w2n.word_to_num)
df.cylindernumber = df.cylindernumber.apply(w2n.word_to_num)

(df.doornumber, df.cylindernumber)

df = df.drop('car_ID', axis=1)

df.columns

df.rename(columns={'fueltype': 'fuelType', 'doornumber': 'num_Doors', 'carbody': 'carBody', 'drivewheel': 'driveWheel', 'enginelocation': 'engineLocation', 'wheelbase': 'wheelBase', 'carlength': 'carLength', 'carwidth': 'carWidth', 'carheight': 'carHeight', 'curbweight': 'curbWeight', 'enginetype': 'engineType', 'cylindernumber': 'num_Cyl', 'enginesize': 'engineSize', 'fuelsystem': 'fuelSystem', 'boreratio': 'boreRatio', 'compressionratio': 'compressionRatio', 'horsepower': 'horsePower', 'peakrpm': 'peakRPM', 'citympg': 'cityMPG', 'highwaympg': 'highwayMPG'}, inplace=True)

df.select_dtypes('object')

df.columns

cars = df[['symboling', 'fuelType', 'aspiration', 'num_Doors', 'carBody', 'driveWheel', 'engineLocation', 'wheelBase', 'carLength', 'carWidth', 'carHeight', 'curbWeight', 'engineType', 'num_Cyl', 'engineSize', 'fuelSystem', 'boreRatio', 'stroke', 'compressionRatio', 'horsePower', 'peakRPM', 'cityMPG', 'highwayMPG', 'price']]
x = cars.drop(['price'], axis=1).values
y = cars['price'].values

from sklearn.preprocessing import RobustScaler
ro_scaler = RobustScaler()
x_train = ro_scaler.fit_transform(x_train)
x_test = ro_scaler.fit_transform(x_test)

from sklearn import linear_model
reg = linear_model.LinearRegression()
reg.fit(x_train, y_train)

(reg.score(x_train, y_train), reg.score(x_test, y_test))

pd.DataFrame(reg.coef_, cars.columns[:-1], columns=['Coeficient'])

y_pred = reg.predict(x_test)
df1 = pd.DataFrame({'Y_test': y_test, 'Y_pred': y_pred})
df1.head(10)