<jupyter_start><jupyter_text>Reading the dataset and preprocessing it.<jupyter_code>ds = pd.read_csv('car data.csv')
ds.head()
ds.isnull().sum()
ds = ds.drop('Car_Name', axis = 1)
ds.head()
print(ds['Fuel_Type'].unique())
print(ds['Seller_Type'].unique())
print(ds['Transmission'].unique())
ds['current'] = 2020
ds.head()
ds['Nof_Years'] = ds['current'] - ds['Year']
ds.head()
ds = ds.drop(['current','Year'], axis = 1)
ds.head()
ds = pd.get_dummies(ds, drop_first = True)
ds.head()<jupyter_output><empty_output><jupyter_text>Visualizing the data.<jupyter_code>plt.scatter(ds['Selling_Price'] , ds['Nof_Years'])
plt.plot(3 ,6)
plt.scatter(ds['Kms_Driven'] , ds['Selling_Price'])
plt.xlabel('km driven')
plt.ylabel('selling price')
plt.legend()
sns.distplot(ds)
sns.pairplot(ds)
plt.figure(figsize=(20,20))
sns.heatmap(ds.corr(), annot = True, cmap = 'RdYlGn')<jupyter_output><empty_output><jupyter_text>Performing feature selection.<jupyter_code>x = ds.iloc[:,1:]
y = ds.iloc[:,0]
x.head()
model = ExtraTreesRegressor()
model.fit(x,y)
imp = pd.Series(model.feature_importances_,index = x.columns)
imp.nlargest(5).plot(kind = 'barh')
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 0.2)<jupyter_output><empty_output><jupyter_text>Hyperparameter tuning.<jupyter_code>rf = RandomForestRegressor()
estimators = [int(x) for x in np.linspace(start = 100, stop = 1200, num =12)]
maxf = ['auto','sqrt']
dept = [int(x) for x in np.linspace(5, 30, num = 6)]
mins = [2, 5, 10, 15, 100]
minl = [1, 2, 5, 10]
param = {'n_estimators': estimators,
        'max_features': maxf,
        'max_depth': dept,
        'min_samples_split': mins,
        'min_samples_split' :minl
        }
randcv = RandomizedSearchCV(estimator = rf, 
                            param_distributions = param, 
                            scoring = 'neg_mean_squared_error',
                           n_iter = 10,
                           cv = 5,
                           verbose = 2,
                           random_state = 42,
                           n_jobs = 1)
randcv.fit(x_train, y_train)
y_hat = randcv.predict(x_test)<jupyter_output><empty_output><jupyter_text>Visualizing the results & saving the  model.<jupyter_code>sns.distplot(y_test-y_hat)
plt.scatter(y_test,y_hat)
pik = open('car_r.p','wb')
pickle.dump(randcv,pik)
pik.close()<jupyter_output><empty_output>