Data Scientist Professional Practical Exam

Company Background

Inn the Neighborhood is an online platform that allows people to rent out their properties for short stays. At the moment, only 2% of people who come to the site interested in renting out their homes start to use it.

The product manager would like to increase this. They want to develop an application to help people estimate how much they could earn renting out their living space. They hope that this would make people more likely to sign up.

Customer Question

The product manager would like to know:

Success Criteria

They want to avoid estimating prices that are more than 25 dollars off of the actual price, as this may discourage people.

Dataset

The data you will use for this analysis can be accessed here: "data/rentals.csv"

The columns and their descriptions are presented as follows:

1. Data Validation

Here we will access the data quality, perform validation tasks on them and cleaning/changes where it shows necessary.

1.1. NA Values

From our initial analysis we detected 2 columns with missing values.

Since we have just a few rows with missing data and it appears they are random, we can remove them from the data that we will be working on.

We will inspect now some columns, regarding their type and values and making changes where necessary.

1.2. property_type column

1.3. room_type column

1.4. bathrooms column

1.5. bedrooms column

1.6. Proper changes

Validation tests were performed with property_type and room_type in order to detect if there were different representations for same words, like use of uppercase/lowercase or unnecessary spaces. This was not the case.

However we will investigate better the column property_type in the next section, since it has 26 different categories. For now we will transform both columns into category columns.

Regarding the bathrooms column, we investigated and came to conclusion that sometimes the half number is used to refer to Half-baths, which means a powder room, lavatory, or guest bath. We decided to keep the column as float type, with the half numbers.

Regarding the bedrooms column, it has float type, but all of its values are integer numbers. We will maintain the column as float type.

Finally we change the price column, by removing the money symbol $ and transforming the column into float.

We finish by analyzing again the data distribution, in order to detect negative values in the numeric variables where it shouldn't have.

Concluding our Data Validation step, we:

2. Exploratory Analysis

Now we will create data visualizations in order to highlight the features and detect their relationships between each others.

2.1. Target Variable: Price

We start analyzing the distribution of our target variable, which is the price. Since it is a float variable and contains many different values, we show that in this case it is better presented by a KDE (Kernel density estimation) along with a histogram of the distribution.

We can clearly see that our target variable Price does not follow a normal distribution, it has a long right tail. However it does have many outliers, as showed in the boxplot below.

We can also sort our data, by descending order of prices. After analyzing it, we have decided to remove the higher outliers, which corresponds to 1.36% of our entire dataset being removed.

We show again the Distribution and Histogram of our target variable Price, after removal of outliers, which will be used in our studies.

Since our target variable Price does not follow a normal distribution, we will perform a power transformation, in order to achieve better modelling in next steps.

Since our data has one row with null price, we will remove this row.
Below we experiment with the Box-Cox and Yeo-Johnson transformations, comparing their p-values, histograms and QQ-plot.

Analyzing the p-values, we see that Box-Cox transformation achieved a value of 0.0153 while the Yeo-Johnson transformation achieved a value of 0.0366. Both values are below 0.05, the p-value we chose, so we can reject the null-hypothesis, and both still do not follow normal distributions.

This is better illustrated by their QQ-Plots, where we can see a flat tail to the right, which corresponds to the high occurrences at the data extremity. Although the transformations did not achieve a complete normal distribution, we will proceed with the Yeo-Johnson transformation.

For the exploratory analysis we will apply the transformation to the entire Price column. Posteriorly for our model training and testing, we will apply the transformation only based on the training set.

2.2. Numerical variables

We start analyzing the numeric variables of our dataset, showing the correlation matrix between them, foccusing more on our target variable price transformed.

From the correlation matrix presented above, we can identify there is a moderate linear positive relationship between bedrooms and price. We also identified some weak linear positive relationship between bedrooms to bathrooms. We will proceed with further investigation on each numeric feature.

2.3. Columns bedrooms and bathrooms

Since we detected some correlation between these two columns, we will investigate their distribution.
Here we apply countplot instead of histogram, in order to show the PMF (probability mass function).

Both distributions are skewed with tails to the right.

Next we analyze the relationship of the two columns with the target variable price.

From both scatterplots we can see there is one outlier away from the distributions. We can verify it corresponds to the same row, therefore we will remove it.

For better visualization, we will apply some jitting to the data points. We also included linear regression lines, made by seaborn, just for illustrative purpose.

2.4. Column id

This feature does not add any information to our model. We can check that each row has a different id.
So we will not select it as feature for prediction.

2.5. Columns latitude and longitude

For exploratory analysis, we will look the latitude and longitude distributions.

Both distributions are slightly skewed with tails to the left. We will investigate their relationship to the target variable price.

From the scatterplots we can see there is no relationship between price and latitude/longitude.

2.6. Column minimum_nights

We start analyzing this column by showing its distribution through a boxplot. We can see there are some outliers.

Sorting the dataframe by minimum_nights column, in descending order, we can verify the outliers. They are not reasonable, so we will remove the first two rows.

After removing these rows, we can show the boxplot again.

There are still outliers, but we will keep them, since they may represent real intended values.
We may proceed now by analyzing the distribution of minimum_nights with histogram.

This feature distribution reveals something interesting. It follows a bimodal distribution, with one peak close to 1-2 minimum nights and another peak related to 30 minimum nights.

Let us visualize now how it relates to our target variable price.

We will apply a little jitting again, together with a linear regression line, made by seaborn, for illutrative purpose.

2.7. Categorical variables

We now proceed to investigate the categorical variables.

2.8. Column property_type

We will perform first a more detailed investigation on property_type column, since it may have categories with similar meaning, among all 26 different values.

Visualizing property_type distribution, we can see that there is a significant quantity of diffenrent categories. But just a few of them show significant instances. Let us investigate those who appear less.

Visualizing how the variable property_type relates to our target variable price and analyzing its categories we can see that there are different categories with similar meaning and behavior like the words 'Aparthotel', 'Apartment' and 'Condominium'.

Since we have so many different categories with so few instances and different words representing the same category, we will proceed by mapping categories with similar meaning, into 9 different categories: apartment, castle, guest, hostel, hotel, house, others, resort and tiny house, as presented by the following table:

Group Original
Apartment Aparthotel
Apartment Apartment
Apartment Condominium
Apartment Serviced apartment
Apartment Townhouse
Castle Castle
Guest Guest suite
Guest Guesthouse
Hostel Bed and breakfast
Hostel Hostel
Hotel Boutique hotel
Hotel Hotel
House House
House Bungalow
House Cottage
House Loft
Others Other
Others Villa
Resort Resort
Tiny House Cabin
Tiny House Tiny house

We can now investigate once more the distribution and also the variable property_type relationship to the target variable price.

The mapping of 26 different categories into 9 categories might help us model better the problem.

2.9. Column room_type

We start analyzing the distribution of room_type column.

Analyzing the countplots above, we can see that it has unbalanced distribution.
Let's analyze how this variable relates to our target variable price.

From the boxplot presented, we can see there is some slighty difference in distribution of prices among room_type categories, however all of them have outliers.

2.10. Exploratory Analysis Conclusion

Overall, the data appears to be very scrambled and difficult to model. The variable bedrooms showed as the best numerical variable, with a slight clearer linear correlation with price. Among the categorical variables, room_type presented the best distribution of different prices among its categories.

The columns minimum_nights and bathrooms, despite being numerical, had price values along almost the entire range, for same feature values. This might compromise considerably the models development in next step.

3. Model Development

In this step we will identify the proper type of problem, implement two machine learning models, one for baseline and one for comparison, and fit both.

Our target variable is price and it is a numerical variable, therefore we have a regression problem.

3.1. Baseline Model

For our baseline model we will select a Linear Regression model, since it is one of the simplest models and some of our variables have moderate relationship to the target variable.

First we need to select the proper variables, which will be used as features for our models. From our exploratory analysis, we will select the columns property_type, room_type, bedrooms, bathrooms and minimum_nights.

We also need to do some proper transformations first. The categorical variables will be transformed to numeric features. Since we wanto to give equal weightage to the categorical variables, we will apply one hot encoder transformation.

We will now split the data into training and test sets.

Now we will apply power transformation on the target variable price and standardization to the numerical features. We fit and transform on the training set and transform the test set.

We are now ready to fit our baseline model.

3.2. Comparison Model

For our comparison model we chose to apply an Ensemble Model, by applying a Bagging Regressor with multiple Decision Tree Regressors.

We chose to use Decision Trees in order to model the non-linearities of the model. In addition, we employed Ensemble Model for a more robust and less overfitted regressor.

4. Model Evaluation

In this step we will evaluate both models performance, in the test set. We will compare both based on two regression metrics: the R-Squared Score, which measures how well the model fits dependent variables and the RMSE (Root Mean Squared Error), which measures how much the predicted results deviate from the real target values.

4.1. Linear Regressor

We start analyzing how our baseline model performs on the test set.

4.2. Bagging Regressor

We now compare our comparison model on the same test set.

4.3. Hyperparameters tunning

We would like to perform a Grid Search Cross Validation, in order to find the best hyperparameters for our Decision Tree Regressor and Bagging Regressor.

We will foccus on the following hyperparameters:

This test should take around 3 min to run with standard environment configurations.

By comparing the first bagging regressor model with the best one achieved, through the Grid Search CV, there is only a slight improvement in the model metrics.

4.4. Model Evaluation Conclusions

By comparing both models R-Squared Score and RMSE, we verify that the Bagging Regressor has a better performance than the Linear Regressor. This indicates that the problem may have influence of non-linearities.

However both R-Squared Scores were still very far from the ideal 1.0. This illustrates how the data is scrambled and presents challenges for the models to predict correctly.

With these results, we will proceed to the Business Criteria and show how this models can still benefit the company, although their low performances.

5. Business Criteria

The company wants to avoid estimating prices that are more than 25 dollars off of the actual price. Therefore, we will show the percentage of predictions with price within range of 25 dollars from the actual price, as KPI to compare the two models.

For our calculations we will transform back the predictions made on previous step, to dollar uni.

As we can see by the KPI presented above, the results are very promising. With the Linear Regression model, 67.97% of predictions were not 25 dollars higher than the actual price. With the Bagging Regression model, 69.27% of predictions were not 25 dollars higher than actual price.

Although the results obtained are still far from desirable 90% or even higher, it may represent a big improvement to the platform, in order to drastically increase the number of people signing up and using it. As informed, at the moment, only 2% of people who visit the site end up using it. By developing this price prediction model, we may attract the attention of 69% of visitors, encouraging them to use our system.

6. Recommendations

To help improve Inn the Neighborhood platform, attract more people to sign up and use it, we recommend the development of a professional and appealing design, made by the front-end team of the company, to show our Bagging Regression Model predictions. With this new feature, about 69% of predictions will encourage the visitors to explore more and use our system. For sure this will represent a drastical increase of users, compared to previous 2% of visitors.

To further improve our model, we may perform stratified tests, in order to perform better modelling to specific public as different property types, since we have so many different types and they can perform differently.

To improve our model, we can make the following directions: