4
$\begingroup$

I want to create a predictive model to predict a categorical value (1,0) but the independent variables are also having few string columns (country, location, age) which I feel are important for the prediction and should be included.

Which model should I use, will Linear Regression work? till now I did regressions which only had continuous or discrete value, is there any norm to address values which has columns with string values ?

Below is the similar question been asked before, but unfortunately I didn't get much information
Regression Analysis with String values in column of DataFrame

I am in an initial phase of learning and practicing machine learning please spare me if this question breaks the eligibility of valid question.

Please provide some insight, any source of help will be appreciated!!!

Edit: Added partial dataset below

   Year     Location      Country
0  2016      chitwan      Nepal   
1  2016      siberia      Russia   
2  2016    Oba Hills      Nigeria   
3  2016     Edumanom      Nigeria  
4  2016        Kanha      India

  Age                                Injury Survived Time  
  09                         attack on head     N    11h00
  19                            Neck Injury     N    11h00
  23                              lower leg     N    04h43
  65                             leg injury     N    11h00
  NaN                  attacked from behind     N    18h00 
$\endgroup$
1
  • 1
    $\begingroup$ Adding some of your data in the post will help give proper answers - how are the categorical variables constructed? what is your dependent variable? $\endgroup$ – Yuval Spiegler Oct 9 '16 at 17:53
1
$\begingroup$

Regression What you probably need is a Logistic Regression model. A regular linear regression model needs a continuous dependent variable to work, but a logistic regression is used to predict a binary outcome variable.

String Variables The 'sting' variables will need to become dummies. A regression model can handle categorical variables with more than two categories as binary pairs. For example, the variable education with the 3 levels of high_school, college, graduate will be turned to 3 binary variables with each pointing to the representative level:

high_school [1,0] where 1 represents high school graduates and 0 college and grad
college [1,0] where 1 represents college graduates and 0 high school and grad
graduate [1,0] where 1 represents graduate school graduates and 0 all others

Make sure that the recording is 0 and 1, or else the interpretation of the coefficients will be less straightforward. When using these variables (known as Dummy variables) you must keep one out of the regression and it will be your reference category, which all other compare to (more on that in a sec). So if I am interested most in high school graduates, that will be left out of the model. The logic here is that when the rest are 0, than the reference variable will be used. If its NOT graduates and NOT college, than in MUST be high school.

$\endgroup$
2
  • $\begingroup$ Thanks for the instant reply, will your solution work with the dataset I mentioned ? what if I use Logistic regression but with so many string variables (Location, Country, Injury, Time) and their values, will your provided solution still work ? thanks in advance !!! $\endgroup$ – Soumyaansh Oct 11 '16 at 12:54
  • $\begingroup$ Well, it depends. First, age is a continuous variable, so no problem there. Location, it depends on the number of categories and observations per category. If you have many categories and few observations each than you won't have enough variance and won't be able to use it properly. $\endgroup$ – Yuval Spiegler Oct 11 '16 at 13:22
1
$\begingroup$

Logistic regression is what you want to deal with the fact your dependent variable is bounded between (0,1).

Dummy variables is what you will want to use to deal with your variables in string format.

If you are interested in interpretability and avoiding overfitting consider grouping your categorical variables together. For example, instead of having a dummy variable for each country, consider grouping your countries into continents (or another grouping that you think it is valid). Interpreting a model with seven covariates representing continents as opposed to 195 covariates representing countries will be much easier.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.