Data Science: Regression on Javascript


In the previous article, we analyzed the data representing the statistics of javascript during the year 2019. The data visualization showed us how various types of javascript developers are distributed across the countries. In this article, we will look at linear and logistic regression mechanisms that can be applied to the data to predict the type of javascript developers and the various technologies that will gain more usage in the future. We will particularly look at using several descriptive features given by the users to predict whether they work in AngularJS or not.

Data Preprocessing

The combineddf used for visualizing various charts to see the data distribution will be again used for regression. Since most of the descriptive features are categorical we will be using LabelEncoder to transform this to Numerical data. This can be done in two ways:

  1. Use the LabelEncoder method from sklearn.preprocessing library:

This method would replace all the categorical columns/features with numeric features.

2. Use replace to find the various categories and replace them with appropriate numeric value:

This method will transform the yearly_salary column to numeric.

The transformation would be done for yearly_salary, years_of_experience, and job_title categorical features. And these are the features we will be used for classifying the data. We will also transform the column angular to predict how many users would be using angularjs given their descriptive features.

Logistic regression — linear model

The first step is to apply a linear model for logistic regression. This means we would try to see if the data can be fit using a straight line. The logistic regression would give out a function that separates the two output classes of data (In our case whether the person codes/uses AngularJs or not). Using a linear model, we would get a function that represents a straight line.

In the above code:

  1. We are first selecting the set of columns to be used as descriptive features. These include an array having the values ‘yearlysalary’, ‘yearsofexperience’, ‘backendproficiency’, and ‘css_proficiency’.
  2. Next, we select the target we want to predict ‘angular’.
  3. The data is now split into a training set and test set.
  4. The logistic-regression function from sklearn.linear_model is now used to fit the training data.
  5. The test set can be used for the prediction and verification of our model.

Following are the metrics obtained:

  • Accuracy of the classification: 81%
  • Confusion matrix:

We can see that the model is overfitting, and is classifying every data point to be an angular js user. In other words, the number of false positives in the predicted data is very high.

Logistic regression — Polynomial model

The linear model used for classifying data is overfitting. The simpler way to solve this would be to provide different attributes as descriptive features and check their effect on the model. The reason for overfitting can be:

  • The amount of data used for training is less
  • The Data has too many 1’s compared to 0’s for the Brown frogs.
  • The logistic regression is also sensitive to the outliers.

We can either use a different algorithm or try the polynomial logistic regression function:

  1. The training set obtained by splitting the data is now transformed into the set of polynomial features of degree 2. This increases the number of features that would be used as independent variables.
  2. The logistic regression function can now fit the model and predict the data.

Following are the metrics obtained:

  • Accuracy of the classification: 69%
  • Confusion matrix:

We can see that the model is also overfitting, however, its accuracy has come down to 69%. But note that this model is predicting the values in both categories and is not completely biased to one side. This shows that logistic regression is sensitive to outliers is not the best type of algorithm that can be used for prediction. We can use better ML algorithms. In the next post let us explore SVMs and how they can be used to better predict the values from the same data.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store