text_plain_output_1.png
from sklearn import linear_model

from sklearn.preprocessing import RobustScaler

import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

data = pd.read_csv('../input/car-price-prediction/CarPrice_Assignment.csv')

df_cars = data.copy()

def check(df):
    l = []
    columns = df.columns
    for col in columns:
        dtypes = df[col].dtypes
        nunique = df[col].nunique()
        sum_null = df[col].isnull().sum()
        l.append([col, dtypes, nunique, sum_null])
    df_check = pd.DataFrame(l)
    df_check.columns = ['column', 'dtypes', 'nunique', 'sum_null']
    return df_check
check(df_cars)

df_cars.isnull().sum()

df_cars.duplicated().sum()

df_cars.columns

df_cars.drop('car_ID', axis=1, inplace=True)

df_cars.CarName.unique()

df_cars.CarName.unique()

categorical_cols = df_cars.select_dtypes(include=['object']).columns

c = df_cars.corr()

cars = df_cars[['wheelbase', 'carlength', 'carwidth', 'curbweight', 'enginesize', 'boreratio', 'horsepower', 'citympg', 'highwaympg', 'drivewheel', 'fuelsystem', '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)

reg.intercept_

reg.coef_

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