I have a largar dataset which looks like the picture below, which also contains column "Month" and "Year". I try to use Linear Regression model to precit the total number of victims per month, but I don't know how to get the total number victimsDatafram
from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(df_pre[[]],df_pre["Year"]) #don't know how to fit the data in here.
Appreciate help!
I try to fit Vict Age and Month, but I got wrong answer. And I try to create a new datafram which contains only month and total victim, then the fit will have different size.
The concept behind fitting data to the model is:
Since, I couldn't preview your dataset properly, here is a simple example on how to fit data and predict with
LinearRegression.Let say we have small dataset of
x_1,x_2,ywherex_1andx_2are the features (inputs to the model) whileyis the target (what we want to predict).Our dataset:
Full code
Note that we are using this simple equation
y = (1 * x_1) + (2 * x_2) + 3and if you should passx_1 = 3andx_2 = 5to the equation,y = 16which means our model works fine.