
https://nbviewer.jupyter.org/gist/oguzhanilter/25c1fdfa3ab2c7c21e1bbc57524e0575
Analysis of Bike-Share System in Los Angeles
In this part of the project, we want to see if we can predict some information about a ride even before the ride begins and without knowing anything about user. So that, we can plan to build some new stations without being depended on user data. In both machine learning methods we seperated our data into two parts: 60% training data and 40% test (validation) data.
In the bike-sharing system, most commonly encountered problem is that users can not find a bike in the most visited stations. The reasons behind this problem are followings: unpredictable ride durations and non-cyclic ride route patterns. In order to provide enough bikes all the time to users, we should know the the destination of the ride, duration of the ride and the type of the ride (round trip or one way). In order to predict these parameters, we built 3 ML models.
In order to predict destination of the ride and duration of the ride we will use Decision Tree; for the type of the ride we will build a SVM model. With the parameters we used to predict these variables, these two models made sense for what they were trying to achieve.
Decision Tree Models:
1) Ending Station ID Prediction using Starting Station ID, Time of Day, and Day of Week


There are two types of criterias:
These criterias evaluate the data according to its uncertainty depending on its columns. We will focus on entropy in this project, since throughout the semester we used notion of entropy.

Lets also try with gini to see if there is any difference

There is no difference between entropy and gini criterias for this case.
Result of this model:
This model is not successful since we can predict final destination with an accuracy of 15%. This result has been achieved after we test our the model on test dataset which is separated from training dataset at the beginning. This is very low. Parameters we had from the datasets were simply not enough to make a reliable prediction. If we could have some user information like age of user, employment status … etc. we could do a better prediction.
2) Duration Prediction by Using Starting Station Crime Rate, Ending Station Crime Rate, Starting Station Accident Rate, Ending Station Accident Rate


Again, there are two types of criterias:
We will focus on entropy in this project, since throughout the semester we used notion of entropy.

Lets also try with gini to see if there is any difference

The difference between entropy and gini criterias are negligible.
Result of this model:
This model is successful since we can predict ride durations with an accuracy of 76%. We verified that by testing the model on test dataset which is separated from training data. This is high enough to build some models and predict some user behaviour. In this case, we used the fact which we found in Dataset Exploration step. The fact is: how long users ride their bikes is corrolated with crime and accident rates in their area
We tried to visualize the decision tree but due to its large size it was not possible
Support Vector Machine Model
We will use built-in svm function from sklearn
Sklearn is a well known Python library that provides efficient Machine learning algorithms.
A Support Vector Machine (SVM) is a discriminative classifier formally defined by a separating hyperplane. In other words, given labeled training data (supervised learning), the algorithm outputs an optimal hyperplane which categorizes new examples. In two dimentional space this hyperplane is a line dividing a plane in two parts where in each class lay in either side.
In our case space is 2D, therefore our seperation is done by a line into two classes.
Constructing the data that we are going to use for svm
We will use the columns from the extended_bike dataset “Time”, “Starting Station Crime Rate”, “Trip Route Category” By using Time and Starting Station Crime Rate we will try to estimate Trip Route Category. By using Time and Starting Station Crime Rate we will try to estimate Trip Route Category. Which can be one way or round trip.

Trip type is given in binary format for the sake of simplicty. Round Trip -> 0 and One Way -> 1
We seperate the data to x (attributes) and y (target variable) parts. Each divided for testing and training purposes.
Sklearn’s built-in svm library does not work with pandas. Thus, we will convert everything to numpy arrays



The accuracy is around 89%
Results:
We have built 3 models to try to estimate 3 different ride features. 2 of them have worked successfully but 1 of them which is the hardest one to predict without user information, has failed. Even so, we are able to create a general profile for every station about their need of bikes. When we want to build a new station, we can predict its required number of bikes for every time slot of the day. Because right now we can predict, if a bike will return to station or how many minutes will the bike be used by taking “Time”, “Starting Station Crime Rate”, “Ending Station Crime Rate”, “Starting Station Accident Rate”, “Ending Station Accident Rate” as inputs.
These two successful prediction models are enough for some simple predictions. The most important part of the project is that we created some features (Crime and Accident Rates for stations) by combining multiple columns and datasets and those features have been successfully used to build a model.
Discussion:
In our three different datasets, we had information columns with various types. At the beginning of the project, in the Data Exploration Phase, we created one big dataset, namely extended_bike, which covers information from our three initial datasets. In this dataset, we were able to reduce the number of type of features to two, namely: discrete classes (e.g. Time Of Day, Starting Station ID… ) and continuous values (Duration, Crime Rates…).
The order of ML Method selection in a normal project should start with Bayesian Decision Tree since it is very easy to implement and very informative in the sense of probability. After that Logistic Regression would be the appropriate choice due to its classification capabilities in continuous space. In order to improve our classification in continuous space, we can use SVM. When we want to switch our continuous feature space to discrete feature space, Decision Trees could give high precision with very small training time.
In our project, we have selected our ML techniques having considered the information we have explained above. Therefore when we use discrete classes for classification, decision tree would be the right choice. On the other hand, when we use continuous data for classification, our model should be SVM due to its continuous space representation capability.
We thought about creating more models but the two successful models gave us enough information to achieve our initial goals. We can predict bike needs fairly accurately for existing or even new stations using time of day, crime rates, and accident rates in the area of the station. Considering this, we decided that adding more models would make the project more complicated than it needs to be. After all, as long as it works, simplicity is better than complexity. There is some more highly correlated information columns which can be predicted by using ML methods. However , those predictions do not help our design goal. Therefore we omitted them.
At the beginning of the project we did some extra research to find more user centred data, however, they were not shared due to privacy concerns. If we would have had user centred data, we could do some analysis about routes and personal pieces of information. So that we could predict some more possible routes along with new locations for possible new stations.






















