0

I have a dataset like the below:

    state year      response
1     MA    1   -0.2038564714
2     MA    2   -1.9344440707
3     MA    3   -0.3105101158
4     MA    4   -0.4222270032
5     MA    5    0.6818296904
6     MA    6    1.0094961857
7     MA    7   -0.7261049649
8     MA    8    0.8061088684
9     MA    9    1.4243231097
10    MA   10   -0.7841440048
11    NY    1   -0.6524043665
12    NY    2    0.6507783632
13    NY    3    0.1830479699
14    NY    4    0.5487749604
15    NY    5    1.4046842945
16    NY    6    0.3870831196
17    NY    7    1.0517012702
18    NY    8    0.6229054623
19    NY    9    0.4336203898
20    NY   10    0.3860844382

I want to build a regression model with group by as the "State" variable.

I dont know how to make a group by regression using Random forest regression or gradient boosting algorithms

max_depth = 30
regr_multirf = MultiOutputRegressor(RandomForestRegressor(max_depth=max_depth,
                                                          random_state=0))
regr_multirf.fit(X_train, y_train)

Since i am very new to python (my first day of coding), I dont know how to include groupby here.

There was a similar code [here][1] using linear regression. While it has the groupby facility, I dont know whether Randomforest [1]: Python pandas linear regression groupby has this or not. Any help on this will be much appreciated.

Thank you.

Doubt Dhanabalu
  • 457
  • 4
  • 8
  • 18
  • 1
    @ChihebNexus - Yes sir, I am using pandas. Updated the topic to pandas as well just now, Thank you. – Doubt Dhanabalu Jul 01 '17 at 18:23
  • Can you add a sample of your desired output ? – Chiheb Nexus Jul 01 '17 at 18:26
  • @ChihebNexus - Valid question sir. But i dont have an output now. If you see the input data, its a kind of time series data from two different states. I want to apply the Multi output regressor algorithm with group by so that i can train the model and predict for different states. A similar example given in the link (https://stackoverflow.com/questions/41511945/python-pandas-linear-regression-groupby), though not exact, I want to use the groupby as similar to mentioned on the link – Doubt Dhanabalu Jul 01 '17 at 18:31

0 Answers0